Skip to content

Commit c07cd9d

Browse files
author
Camille Moussu
committed
[#352] update exceptions on all update without reseting them
1 parent fe8e196 commit c07cd9d

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

src/features/Events/EventApi.ts

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,71 @@ export const updateSeries = async (
345345
// When date/time/timezone/repeat rules changed, remove all override instances
346346
finalVevents = [updatedMaster];
347347
} else {
348-
// When only properties changed, keep override instances
349-
vevents[masterIndex] = updatedMaster;
350-
finalVevents = vevents;
348+
// When only properties changed, keep override instances and update their metadata
349+
const updatedVevents = vevents.map((vevent, index) => {
350+
if (index === masterIndex) {
351+
return updatedMaster;
352+
}
353+
354+
const [veventType, props] = vevent;
355+
const updatedProps = [...updatedMaster[1]];
356+
357+
// Fields that should be updated from master (metadata)
358+
const updateFields = [
359+
"summary",
360+
"description",
361+
"location",
362+
"class",
363+
"transp",
364+
"attendee",
365+
"organizer",
366+
"valarm",
367+
"x-openpaas-videoconference",
368+
];
369+
370+
// Start with existing exception properties
371+
const newProps = [...props];
372+
373+
// Update each metadata field from the master
374+
updateFields.forEach((fieldName) => {
375+
const fieldNameLower = fieldName.toLowerCase();
376+
377+
// Remove old values of this field from exception
378+
const filteredProps = newProps.filter(
379+
([k]) => k.toLowerCase() !== fieldNameLower
380+
);
381+
382+
// Get new values from updated master
383+
const newValues = updatedProps.filter(
384+
([k]) => k.toLowerCase() === fieldNameLower
385+
);
386+
387+
// Replace with new values
388+
newProps.length = 0;
389+
newProps.push(...filteredProps, ...newValues);
390+
});
391+
392+
// Increment sequence number for the exception
393+
const sequenceIndex = newProps.findIndex(
394+
([k]) => k.toLowerCase() === "sequence"
395+
);
396+
if (sequenceIndex !== -1) {
397+
const currentSequence = parseInt(newProps[sequenceIndex][3] || "0", 10);
398+
newProps[sequenceIndex] = [
399+
newProps[sequenceIndex][0],
400+
newProps[sequenceIndex][1],
401+
newProps[sequenceIndex][2],
402+
String(currentSequence + 1),
403+
];
404+
} else {
405+
// Add sequence if it doesn't exist
406+
newProps.push(["sequence", {}, "integer", "1"]);
407+
}
408+
409+
return [veventType, newProps];
410+
});
411+
412+
finalVevents = updatedVevents;
351413
}
352414

353415
const newJCal = [

0 commit comments

Comments
 (0)