Skip to content

Commit

Permalink
Fix geosolutions-it#10062 enhanced the way details are stored within …
Browse files Browse the repository at this point in the history
…app (geosolutions-it#10149)

* geosolutions-it#10062 fix details aswell

* fix tests

* fix tests
  • Loading branch information
MV88 authored Apr 3, 2024
1 parent bbfa7d7 commit d246b2c
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 124 deletions.
74 changes: 12 additions & 62 deletions web/client/epics/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ describe('config epics', () => {
checkActions
);
});
it('loadMapInfo will not fetch data and attributes', (done) => {
it('loadMapInfo will not fetch data', (done) => {
const checkActions = ([a, b]) => {
expect(a).toExist();
expect(b).toExist();
expect(b.type).toBe(MAP_INFO_LOADED);
expect(b?.info?.data).toBeFalsy();
expect(b?.info?.data).toEqual({});
done();
};
testEpic(loadMapInfoEpic,
Expand All @@ -360,63 +360,25 @@ describe('config epics', () => {
id: mapId,
name: "name"
};
const mapAttributesEmptyDetails = {
"AttributeList": {
"Attribute": [
{
"name": "details",
"type": "STRING",
"value": EMPTY_RESOURCE_VALUE
}
]
}
};

const mapAttributesWithoutDetails = {
"AttributeList": {
"Attribute": []
const mapWithAttr = {
id: mapId,
name: "name",
attributes: {
details: "blabla",
detailsSettings: {}
}
};

const mapAttributesWithDetails = {
AttributeList: {
Attribute: [
{
name: 'details',
type: 'STRING',
value: 'rest\/geostore\/data\/1\/raw?decode=datauri'
},
{
name: "thumbnail",
type: "STRING",
value: 'rest\/geostore\/data\/1\/raw?decode=datauri'
},
{
name: 'owner',
type: 'STRING',
value: 'admin'
}
]
}
};
it('test storeDetailsInfoEpic', (done) => {
mockAxios.onGet().reply(200, mapAttributesWithDetails);
const NUM_ACTION = 2;
testEpic(addTimeoutEpic(storeDetailsInfoEpic), NUM_ACTION, mapInfoLoaded(map, mapId), actions => {
const NUM_ACTION = 1;
testEpic(storeDetailsInfoEpic, NUM_ACTION, mapInfoLoaded(mapWithAttr, mapId), actions => {
expect(actions.length).toBe(NUM_ACTION);
actions.map((action) => {

switch (action.type) {
case DETAILS_LOADED:
expect(action.id).toBe(mapId);
expect(action.detailsUri).toBe("rest/geostore/data/1/raw?decode=datauri");
break;
case MAP_INFO_LOADED:
expect(action.info.attributes).toEqual({
details: "rest/geostore/data/1/raw?decode=datauri",
owner: "admin",
thumbnail: "rest/geostore/data/1/raw?decode=datauri"
});
expect(action.detailsUri).toBe("blabla");
break;
default:
expect(true).toBe(false);
Expand All @@ -429,22 +391,10 @@ describe('config epics', () => {
});
it('test storeDetailsInfoEpic when api returns NODATA value', (done) => {
// const mock = new MockAdapter(axios);
mockAxios.onGet().reply(200, mapAttributesEmptyDetails);
const NUM_ACTION = 1;
testEpic(addTimeoutEpic(storeDetailsInfoEpic), NUM_ACTION, mapInfoLoaded(map, mapId), actions => {
expect(actions.length).toBe(NUM_ACTION);
actions.map((action) => expect(action.type).toBe(MAP_INFO_LOADED));
done();
}, {mapInitialConfig: {
"mapId": mapId
}});
});
it('test storeDetailsInfoEpic when api doesnt return details', (done) => {
mockAxios.onGet().reply(200, mapAttributesWithoutDetails);
const NUM_ACTION = 1;
testEpic(addTimeoutEpic(storeDetailsInfoEpic), NUM_ACTION, mapInfoLoaded(map, mapId), actions => {
expect(actions.length).toBe(NUM_ACTION);
actions.map((action) => expect(action.type).toBe(MAP_INFO_LOADED));
actions.map((action) => expect(action.type).toBe("EPICTEST:TIMEOUT"));
done();
}, {mapInitialConfig: {
"mapId": mapId
Expand Down
4 changes: 3 additions & 1 deletion web/client/epics/__tests__/details-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const mapTestState = {
map: {
present: {
info: {
details: encodeURIComponent(detailsUri)
attributes: {
details: encodeURIComponent(detailsUri)
}
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions web/client/epics/__tests__/tutorial-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,10 @@ describe('tutorial Epics', () => {
present: {
mapId: "123",
info: {
detailsSettings: {
showAtStartup: true
attributes: {
detailsSettings: {
showAtStartup: true
}
}
}
}
Expand Down
51 changes: 14 additions & 37 deletions web/client/epics/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const loadMapInfoEpic = action$ =>
action$.ofType(LOAD_MAP_INFO)
.switchMap(({mapId}) =>
Observable
.defer(() => Persistence.getResource(mapId, { includeAttributes: false, withData: false }))
.defer(() => Persistence.getResource(mapId, { includeAttributes: true, withData: false }))
.map(resource => mapInfoLoaded(resource, mapId))
.catch((e) => Observable.of(mapInfoLoadError(mapId, e)))
.startWith(mapInfoLoadStart(mapId))
Expand All @@ -206,44 +206,21 @@ export const loadMapInfoEpic = action$ =>
*/
export const storeDetailsInfoEpic = (action$, store) =>
action$.ofType(MAP_INFO_LOADED)
.take(1)
.switchMap(() => {
.filter(() => {
const mapId = mapIdSelector(store.getState());
return !!mapId;
})
.switchMap(({mapId, info: {attributes}}) => {
const isTutorialRunning = store.getState()?.tutorial?.run;
return !mapId
? Observable.empty()
: Observable.fromPromise(
GeoStoreApi.getResourceAttributes(mapId)
).switchMap((attributes) => {
let details = find(attributes, {name: 'details'});
const detailsSettingsAttribute = find(attributes, {name: 'detailsSettings'});
let detailsSettings = {};
const mapInfoLoadedUpdateAction = mapInfoLoaded(
{
attributes: attributes.reduce((acc, curr) => ({
...acc,
[curr.name]: curr.value
}), {})
},
mapId,
true
);
if (!details || details.value === EMPTY_RESOURCE_VALUE) {
return Observable.of(mapInfoLoadedUpdateAction);
}

try {
detailsSettings = JSON.parse(detailsSettingsAttribute.value);
} catch (e) {
detailsSettings = {};
}

return Observable.from([
mapInfoLoadedUpdateAction,
detailsLoaded(mapId, details.value, detailsSettings),
...(detailsSettings.showAtStartup && !isTutorialRunning ? [openDetailsPanel()] : [])]
);
});
let details = attributes?.details;
const detailsSettings = attributes?.detailsSettings;
if (!details || details.value === EMPTY_RESOURCE_VALUE) {
return Observable.empty();
}
return Observable.from([
detailsLoaded(mapId, details, detailsSettings),
...(detailsSettings.showAtStartup && !isTutorialRunning ? [openDetailsPanel()] : [])]
);
});
export const storeDetailsInfoDashboardEpic = (action$, store) =>
action$.ofType(DASHBOARD_LOADED)
Expand Down
2 changes: 1 addition & 1 deletion web/client/reducers/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Test the mapConfig reducer', () => {
}, {type: DETAILS_LOADED, id: 1, detailsUri});
expect(state.map).toExist();
expect(state.map.info).toExist();
expect(state.map.info.details).toBe(detailsUri);
expect(state.map.info.attributes.details).toBe(detailsUri);
});
it('DETAILS_LOADED Dahboard', () => {
const detailsUri = "details/uri";
Expand Down
25 changes: 18 additions & 7 deletions web/client/reducers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import { LOCATION_CHANGE } from 'connected-react-router';

import {
MAP_CONFIG_LOADED,
Expand Down Expand Up @@ -33,6 +34,12 @@ import {
function mapConfig(state = null, action) {
let map;
switch (action.type) {
case LOCATION_CHANGE: {
return {
...state,
mapInitialConfig: {}
};
}
case MAP_CONFIG_LOADED:
let size = state && state.map && state.map.present && state.map.present.size || state && state.map && state.map.size;
// bbox is taken from the state to keep widgets having correct dataset after map is saved or saved as.
Expand Down Expand Up @@ -92,13 +99,17 @@ function mapConfig(state = null, action) {
let dashboardResource = state.dashboard?.resource;
map = state && state.map && state.map.present ? state.map.present : state && state.map;
if (map && map.mapId.toString() === action.id.toString()) {
map = assign({}, map, {
info:
assign({}, map.info, {
details: action.detailsUri,
detailsSettings: action.detailsSettings
})
});
map = {
...map,
info: {
...map.info,
attributes: {
...map.info?.attributes,
details: action.detailsUri || map.info?.attributes?.details,
detailsSettings: action.detailsSettings || map.info?.attributes?.detailsSettings
}
}
};
return assign({}, state, {map: map});
} else if (dashboardResource && dashboardResource.id === action.id.toString()) {
dashboardResource = assign({}, dashboardResource, {
Expand Down
3 changes: 3 additions & 0 deletions web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
UPDATE_MAP_VIEW,
UPDATE_MAP_OPTIONS
} from '../actions/map';
import { LOCATION_CHANGE } from 'connected-react-router';

import assign from 'object-assign';
import MapUtils from '../utils/MapUtils';
Expand All @@ -41,6 +42,8 @@ function mapConfig(state = {eventListeners: {}}, action) {
return assign({}, state, {
mousePointer: action.pointer
});
case LOCATION_CHANGE:
return assign({}, {eventListeners: {}});
case CHANGE_ZOOM_LVL:
return assign({}, state, {
zoom: action.zoom,
Expand Down
9 changes: 6 additions & 3 deletions web/client/selectors/__tests__/contextcreator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('contextcreator selectors', () => {
name: undefined
}
});
expect(generateContextResource({
const source = {
map: {
present: {
zoom: 10
Expand All @@ -114,7 +114,8 @@ describe('contextcreator selectors', () => {
}
}
}
})).toEqual({
};
const expected = {
category: 'CONTEXT',
data: {
mapConfig: {
Expand Down Expand Up @@ -173,6 +174,8 @@ describe('contextcreator selectors', () => {
userPlugins: []
},
metadata: { name: undefined }
});
};
const generatedSource = generateContextResource(source);
expect(generatedSource).toEqual(expected);
});
});
6 changes: 3 additions & 3 deletions web/client/selectors/__tests__/dashboard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
dashboardIsNewServiceSelector,
dashboardSaveServiceSelector,
dashboardResourceInfoSelector,
dashbaordInfoDetailsUriFromIdSelector,
dashboardInfoDetailsUriFromIdSelector,
dashboardInfoDetailsSettingsFromIdSelector,
canEditServiceSelector
} from '../dashboard';
Expand Down Expand Up @@ -132,8 +132,8 @@ describe('dashboard selectors', () => {
resource: resource
}})).toBe(resource);
});
it("test dashbaordInfoDetailsUriFromIdSelector", () => {
expect(dashbaordInfoDetailsUriFromIdSelector({dashboard: {
it("test dashboardInfoDetailsUriFromIdSelector", () => {
expect(dashboardInfoDetailsUriFromIdSelector({dashboard: {
resource: {
attributes: {
details: "Details"
Expand Down
4 changes: 3 additions & 1 deletion web/client/selectors/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('Test map selectors', () => {
map: {
present: {
info: {
details
attributes: {
details
}
}
}
}});
Expand Down
2 changes: 1 addition & 1 deletion web/client/selectors/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const dashboardCatalogModeSelector = state => state && state.dashboard &&
export const dashboardIsNewServiceSelector = state => state.dashboard?.isNew || false;
export const dashboardSaveServiceSelector = state => state.dashboard?.saveServiceLoading || false;
export const dashboardResourceInfoSelector = state => get(state, "dashboard.resource");
export const dashbaordInfoDetailsUriFromIdSelector = state => state?.dashboard?.resource?.attributes?.details;
export const dashboardInfoDetailsUriFromIdSelector = state => state?.dashboard?.resource?.attributes?.details;
export const dashboardInfoDetailsSettingsFromIdSelector = state => get(dashboardResource(state), "attributes.detailsSettings");
export const editingAllowedRolesSelector = state => get(state, "dashboard.servicesPermission.editingAllowedRoles", []);
export const editingAllowedGroupsSelector = state => get(state, "dashboard.servicesPermission.editingAllowedGroups", []);
Expand Down
8 changes: 4 additions & 4 deletions web/client/selectors/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
* LICENSE file in the root directory of this source tree.
*/

import { dashboardInfoDetailsSettingsFromIdSelector, getDashboardId, dashbaordInfoDetailsUriFromIdSelector } from "./dashboard";
import { dashboardInfoDetailsSettingsFromIdSelector, getDashboardId, dashboardInfoDetailsUriFromIdSelector } from "./dashboard";
import { mapIdSelector, mapInfoDetailsSettingsFromIdSelector, mapInfoDetailsUriFromIdSelector } from "./map";

export const detailsTextSelector = state => state?.details?.detailsText;

export const detailsUriSelector = state => {
const mapId = mapIdSelector(state);
const dashboardId = getDashboardId(state);
// todo: this is now for map and dashboard only, in the future if something else needs to use this like geostory, an additional contional should be added
let detailsUri = dashboardId && dashbaordInfoDetailsUriFromIdSelector(state, dashboardId) || mapId && mapInfoDetailsUriFromIdSelector(state, mapId);
// todo: this is now for map and dashboard only, in the future if something else needs to use this like geostory, an additional condition should be added
let detailsUri = dashboardId && dashboardInfoDetailsUriFromIdSelector(state) || mapId && mapInfoDetailsUriFromIdSelector(state);
return detailsUri;
};

export const detailsSettingsSelector = state => {
const mapId = mapIdSelector(state);
const dashboardId = getDashboardId(state);
// todo: this is now for map and dashboard only, in the future if something else needs to use this like geostory, an additional contional should be added
let detailsSettings = dashboardId && dashboardInfoDetailsSettingsFromIdSelector(state, dashboardId) || mapId && mapInfoDetailsSettingsFromIdSelector(state, mapId);
let detailsSettings = dashboardId && dashboardInfoDetailsSettingsFromIdSelector(state) || mapId && mapInfoDetailsSettingsFromIdSelector(state);
return detailsSettings;
};
4 changes: 2 additions & 2 deletions web/client/selectors/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const mapIdSelector = (state) => get(state, "mapInitialConfig.mapId") &&
export const mapInfoSelector = state => get(mapSelector(state), "info");
export const mapInfoLoadingSelector = state => get(mapSelector(state), "loadingInfo", false);
export const mapSaveErrorsSelector = state => get(mapSelector(state), "mapSaveErrors");
export const mapInfoDetailsUriFromIdSelector = state => get(mapInfoSelector(state), "details");
export const mapInfoDetailsSettingsFromIdSelector = state => get(mapInfoSelector(state), "detailsSettings");
export const mapInfoDetailsUriFromIdSelector = state => get(mapInfoSelector(state), "attributes.details");
export const mapInfoDetailsSettingsFromIdSelector = state => get(mapInfoSelector(state), "attributes.detailsSettings");
export const mapIsEditableSelector = state => {
const mapInfoCanEdit = get(mapInfoSelector(state), 'canEdit');
if (mapInfoCanEdit === undefined) {
Expand Down

0 comments on commit d246b2c

Please sign in to comment.