Skip to content

Commit

Permalink
[Bug] fix update layer type reset layer dataId, new layer at the top (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta committed Jan 26, 2023
1 parent ac5f490 commit 943ee50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/reducers/src/vis-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ export function layerTypeChangeUpdater(
let newLayer = new state.layerClasses[newType]({
// keep old layer lable and isConfigActive
label: oldLayer.config.label,
isConfigActive: oldLayer.config.isConfigActive
isConfigActive: oldLayer.config.isConfigActive,
dataId: oldLayer.config.dataId
});

if (!oldLayer.type) {
Expand Down Expand Up @@ -1142,7 +1143,8 @@ export const addLayerUpdater = (
...state,
layers: [...state.layers, newLayer],
layerData: [...state.layerData, newLayerData],
layerOrder: [...state.layerOrder, state.layerOrder.length],
// add new layer at the top
layerOrder: [state.layerOrder.length, ...state.layerOrder],
splitMaps: addNewLayersToSplitMap(state.splitMaps, newLayer)
};
};
Expand Down Expand Up @@ -1210,11 +1212,13 @@ export const duplicateLayerUpdater = (

// add layer to state
let nextState = addLayerUpdater(state, {config: loadedLayer});

// new added layer are at the end, move it to be on top of original layer
const newLayerOrderIdx = nextState.layerOrder.length - 1;
// layers: ['a', 'b', 'c', 'd']
// order: [3, 0, 1, 2]
// [0, 3, 1, 2]
// new added layer are at the top, move it to be on top of original layer
const newLayerOrderIdx = nextState.layers.length - 1;
const newLayerOrder = arrayInsert(
nextState.layerOrder.slice(0, newLayerOrderIdx),
nextState.layerOrder.slice(1, nextState.layerOrder.length),
originalLayerOrderIdx,
newLayerOrderIdx
);
Expand Down
2 changes: 1 addition & 1 deletion test/node/reducers/vis-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ test('#visStateReducer -> ADD_LAYER.1', t => {
[oldState.layerData[0], {}],
'newState should have empty layer datat'
);
t.deepEqual(newReducer.layerOrder, [0, 1], 'should add to layerOrder');
t.deepEqual(newReducer.layerOrder, [1, 0], 'should add to layerOrder');
t.deepEqual(newReducer.splitMaps, expectedSplitMaps, 'should add to SplitMaps');

t.end();
Expand Down

0 comments on commit 943ee50

Please sign in to comment.