Skip to content

Commit

Permalink
[Bug] rename dataset should not use spread (#1911)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta committed Aug 9, 2022
1 parent 486e323 commit ac59ac7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
26 changes: 13 additions & 13 deletions src/reducers/vis-state-updaters.ts
Expand Up @@ -1847,20 +1847,20 @@ export function renameDatasetUpdater<S extends VisState>(
const {dataId, label} = action;
const {datasets} = state;
const existing = datasets[dataId];
// @ts-ignore
return existing
? {
...state,
datasets: {
...datasets,
[dataId]: {
...existing,
label
}
}

if (existing) {
const newDataset = copyTableAndUpdate(existing, {label});
return {
...state,
datasets: {
...datasets,
[dataId]: newDataset
}
: // No-op if the dataset doesn't exist
state;
};
}

// No-op if the dataset doesn't exist
return state;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/comparison-utils.js
Expand Up @@ -227,11 +227,13 @@ export function cmpDatasets(t, expectedDatasets, actualDatasets) {
cmpDataset(t, expectedDatasets[dataId], actualDatasets[dataId]);
});
}

export function assertDatasetIsTable(t, dataset) {
t.ok(dataset instanceof KeplerTable, `${dataset.label || 'dataset'} should be a KeplerTable`);
}

export function cmpDataset(t, expectedDataset, actualDataset, opt = {}) {
assertDatasetIsTable(t, actualDataset);
cmpObjectKeys(t, expectedDataset, actualDataset, `dataset:${expectedDataset.id}`);

// test everything except auto generated color
Expand Down
31 changes: 15 additions & 16 deletions test/node/reducers/vis-state-test.js
Expand Up @@ -36,6 +36,7 @@ import {getDefaultInteraction} from 'utils/interaction-utils';
import {getDefaultFilter} from 'utils/filter-utils';
import {createNewDataEntry} from 'utils/dataset-utils';
import {maybeToDate} from 'utils/data-utils';
import KeplerTable from 'utils/table-utils/kepler-table';
import {processCsvData, processGeojson} from '@kepler.gl/processors';
import {Layer, KeplerGlLayers} from '@kepler.gl/layers';
import {
Expand Down Expand Up @@ -71,7 +72,8 @@ import {
cmpDatasets,
cmpDataset,
cmpObjectKeys,
cmpField
cmpField,
assertDatasetIsTable
} from 'test/helpers/comparison-utils';
import {
applyActions,
Expand All @@ -86,7 +88,6 @@ import {
InitialState
} from 'test/helpers/mock-state';
import {getNextColorMakerValue} from 'test/helpers/layer-utils';
import {assertDatasetIsTable} from '../../helpers/comparison-utils';

const mockData = {
fields: [
Expand Down Expand Up @@ -1361,8 +1362,16 @@ test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {
}
}
});
const snowflake = new KeplerTable({
data: {
fields: [{name: 'a'}, {name: 'b'}],
rows: [['something'], ['something_else']]
},
info: {
id: 'snowflake'
}
});

const testFields3 = [{id: 'a'}, {id: 'b'}];
const oldState = {
...INITIAL_VIS_STATE,
layers: [mockLayer],
Expand All @@ -1373,12 +1382,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {
[7, 8]
],
datasets: {
snowflake: {
fields: testFields3,
dataContainer: createDataContainer([['something'], ['something_else']], {
fields: testFields3
})
}
snowflake
},
filters: [{name: 'hello'}, {name: 'world'}],
interactionConfig: {
Expand All @@ -1396,14 +1400,8 @@ test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {
splitMaps: []
};

const testFields2 = [{id: 'a'}, {id: 'b'}];
const expectedDatasets = {
snowflake: {
fields: testFields2,
dataContainer: createDataContainer([['something'], ['something_else']], {
fields: testFields2
})
},
snowflake,
smoothie: {
metadata: {
id: 'smoothie',
Expand Down Expand Up @@ -2187,6 +2185,7 @@ test('#visStateReducer -> RENAME_DATASET', t => {
const newLabel = 'New label!!!11';
const updated = reducer(initialState, VisStateActions.renameDataset(tripDataInfo.id, newLabel));

assertDatasetIsTable(t, updated.datasets[tripDataInfo.id]);
t.equal(updated.datasets[tripDataInfo.id].label, newLabel, 'Updated label as expected');

t.end();
Expand Down

0 comments on commit ac59ac7

Please sign in to comment.