Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9683: add Details Panel for MS dashboard #9689

Merged
merged 9 commits into from
Nov 21, 2023
12 changes: 10 additions & 2 deletions web/client/actions/__tests__/details-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ describe('details actions tests', () => {
const a = closeDetailsPanel();
expect(a.type).toBe(CLOSE_DETAILS_PANEL);
});
it('detailsLoaded', () => {
it('detailsLoaded for map', () => {
const mapId = 1;
const detailsUri = "sada/da/";
const a = detailsLoaded(mapId, detailsUri);
expect(a.type).toBe(DETAILS_LOADED);
expect(a.detailsUri).toBe(detailsUri);
expect(a.mapId).toBe(mapId);
expect(a.id).toBe(mapId);
});
it('detailsLoaded for dashboard', () => {
const dashboardId = 1;
const detailsUri = "sada/da/";
const a = detailsLoaded(dashboardId, detailsUri);
expect(a.type).toBe(DETAILS_LOADED);
expect(a.detailsUri).toBe(detailsUri);
expect(a.id).toBe(dashboardId);
});
it('updateDetails', () => {
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
const a = updateDetails('text');
Expand Down
8 changes: 4 additions & 4 deletions web/client/actions/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export const NO_DETAILS_AVAILABLE = "NO_DETAILS_AVAILABLE";
* @memberof actions.details
* @return {action} type `UPDATE_DETAILS`
*/
export const updateDetails = (detailsText) => ({
export const updateDetails = (detailsText, resourceId) => ({
type: UPDATE_DETAILS,
detailsText
detailsText, id: resourceId
});

/**
* detailsLoaded
* @memberof actions.details
* @return {action} type `DETAILS_LOADED`
*/
export const detailsLoaded = (mapId, detailsUri, detailsSettings) => ({
export const detailsLoaded = (resourceId, detailsUri, detailsSettings) => ({
type: DETAILS_LOADED,
mapId,
id: resourceId,
detailsUri,
detailsSettings
});
Expand Down
8 changes: 5 additions & 3 deletions web/client/components/details/DetailsPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class DetailsPanel extends React.Component {
panelClassName: PropTypes.string,
style: PropTypes.object,
onClose: PropTypes.func,
width: PropTypes.number
width: PropTypes.number,
isDashboard: PropTypes.bool
};

static contextTypes = {
Expand All @@ -41,14 +42,15 @@ class DetailsPanel extends React.Component {
},
active: false,
panelClassName: "details-panel",
width: 550
width: 550,
isDashboard: false
};

render() {
return (
<ResponsivePanel
containerId="details-container"
containerClassName="dock-container"
containerClassName={` dock-container ${this.props.isDashboard ? "leftZeroPanel" : ""}`}
containerStyle={this.props.dockStyle}
open={this.props.active}
size={this.props.width}
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/layout/BorderLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React from 'react';
* /></BorderLayout>
*
*/
export default ({id, children, header, footer, columns, height, style = {}, className, bodyClassName = "ms2-border-layout-body"}) =>
export default ({id, children, header, footer, columns, height, style = {}, className, bodyClassName = "ms2-border-layout-body" }) =>
(<div id={id} className={className} style={{
display: "flex",
flexDirection: "column",
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/resources/ResourceGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default ({
edit,
nameFieldFilter,
category: categoryName,
enableDetails: categoryName === 'MAP',
enableDetails: categoryName === 'MAP' || categoryName === 'DASHBOARD',
onResourceLoad
// resource
})}
Expand Down
11 changes: 6 additions & 5 deletions web/client/components/resources/modals/enhancers/handleSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export default mapPropsStream(props$ => {
.withLatestFrom(props$)
.switchMap(([resource, props]) =>
updateResource(resource)
.flatMap(rid => resource.category === 'MAP' ? updateResourceAttribute({
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
id: rid,
name: 'detailsSettings',
value: JSON.stringify(resource.attributes?.detailsSettings || {})
}) : Rx.Observable.of(rid))
.flatMap(rid => (['MAP', 'DASHBOARD'].includes(resource.categoryName)) ?
updateResourceAttribute({
id: rid,
name: 'detailsSettings',
value: JSON.stringify(resource.attributes?.detailsSettings || {})
}) : Rx.Observable.of(rid))
.do(() => {
if (props) {
if (props.onClose) {
Expand Down
10 changes: 9 additions & 1 deletion web/client/configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,15 @@
"FeedbackMask"
],
"dashboard": [
"BurgerMenu",
"Details",
"AddWidgetDashboard",
"MapConnectionDashboard",
{
"name": "SidebarMenu",
"cfg" : {
"containerPosition": "columns"
}
},
{
"name": "Dashboard",
"cfg": {
Expand Down
107 changes: 105 additions & 2 deletions web/client/epics/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import expect from 'expect';
import {head} from 'lodash';
import {loadMapConfigAndConfigureMap, loadMapInfoEpic, storeDetailsInfoEpic} from '../config';
import {loadMapConfigAndConfigureMap, loadMapInfoEpic, storeDetailsInfoDashboardEpic, storeDetailsInfoEpic} from '../config';
import {LOAD_USER_SESSION} from '../../actions/usersession';
import {
loadMapConfig,
Expand All @@ -30,6 +30,7 @@ import testConfigEPSG31468 from "raw-loader!../../test-resources/testConfigEPSG3
import ConfigUtils from "../../utils/ConfigUtils";
import { DETAILS_LOADED } from '../../actions/details';
import { EMPTY_RESOURCE_VALUE } from '../../utils/MapInfoUtils';
import { dashboardLoaded } from '../../actions/dashboard';

const api = {
getResource: () => Promise.resolve({mapId: 1234})
Expand Down Expand Up @@ -345,7 +346,7 @@ describe('config epics', () => {

switch (action.type) {
case DETAILS_LOADED:
expect(action.mapId).toBe(mapId);
expect(action.id).toBe(mapId);
expect(action.detailsUri).toBe("rest/geostore/data/1/raw?decode=datauri");
break;
default:
Expand Down Expand Up @@ -379,5 +380,107 @@ describe('config epics', () => {
}});
});
});

describe("storeDetailsInfoDashboardEpic", () => {
beforeEach(done => {
mockAxios = new MockAdapter(axios);
setTimeout(done);
});

afterEach(done => {
mockAxios.restore();
setTimeout(done);
});
const dashboardId = 1;
const dashboardAttributesEmptyDetails = {
"AttributeList": {
"Attribute": [
{
"name": "details",
"type": "STRING",
"value": EMPTY_RESOURCE_VALUE
}
]
}
};

const dashboardAttributesWithoutDetails = {
"AttributeList": {
"Attribute": []
}
};

const dashboardAttributesWithDetails = {
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 storeDetailsInfoDashboardEpic', (done) => {
mockAxios.onGet().reply(200, dashboardAttributesWithDetails);
testEpic(addTimeoutEpic(storeDetailsInfoDashboardEpic), 1, dashboardLoaded("RES", "DATA"), actions => {
expect(actions.length).toBe(1);
actions.map((action) => {

switch (action.type) {
case DETAILS_LOADED:
expect(action.id).toBe(dashboardId);
expect(action.detailsUri).toBe("rest/geostore/data/1/raw?decode=datauri");
break;
default:
expect(true).toBe(false);
}
});
done();
}, {dashboard: {
resource: {
id: dashboardId,
attributes: {}
}
}});
});
it('test storeDetailsInfoDashboardEpic when api returns NODATA value', (done) => {
// const mock = new MockAdapter(axios);
mockAxios.onGet().reply(200, dashboardAttributesWithoutDetails);
testEpic(addTimeoutEpic(storeDetailsInfoDashboardEpic), 1, dashboardLoaded("RES", "DATA"), actions => {
expect(actions.length).toBe(1);
actions.map((action) => expect(action.type).toBe(TEST_TIMEOUT));
done();
}, {dashboard: {
resource: {
id: dashboardId,
attributes: {}
}
}});
});
it('test storeDetailsInfoDashboardEpic when api doesnt return details', (done) => {
mockAxios.onGet().reply(200, dashboardAttributesEmptyDetails);
testEpic(addTimeoutEpic(storeDetailsInfoDashboardEpic), 1, dashboardLoaded("RES", "DATA"), actions => {
expect(actions.length).toBe(1);
actions.map((action) => expect(action.type).toBe(TEST_TIMEOUT));
done();
}, {dashboard: {
resource: {
id: dashboardId,
attributes: {}
}
}});
});
});
});

26 changes: 11 additions & 15 deletions web/client/epics/__tests__/dashboard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,14 @@ describe('saveDashboard', () => {

const startActions = [saveDashboard(RESOURCE)];
testEpic(saveDashboardMethod, actionsCount, startActions, actions => {
expect(actions.length).toBe(actionsCount);
expect(actions[0].type).toBe(DASHBOARD_LOADING);
expect(actions[0].value).toBe(true);
expect(actions[1].type).toBe(SAVE_ERROR);
expect(actions.length).toBe(2);
expect(actions[0].type).toBe(SAVE_ERROR);
expect(
actions[1].error.status === 403
|| actions[1].error.status === 404
actions[0].error.status === 403
|| actions[0].error.status === 404
).toBeTruthy();
expect(actions[2].type).toBe(DASHBOARD_LOADING);
expect(actions[2].value).toBe(false);
expect(actions[1].type).toBe(DASHBOARD_LOADING);
expect(actions[1].value).toBe(false);
}, BASE_STATE, done);
});

Expand All @@ -364,13 +362,11 @@ describe('saveDashboard', () => {

const startActions = [saveDashboard(withoutMetadata)];
testEpic(saveDashboardMethod, actionsCount, startActions, actions => {
expect(actions.length).toBe(3);
expect(actions[0].type).toBe(DASHBOARD_LOADING);
expect(actions[0].value).toBe(true);
expect(actions[1].type).toBe(SAVE_ERROR);
expect(typeof(actions[1].error) === 'string').toBeTruthy();
expect(actions[2].type).toBe(DASHBOARD_LOADING);
expect(actions[2].value).toBe(false);
expect(actions.length).toBe(2);
expect(actions[0].type).toBe(SAVE_ERROR);
expect(typeof(actions[0].error) === 'string').toBeTruthy();
expect(actions[1].type).toBe(DASHBOARD_LOADING);
expect(actions[1].value).toBe(false);
}, BASE_STATE, done);
});
});
Expand Down
Loading
Loading