coopcycle-web
coopcycle-web copied to clipboard
Editing issues when recurrent task edit
When editing recurrent rules, the addresses don't change. See GIF
It seems to be because what is stored in the task_rrule.template
column in database is wrong. It contains at the same time an @id
column, and properties.
Example:
{
"@type":"hydra:Collection",
"hydra:member":[
{
"@type":"Task",
"type":"PICKUP",
"address":{
"@id":"\/api\/addresses\/12487",
"streetAddress":"20 Rue du Clos Feuqui\u00e8res, Paris, France",
"postalCode":"75015",
"contactName":"Jean Michel",
"telephone":"+33606060606"
},
"after":"00:00",
"before":"23:59",
"comments":"Attention!!!!!!!"
},
{
"@type":"Task",
"type":"DROPOFF",
"address":{
"@id":"\/api\/addresses\/12488",
"streetAddress":"30 Rue Pirandello, Paris, France",
"postalCode":"75013",
"contactName":"Marie Michelle",
"telephone":"+33606060606"
},
"after":"00:00",
"before":"23:59",
"comments":"Pourquoi?"
}
]
}
So probably the code in TaskNormalizer::denormalize
loads what is stored in database, and not the properties in the JSON.
https://github.com/coopcycle/coopcycle-web/blob/4a60bbfa8ea4f5cc9c65aa069e3d168bbea07b09/src/Serializer/TaskNormalizer.php#L115
Hi guys, another thing maybe related to that :
When you change the address of a task created through a recurrent task, it modifies all other recurrent tasks created before and after.
Indeed, it changes the address linked to all tasks but not the address of the recurrent entity :
Created task :
Task created before modification :
Task created after modification :
.
There is some code in TaskRecurrenceRuleSubscriber that persists the adresses entered in the modal (this is why we end up with addresses with an @id
).
We do this, to avoid duplicating addresses each time tasks are created.
There are 2 issues here:
-
[x] Make sure that address is updated when editing a recurrent rule, using duplication. We need to keep the previous address untouched, and recreated a new address, to avoid losing the database links.
-
[x] When editing a task's address, we are actually modifying the address object in database. All other tasks that are linked to this address would have their address modified as well. For most users, when they modify the address of a task, it's not obvious that they will modify all other tasks. So, when a task's address is modified, we need to create a new address, instead of updating the existing address.