Skip to content

Commit

Permalink
fix: properly remap views separately on state load
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest committed Jan 17, 2022
1 parent 1bf2f84 commit 28bbf9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
28 changes: 24 additions & 4 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ function createStore(injected) {

// make sure store modules have a chance to rewrite their saved mappings
// before we re-populate proxy manager state
dispatch('rewriteProxyIds', $oldToNewIdMapping).then(() => {
dispatch('rewriteProxyIds', {
appState,
mapping: $oldToNewIdMapping,
}).then(() => {
// Force update
proxyManager.modified();

Expand Down Expand Up @@ -499,9 +502,26 @@ function createStore(injected) {
dispatch('changeCameraViewPoint', keys[ind]);
},

rewriteProxyIds({ dispatch }, oldToNewMapping) {
dispatch('widgets/rewriteProxyIds', oldToNewMapping);
dispatch('views/rewriteProxyIds', oldToNewMapping);
rewriteProxyIds({ dispatch }, { appState, mapping }) {
// split out the mappings
const extractMapping = (objs) =>
objs.reduce(
(map, obj) => ({ ...map, [obj.id]: mapping[obj.id] }),
{}
);

const sourcesMapping = extractMapping(appState.sources);
const viewsMapping = extractMapping(appState.views);
const repsMapping = extractMapping(appState.representations);
const maps = {
sources: sourcesMapping,
views: viewsMapping,
reps: repsMapping,
all: mapping,
};

dispatch('widgets/rewriteProxyIds', maps);
dispatch('views/rewriteProxyIds', maps);
},
},
});
Expand Down
8 changes: 3 additions & 5 deletions src/store/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'paraview-glance/src/components/core/VtkView/constants';
import { DEFAULT_BACKGROUND } from 'paraview-glance/src/components/core/VtkView/palette';

import { wrapMutationAsAction } from 'paraview-glance/src/utils';
import { remapIdValues, wrapMutationAsAction } from 'paraview-glance/src/utils';

const { CaptureOn } = WidgetManagerConstants;

Expand Down Expand Up @@ -82,10 +82,8 @@ export default ({ proxyManager }) => ({
Vue.set(state.viewOrder, index, viewType);
Vue.set(state.viewOrder, dstIndex, srcViewType);
},
rewriteProxyIds(state, idMapping) {
Object.entries(state.viewTypeToId).forEach(([type, id]) => {
state.viewTypeToId[type] = idMapping[id];
});
rewriteProxyIds(state, { views: idMapping }) {
state.viewTypeToId = remapIdValues(state.viewTypeToId, idMapping);
},
},
actions: {
Expand Down
2 changes: 1 addition & 1 deletion src/store/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default ({ proxyManager }) => ({
setCroppingState(state, { datasetId, planes }) {
state.croppingStates[datasetId] = Array.from(planes);
},
rewriteProxyIds(state, idMapping) {
rewriteProxyIds(state, { sources: idMapping }) {
state.measurements = remapIdKeys(state.measurements, idMapping);
state.imageToLabelmaps = remapIdKeys(state.imageToLabelmaps, idMapping);
state.labelmapStates = remapIdKeys(state.labelmapStates, idMapping);
Expand Down
15 changes: 15 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ export function remapIdKeys(obj, mapping) {
return newObj;
}

/**
* Renames values in an object according to a lookup.
*/
export function remapIdValues(obj, mapping) {
const newObj = {};
Object.entries(obj).forEach(([key, id]) => {
let newId = id;
if (id in mapping) {
newId = mapping[id];
}
newObj[key] = newId;
});
return newObj;
}

/**
* Replaces elements in a list according to a mapping.
*/
Expand Down

0 comments on commit 28bbf9f

Please sign in to comment.