Skip to content

Commit

Permalink
consolidated addVisualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
bobular committed May 17, 2023
1 parent 85f6619 commit 59005c2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/libs/eda/src/lib/core/hooks/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,19 @@ export function useAnalysis(
[setComputations]
);

// add or move a visualization (silently removes it before adding) to a computation
// add or move a visualization (silently removes it from any (or none) computation before adding) to a computation
const addVisualization = useCallback(
(computationId: string, visualization: Visualization) => {
deleteVisualization(visualization.visualizationId);
setComputations((computations) =>
computations.map((comp) => ({
...comp,
visualizations:
comp.computationId === computationId
? [...comp.visualizations, visualization]
: comp.visualizations,
visualizations: [
...comp.visualizations.filter(
({ visualizationId }) =>
visualizationId !== visualization.visualizationId
),
...(comp.computationId === computationId ? [visualization] : []),
],
}))
);
},
Expand Down

0 comments on commit 59005c2

Please sign in to comment.