Skip to content

Commit

Permalink
Fix issue regarding link auto deletion on workspace load affecting #393
Browse files Browse the repository at this point in the history
  • Loading branch information
bindeali committed Mar 2, 2022
1 parent 55113a8 commit 0239956
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/modals/CreationModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const CreationModals: React.FC<Props> = (props) => {
props.linkConfiguration.targetID,
]
),
updateProjectLink(false, ...initConnections())
updateProjectLink(false, ...initConnections().add)
);
setRepresentation(Representation.COMPACT);
AppSettings.selectedElements = [];
Expand Down
2 changes: 1 addition & 1 deletion src/function/FunctionElem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export async function putElementsOnCanvas(
);
const newIDs = initElements(true);
queries.push(updateProjectElement(false, ...newIDs));
queries.push(updateProjectLink(false, ...initConnections()));
queries.push(updateProjectLink(false, ...initConnections().add));
ids.push(...newIDs);
addToFlexSearch(...ids);
}
Expand Down
2 changes: 1 addition & 1 deletion src/function/FunctionGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function spreadConnections(
);
const newIDs = initElements();
queries.push(updateProjectElement(false, ...newIDs));
queries.push(updateProjectLink(false, ...initConnections()));
queries.push(updateProjectLink(false, ...initConnections().add));
ids.push(...newIDs);
}
const elem = graph.getElements().find((elem) => elem.id === id);
Expand Down
5 changes: 2 additions & 3 deletions src/function/FunctionRestriction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createRestriction(
restrictions.push(restriction);
}

export function initConnections(removeOutdated: boolean = false): string[] {
export function initConnections(): { add: string[]; del: string[] } {
const linksToPush = [];
const linksToDelete: string[] = Object.keys(WorkspaceLinks);
const restrictions = _.flatten(
Expand Down Expand Up @@ -99,6 +99,5 @@ export function initConnections(removeOutdated: boolean = false): string[] {
}
}
}
if (removeOutdated) return linksToPush.concat(linksToDelete);
return linksToPush;
return { add: linksToPush, del: linksToDelete };
}
14 changes: 4 additions & 10 deletions src/interface/ContextInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,8 @@ export async function retrieveContextData(): Promise<boolean> {
)
return false;
addToFlexSearch(...Object.keys(WorkspaceElements));
const connections = initConnections(true);
const connectionsToDelete = connections.filter(
(link) => link in WorkspaceLinks
);
const connectionsToInitialize = connections.filter(
(link) => !(link in WorkspaceLinks)
);
for (const id of connectionsToDelete) {
const connections = initConnections();
for (const id of connections.del) {
// This is expected behaviour e.g. for imported diagrams,
// if they have references to links that no longer exist in the data.
console.warn(
Expand All @@ -238,8 +232,8 @@ export async function retrieveContextData(): Promise<boolean> {
return await processTransaction(
AppSettings.contextEndpoint,
qb.constructQuery(
updateProjectLink(false, ...connectionsToInitialize),
updateDeleteProjectLink(true, ...connectionsToDelete)
updateProjectLink(false, ...connections.add),
updateDeleteProjectLink(true, ...connections.del)
)
);
}

0 comments on commit 0239956

Please sign in to comment.