Skip to content

Commit

Permalink
fix style editor in maps (#1170) (#1172)
Browse files Browse the repository at this point in the history
Co-authored-by: stefano bovio <stefano.bovio@geosolutionsgroup.com>
  • Loading branch information
DavidQuartz and allyoucanmap committed Sep 5, 2022
1 parent 17901a7 commit 49ba48b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
5 changes: 3 additions & 2 deletions geonode_mapstore_client/client/js/epics/datasetscatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SET_CONTROL_PROPERTY } from '@mapstore/framework/actions/controls';
import { updateMapLayout, UPDATE_MAP_LAYOUT } from '@mapstore/framework/actions/maplayout';
import { mapLayoutSelector } from '@mapstore/framework/selectors/maplayout';
import { getConfigProp } from "@mapstore/framework/utils/ConfigUtils";
import { LayoutSections } from "@js/utils/LayoutUtils";

/**
* @module epics/datasetcatalog
Expand All @@ -22,7 +23,7 @@ export const gnUpdateDatasetsCatalogMapLayout = (action$, store) =>
action$.ofType(UPDATE_MAP_LAYOUT, SET_CONTROL_PROPERTY)
.filter(() => store.getState()?.controls?.datasetsCatalog?.enabled)
.filter(({ source }) => {
return source !== 'DatasetsCatalog';
return source !== LayoutSections.PANEL;
})
.map(({ layout }) => {
const mapLayout = getConfigProp('mapLayout') || { left: { sm: 300, md: 500, lg: 600 }, right: { md: 658 }, bottom: { sm: 30 } };
Expand All @@ -35,7 +36,7 @@ export const gnUpdateDatasetsCatalogMapLayout = (action$, store) =>
right: mapLayout.right.md
}
});
return { ...action, source: 'DatasetsCatalog' }; // add an argument to avoid infinite loop.
return { ...action, source: LayoutSections.PANEL }; // add an argument to avoid infinite loop.
});

export default {
Expand Down
5 changes: 3 additions & 2 deletions geonode_mapstore_client/client/js/epics/layersettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { updateMapLayout, UPDATE_MAP_LAYOUT } from '@mapstore/framework/actions/
import { mapLayoutSelector } from '@mapstore/framework/selectors/maplayout';
import { getConfigProp } from "@mapstore/framework/utils/ConfigUtils";
import { SHOW_SETTINGS } from '@mapstore/framework/actions/layers';
import { LayoutSections } from "@js/utils/LayoutUtils";
/**
* @module epics/layersetting
*/
Expand All @@ -21,7 +22,7 @@ export const gnUpdateLayerSettingsMapLayout = (action$, store) =>
action$.ofType(UPDATE_MAP_LAYOUT, SHOW_SETTINGS)
.filter(() => store.getState()?.layers?.settings?.expanded)
.filter(({ source }) => {
return source !== 'LayerSettings';
return source !== LayoutSections.PANEL;
})
.map(({ layout }) => {
const mapLayout = getConfigProp('mapLayout') || { left: { sm: 300, md: 500, lg: 600 }, right: { md: 658 }, bottom: { sm: 30 } };
Expand All @@ -34,7 +35,7 @@ export const gnUpdateLayerSettingsMapLayout = (action$, store) =>
left: mapLayout.left.sm
}
});
return { ...action, source: 'LayerSettings' }; // add an argument to avoid infinite loop.
return { ...action, source: LayoutSections.PANEL }; // add an argument to avoid infinite loop.
});

export default {
Expand Down
5 changes: 3 additions & 2 deletions geonode_mapstore_client/client/js/epics/visualstyleeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getStyleProperties } from '@js/api/geonode/style';
import { updateMapLayout, UPDATE_MAP_LAYOUT } from '@mapstore/framework/actions/maplayout';
import { mapLayoutSelector } from '@mapstore/framework/selectors/maplayout';
import { getConfigProp } from "@mapstore/framework/utils/ConfigUtils";
import { LayoutSections } from "@js/utils/LayoutUtils";

/**
* @module epics/visualstyleeditor
Expand Down Expand Up @@ -166,7 +167,7 @@ export const gnUpdateVisualStyleEditorMapLayout = (action$, store) =>
action$.ofType(UPDATE_MAP_LAYOUT, SET_CONTROL_PROPERTY)
.filter(() => store.getState()?.controls?.visualStyleEditor?.enabled)
.filter(({ source }) => {
return source !== 'VisualStyleEditor';
return source !== LayoutSections.PANEL;
})
.map(({ layout }) => {
const mapLayout = getConfigProp('mapLayout') || { left: { sm: 300, md: 500, lg: 600 }, right: { md: 658 }, bottom: { sm: 30 } };
Expand All @@ -179,7 +180,7 @@ export const gnUpdateVisualStyleEditorMapLayout = (action$, store) =>
left: mapLayout.left.md
}
});
return { ...action, source: 'VisualStyleEditor' }; // add an argument to avoid infinite loop.
return { ...action, source: LayoutSections.PANEL }; // add an argument to avoid infinite loop.
});

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import expect from 'expect';
import {
mapSaveSelector
} from '../mapsave';

describe('mapsave selector', () => {
it('should keep the available styles property', () => {
const state = {
map: {
present: {}
},
layers: {
flat: [{ id: '01', availableStyles: [{ name: 'style' }] }]
}
};
const data = mapSaveSelector(state);
expect(data.map.layers[0].availableStyles).toEqual([
{ name: 'style' }
]);
});
});
36 changes: 36 additions & 0 deletions geonode_mapstore_client/client/js/selectors/mapsave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import { mapSaveSelector as msMapSaveSelector } from '@mapstore/framework/selectors/mapsave';
import { layersSelector } from '@mapstore/framework/selectors/layers';

/*
* this map save selector is extending the default properties available in the final map data blob
* eg. availableStyles property
*/
export const mapSaveSelector = (state) => {
const layersState = layersSelector(state);
const { map, ...data } = msMapSaveSelector(state);
return {
...data,
map: {
...map,
layers: (map?.layers || []).map((layer) => {
const layerState = layersState.find((lState) => lState.id === layer.id);
if (layerState) {
const { availableStyles } = layerState;
return {
...layer,
availableStyles
};
}
return layer;
})
}
};
};
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/js/selectors/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { mapSelector } from '@mapstore/framework/selectors/map';
import { mapSaveSelector } from '@mapstore/framework/selectors/mapsave';
import { mapSaveSelector } from '@js/selectors/mapsave';
import { compareMapChanges } from '@mapstore/framework/utils/MapUtils';
import { currentStorySelector } from '@mapstore/framework/selectors/geostory';
import { originalDataSelector } from '@mapstore/framework/selectors/dashboard';
Expand Down
12 changes: 12 additions & 0 deletions geonode_mapstore_client/client/js/utils/LayoutUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2022, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

export const LayoutSections = {
// we need a constant to prevent infinite loop in the epics that update the layout
PANEL: 'PANEL'
};

0 comments on commit 49ba48b

Please sign in to comment.