Skip to content

Commit

Permalink
Fix repeated copy & paste of panel and inset
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Nov 28, 2024
1 parent a863f15 commit 4dd4690
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/js/views/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ export function getRandomId() {
return parseInt(Math.random() * RANDOM_NUMBER_RANGE);
}

export function newIdFromRandomId(oldId) {
return parseInt((oldId * Math.PI) % RANDOM_NUMBER_RANGE);
}

export function updateRoiIds(panelsJson) {
// If we copy and paste an inset panel AND it's corresponding panel with Rect,
// we don't want changes in viewport/Rect to trigger changes in the panels they
Expand All @@ -296,14 +292,15 @@ export function updateRoiIds(panelsJson) {
let idsToUpdate = insetIdsFromPanels.filter(roiId => insetIdsFromShapes.includes(roiId));

// Update the IDs
let toAdd = getRandomId();
let updatedPanels = panelsJson.map(panelJson => {
if (idsToUpdate.includes(panelJson.insetRoiId)) {
panelJson.insetRoiId = newIdFromRandomId(panelJson.insetRoiId);
panelJson.insetRoiId = (panelJson.insetRoiId + toAdd) % RANDOM_NUMBER_RANGE;
}
if (panelJson.shapes) {
panelJson.shapes.forEach(shape => {
if (idsToUpdate.includes(shape.id)) {
shape.id = newIdFromRandomId(shape.id);
shape.id = (shape.id + toAdd) % RANDOM_NUMBER_RANGE;
}
});
}
Expand Down

0 comments on commit 4dd4690

Please sign in to comment.