Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Bug] fix readonly in addDataToMap (#783)

Shan Heb20ac1f71899
diff --git a/src/reducers/combined-updaters.js b/src/reducers/combined-updaters.js
index a3141e934..f519cc06f 100644
--- a/src/reducers/combined-updaters.js
+++ b/src/reducers/combined-updaters.js
@@ -156,7 +156,7 @@ export const addDataToMapUpdater = (state, {payload}) => {
uiState: {
...mergedState.uiState,
...toggleModalUpdater(mergedState.uiState, {payload: null}),
- ...(options.hasOwnProperty('readOnLy') ? {readOnly: options.readOnly} : {})
+ ...(options.hasOwnProperty('readOnly') ? {readOnly: options.readOnly} : {})
}
};
diff --git a/test/node/reducers/composer-state-test.js b/test/node/reducers/composer-state-test.js
index 6be3eb716..cd965afa6 100644
--- a/test/node/reducers/composer-state-test.js
+++ b/test/node/reducers/composer-state-test.js
@@ -27,6 +27,7 @@ import {processCsvData} from 'processors/data-processor';
import testCsvData, {sampleConfig} from 'test/fixtures/test-csv-data';
import testHexIdData, {hexIdDataConfig, mergedH3Layer, mergedFilters} from 'test/fixtures/test-hex-id-data';
import {cmpLayers, cmpFilters, cmpDatasets, cmpInteraction} from 'test/helpers/comparison-utils';
+import {INITIAL_UI_STATE} from 'reducers/ui-state-updaters';
const mockRawData = {
fields: [
@@ -123,6 +124,33 @@ test('#composerStateReducer - addDataToMapUpdater: mapState should be centered',
t.end();
});
+test('#composerStateReducer - addDataToMapUpdater: uiState', t => {
+ // init kepler.gl root and instance
+ const state = keplerGlReducer(undefined, registerEntry({id: 'test'})).test;
+
+ const newState = addDataToMapUpdater(state, {
+ payload: {
+ datasets: {
+ data: mockRawData,
+ info: {
+ id: 'foo'
+ }
+ }
+ }
+ });
+
+ const expectedUIState = {
+ ...INITIAL_UI_STATE,
+ initialState: {},
+ readOnly: false,
+ currentModal: null
+ }
+
+ t.deepEqual(newState.uiState, expectedUIState, 'ui state should be set readOnly:false,currentModal: null');
+
+ t.end();
+});
+
test('#composerStateReducer - addDataToMapUpdater: keepExistingConfig', t => {
const data = processCsvData(testCsvData);
@@ -235,3 +263,43 @@ test('#composerStateReducer - addDataToMapUpdater: keepExistingConfig', t => {
t.end();
});
+
+test('#composerStateReducer - addDataToMapUpdater: readOnly', t => {
+
+ const datasets = {
+ data: processCsvData(testCsvData),
+ info: {
+ id: sampleConfig.dataId
+ }
+ }
+ const state = keplerGlReducer({}, registerEntry({id: 'test'})).test;
+
+ // old state contain splitMaps
+ const nextState = addDataToMapUpdater(state, {
+ payload: {
+ datasets,
+ options: {
+ readOnly: true
+ }
+ }
+ });
+ t.equal(nextState.uiState.readOnly, true, 'should set readonly to be true');
+
+ const nextState1 = addDataToMapUpdater(state, {
+ payload: {
+ datasets
+ }
+ });
+ t.equal(nextState1.uiState.readOnly, false, 'should set readonly to be false');
+
+ const nextState2 = addDataToMapUpdater(state, {
+ payload: {
+ datasets,
+ options: {
+ readOnly: false
+ }
+ }
+ });
+ t.equal(nextState2.uiState.readOnly, false, 'should set readonly to be false');
+ t.end();
+});