From c0c5af0cab54df30cd03f2abb31f9a653c994861 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 1 Aug 2019 14:11:13 +0100 Subject: [PATCH] Fix issue with different items across collections sharing the same uid The existing code falsely (and accidentally) assumed that all items (even across different collections) will have unique uids. This is a false assumption, especially when importing one collection into the other. --- src/Journals/journalView.tsx | 2 +- src/Pim/PimMain.tsx | 15 +++++++++------ src/Pim/index.tsx | 11 ++++++----- src/journal-processors.ts | 6 ++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Journals/journalView.tsx b/src/Journals/journalView.tsx index 8a2d182..69262bd 100644 --- a/src/Journals/journalView.tsx +++ b/src/Journals/journalView.tsx @@ -50,7 +50,7 @@ export function journalView(JournalList: any, JournalItem: any) { render={({match}) => { return ( - + ); }} /> diff --git a/src/Pim/PimMain.tsx b/src/Pim/PimMain.tsx index 2f75a1b..01e3eb6 100644 --- a/src/Pim/PimMain.tsx +++ b/src/Pim/PimMain.tsx @@ -52,24 +52,27 @@ class PimMain extends React.PureComponent { } public eventClicked(event: ICAL.Event) { - const uid = event.uid; + // FIXME:Hack + const itemUid = `${(event as any).journalUid}|${event.uid}`; this.props.history!.push( - routeResolver.getRoute('pim.events._id', { itemUid: uid })); + routeResolver.getRoute('pim.events._id', { itemUid })); } public taskClicked(event: ICAL.Event) { - const uid = event.uid; + // FIXME:Hack + const itemUid = `${(event as any).journalUid}|${event.uid}`; this.props.history!.push( - routeResolver.getRoute('pim.tasks._id', { itemUid: uid })); + routeResolver.getRoute('pim.tasks._id', { itemUid })); } public contactClicked(contact: ContactType) { - const uid = contact.uid; + // FIXME:Hack + const itemUid = `${(contact as any).journalUid}|${contact.uid}`; this.props.history!.push( - routeResolver.getRoute('pim.contacts._id', { itemUid: uid })); + routeResolver.getRoute('pim.contacts._id', { itemUid })); } public newEvent(start?: Date, end?: Date) { diff --git a/src/Pim/index.tsx b/src/Pim/index.tsx index d6b7b40..14f7c83 100644 --- a/src/Pim/index.tsx +++ b/src/Pim/index.tsx @@ -81,11 +81,13 @@ const itemsSelector = createSelector( const ItemChangeLog = pure((props: any) => { const { syncInfo, - items, - uid, + paramItemUid, } = props; - const journalItem = syncInfo.get(items[uid].journalUid); + const tmp = paramItemUid.split('|'); + const journalUid = tmp.shift(); + const uid = tmp.join('|'); + const journalItem = syncInfo.get(journalUid); return ( @@ -169,8 +171,7 @@ const CollectionRoutes = withStyles(styles)(withRouter( )} diff --git a/src/journal-processors.ts b/src/journal-processors.ts index c8c2bf2..7c0a37b 100644 --- a/src/journal-processors.ts +++ b/src/journal-processors.ts @@ -13,10 +13,9 @@ export function syncEntriesToItemMap( entries.forEach((syncEntry) => { const comp = new ContactType(new ICAL.Component(ICAL.parse(syncEntry.content))); - const uid = comp.uid; - // FIXME:Hack (comp as any).journalUid = collection.uid; + const uid = `${collection.uid}|${comp.uid}`; if ((syncEntry.action === EteSync.SyncEntryAction.Add) || (syncEntry.action === EteSync.SyncEntryAction.Change)) { @@ -66,10 +65,9 @@ function syncEntriesToCalendarItemMap( comp.color = color; - const uid = comp.uid; - // FIXME:Hack (comp as any).journalUid = collection.uid; + const uid = `${collection.uid}|${comp.uid}`; if ((syncEntry.action === EteSync.SyncEntryAction.Add) || (syncEntry.action === EteSync.SyncEntryAction.Change)) {