Skip to content

Commit

Permalink
#9219 - Allow to configure hidden columns in featuregrid (#9226)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuren1 authored Jun 16, 2023
1 parent c21c955 commit bee29bb
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 21 deletions.
7 changes: 5 additions & 2 deletions web/client/epics/__tests__/context-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
contextLoadError,
CONTEXT_LOAD_ERROR,
loadFinished

} from "../../actions/context";

import {
Expand Down Expand Up @@ -115,6 +114,9 @@ describe('context epics', () => {
expect(sessionLoadAction.type).toBe(LOAD_USER_SESSION);
expect(sessionLoadAction.name).toBe("2.1.Saitama");
expect(userSessionLoadedAction).toBeTruthy(); // emitted by the test
expect(userSessionLoadedAction.session).toBeTruthy();
expect(userSessionLoadedAction.session.map).toBeTruthy();
expect(userSessionLoadedAction.session.featureGrid).toBeTruthy();
expect(clearMapTemplatesAction.type).toBe(CLEAR_MAP_TEMPLATES);
expect(loadMapAction.type).toBe(LOAD_MAP_CONFIG);
expect(setUserSessionAction.type).toBe(SET_USER_SESSION);
Expand All @@ -137,7 +139,8 @@ describe('context epics', () => {
map: {},
context: {
userPlugins: []
}
},
featureGrid: {attributes: {col1: {hide: true}}}
})).delay(100)),
// simulate load map
action$
Expand Down
7 changes: 4 additions & 3 deletions web/client/epics/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ export const loadMapConfigAndConfigureMap = (action$, store) =>
const userName = userSelector(store.getState())?.name;
return Observable.of(loadUserSession(buildSessionName(null, mapId, userName))).merge(
action$.ofType(USER_SESSION_LOADED).switchMap(({session}) => {
const mapSession = session?.map && {
map: session.map
const sessionData = {
...(session?.map && {map: session.map}),
...(session?.featureGrid && {featureGrid: session.featureGrid})
};
return Observable.merge(
mapFlowWithOverride(configName, mapId, config, mapInfo, store.getState(), mapSession),
mapFlowWithOverride(configName, mapId, config, mapInfo, store.getState(), sessionData),
Observable.of(userSessionStartSaving())
);
})
Expand Down
7 changes: 4 additions & 3 deletions web/client/epics/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ const createSessionFlow = (mapId, contextName, action$, getState) => {
const userName = userSelector(getState())?.name;
return Observable.of(loadUserSession(buildSessionName(id, mapId, userName))).merge(
action$.ofType(USER_SESSION_LOADED).take(1).switchMap(({session}) => {
const mapSession = session?.map && {
map: session.map
const sessionData = {
...(session?.map && {map: session.map}),
...(session?.featureGrid && {featureGrid: session.featureGrid})
};
const contextSession = session?.context && {
...session.context
};
return Observable.merge(
Observable.of(clearMapTemplates()),
createContextFlow(id, contextSession, getState).catch(e => {throw new ContextError(e); }),
createMapFlow(mapId, data && data.mapConfig, mapSession, action$, getState).catch(e => { throw new MapError(e); }),
createMapFlow(mapId, data && data.mapConfig, sessionData, action$, getState).catch(e => { throw new MapError(e); }),
Observable.of(setUserSession(session)),
Observable.of(userSessionStartSaving())
);
Expand Down
9 changes: 8 additions & 1 deletion web/client/reducers/__tests__/featuregrid-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ import {
storeAdvancedSearchFilter,
setUp,
setTimeSync,
setPagination, setViewportFilter
setPagination,
setViewportFilter
} from '../../actions/featuregrid';

import {isViewportFilterActive, paginationSelector, useLayerFilterSelector} from '../../selectors/featuregrid';


import { featureTypeLoaded, createQuery, updateQuery } from '../../actions/wfsquery';
import { changeDrawingStatus } from '../../actions/draw';
import { configureMap } from '../../actions/config';
import museam from '../../test-resources/wfs/museam.json';
describe('Test the featuregrid reducer', () => {

Expand Down Expand Up @@ -455,4 +457,9 @@ describe('Test the featuregrid reducer', () => {
const newState = featuregrid(undefined, setViewportFilter(true));
expect(isViewportFilterActive({ featuregrid: newState })).toEqual(true);
});
it('configureMap', () => {
const featureGrid = {attributes: {col1: {hide: true}}};
const newState = featuregrid(undefined, configureMap({featureGrid}));
expect(newState.attributes).toEqual(featureGrid.attributes);
});
});
4 changes: 4 additions & 0 deletions web/client/reducers/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
SET_PAGINATION,
SET_VIEWPORT_FILTER
} from '../actions/featuregrid';
import { MAP_CONFIG_LOADED } from '../actions/config';

import { FEATURE_TYPE_LOADED, QUERY_CREATE, UPDATE_QUERY } from '../actions/wfsquery';
import { CHANGE_DRAWING_STATUS } from '../actions/draw';
Expand Down Expand Up @@ -443,6 +444,9 @@ function featuregrid(state = emptyResultsState, action) {
case SET_VIEWPORT_FILTER: {
return assign({}, state, {viewportFilter: action.value});
}
case MAP_CONFIG_LOADED: {
return {...state, ...get(action, 'config.featureGrid', {})};
}
default:
return state;
}
Expand Down
10 changes: 10 additions & 0 deletions web/client/selectors/__tests__/mapsave-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const state = {
layers: [{
id: "TEST", title: "Test1", checked: true
}]
},
featuregrid: {
attributes: {
col1: {hide: true}
}
}
};
describe('Test mapsave selectors', () => {
Expand All @@ -61,6 +66,11 @@ describe('Test mapsave selectors', () => {
id: "TEST", title: "Test1", checked: true
}]);
});
it('check featuregrid is selected', () => {
const retVal = mapOptionsToSaveSelector(state);
expect(retVal.featureGrid).toBeTruthy();
expect(retVal.featureGrid.attributes).toEqual({col1: {hide: true}});
});
it('check custom save handlers', () => {
registerCustomSaveHandler('custom', (s) => s.custom);
const retVal = mapOptionsToSaveSelector(state);
Expand Down
10 changes: 6 additions & 4 deletions web/client/selectors/__tests__/usersession-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ describe('Test usersession selector', () => {
expect(userSessionNameSelector({context: {resource: {id: "c"}}, mapInitialConfig: {mapId: "m"}, security: { user: {name: "user"} }})).toBe("c.m.user");
});
it('test userSessionToSaveSelector', () => {
const state = userSessionToSaveSelector({layers: {flat: [{}], groups: [{}]}, map: { center: {x: 10, y: 40}, zoom: 6}});
expect(state).toExist();
expect(state.map).toExist();
const state = userSessionToSaveSelector({layers: {flat: [{}], groups: [{}]}, map: { center: {x: 10, y: 40}, zoom: 6}, featuregrid: {attributes: {col1: {hide: true}}}});
expect(state).toBeTruthy();
expect(state.map).toBeTruthy();
expect(state.map.zoom).toBe(6);
expect(state.map.center.x).toBe(10);
expect(state.map.center.y).toBe(40);
expect(state.map.layers).toExist();
expect(state.map.layers).toBeTruthy();
expect(state.map.layers.length).toBe(1);
expect(state.map.groups.length).toBe(1);
expect(state.featureGrid).toBeTruthy();
expect(state.featureGrid.attributes).toBeTruthy();
});
});
4 changes: 4 additions & 0 deletions web/client/selectors/mapsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { layersSelector, groupsSelector } from '../selectors/layers';
import { backgroundListSelector } from '../selectors/backgroundselector';
import { textSearchConfigSelector, bookmarkSearchConfigSelector } from './searchconfig';
import { customAttributesSettingsSelector } from "./featuregrid";

const customSaveHandlers = {};

Expand Down Expand Up @@ -54,6 +55,9 @@ export const basicMapOptionsToSaveSelector = createStructuredSelector({
endValuesSupport: endValuesSupportSelector,
snapRadioButtonEnabled: snapRadioButtonEnabledSelector,
layers: timelineLayersSetting
}),
featureGrid: createStructuredSelector({
attributes: customAttributesSettingsSelector
})
});

Expand Down
26 changes: 18 additions & 8 deletions web/client/selectors/usersession.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@
*/

import ConfigUtils from '../utils/ConfigUtils';
import {createSelector} from "reselect";
import {contextResourceSelector} from "./context";
import {userSelector} from "./security";
import {mapSelector} from "./map";
import {layersSelector, rawGroupsSelector} from "./layers";
import {mapIdSelector} from "./mapInitialConfig";
import { createSelector } from "reselect";
import { contextResourceSelector } from "./context";
import { userSelector } from "./security";
import { mapSelector } from "./map";
import { layersSelector, rawGroupsSelector } from "./layers";
import { mapIdSelector } from "./mapInitialConfig";
import { customAttributesSettingsSelector } from "./featuregrid";

export const userSessionIdSelector = (state) => state.usersession && state.usersession.id || null;
export const userSessionSelector = (state) => state.usersession && state.usersession.session || null;

export const userSessionToSaveSelector = createSelector([mapSelector, layersSelector, rawGroupsSelector],
(map, layers, groups) => {
export const userSessionToSaveSelector = createSelector(
[
mapSelector,
layersSelector,
rawGroupsSelector,
customAttributesSettingsSelector
],
(map, layers, groups, featureGridAttributes) => {
const {center, zoom} = map;
return {
map: {
center,
zoom,
layers,
groups
},
featureGrid: {
attributes: featureGridAttributes
}
};
});
Expand Down

0 comments on commit bee29bb

Please sign in to comment.