Skip to content

Commit 3be3cfc

Browse files
kasongoyoofftherailz
authored andcommitted
Featured dashboard section not in sync with dashboard delete. Backport #3933 (#4087)
1 parent 05ee37b commit 3be3cfc

14 files changed

Lines changed: 123 additions & 64 deletions

File tree

web/client/components/maps/MapCard.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,16 @@ class MapCard extends React.Component {
154154
left: 0 }} >
155155
<FitIcon glyph={this.props.map.icon} />
156156
</div> : null}
157-
<ConfirmModal ref="deleteMapModal" show={this.state ? this.state.displayDeleteDialog : false} onHide={this.close} onClose={this.close} onConfirm={this.onConfirmDelete} titleText={<Message msgId="manager.deleteMap" />} confirmText={<Message msgId="manager.deleteMap" />} cancelText={<Message msgId="cancel" />} body={<Message msgId="manager.deleteMapMessage" />} />
157+
<ConfirmModal
158+
ref="deleteMapModal"
159+
show={this.state ? this.state.displayDeleteDialog : false}
160+
onHide={this.close}
161+
onClose={this.close}
162+
onConfirm={this.onConfirmDelete}
163+
titleText={this.props.map.title || this.props.map.name || <Message msgId="resources.deleteConfirmTitle" />}
164+
confirmText={<Message msgId="yes" />}
165+
cancelText={<Message msgId="no" />}
166+
body={<Message msgId="resources.deleteConfirmMessage" />} />
158167
</GridCard>
159168
);
160169
}

web/client/components/resources/ResourceCard.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ class ResourceCard extends React.Component {
139139
onHide={this.close}
140140
onClose={this.close}
141141
onConfirm={this.onConfirmDelete}
142-
title={<Message msgId="resources.deleteConfirmTitle" />}
143-
confirmText={<Message msgId="resources.deleteConfirmButtonText" />}
144-
cancelText={<Message msgId="resources.deleteCancelButtonText" />}>
142+
title={this.props.resource.title || this.props.resource.name || <Message msgId="resources.deleteConfirmTitle" />}
143+
cancelText={<Message msgId="no" />}
144+
confirmText={<Message msgId="yes" />}
145+
>
145146
<Message msgId="resources.deleteConfirmMessage" />
146147
</ConfirmModal>
147148
</GridCard>

web/client/components/resources/__tests__/ResourceCard-test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ describe('This test for ResourceCard', () => {
7878
expect(spyonEdit.calls.length).toEqual(1);
7979
// wait for confirm
8080
expect(spyonDelete.calls.length).toEqual(0);
81-
expect(document.querySelector('.modal-details-sheet-confirm')).toExist();
82-
const confirmBtn = document.querySelectorAll('.modal-footer .btn-default')[1];
81+
expect(document.querySelector('.modal-dialog')).toExist();
82+
const confirmBtn = document.querySelectorAll('.modal-footer .btn-primary')[0];
8383
expect(confirmBtn).toExist();
8484
TestUtils.Simulate.click(confirmBtn);
8585
expect(spyonDelete.calls.length).toEqual(1);

web/client/components/resources/modals/ConfirmModal.jsx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88
const React = require('react');
9-
const Portal = require('../../misc/Portal');
10-
const ResizableModal = require('../../misc/ResizableModal');
9+
const Modal = require('../../misc/Modal');
1110
const Message = require('../../I18N/Message');
11+
const { Button } = require('react-bootstrap');
1212

1313
module.exports = ({
1414
title = <Message msgId="warning" />,
@@ -17,31 +17,38 @@ module.exports = ({
1717
onClose = () => {},
1818
onConfirm = () => {},
1919
show,
20-
children
21-
20+
children,
21+
className = '',
22+
buttonSize,
23+
running = false
2224
}) => {
23-
return (<Portal>
24-
<ResizableModal
25-
size="xs"
26-
clickOutEnabled={false}
27-
showClose={false}
28-
title={title}
29-
bodyClassName="modal-details-sheet-confirm"
30-
show={show}
31-
buttons={[{
32-
text: cancelText,
33-
onClick: () => onClose()
34-
}, {
35-
text: confirmText,
36-
onClick: () => {
37-
onConfirm();
38-
}
39-
}]}>
40-
<div className="ms-alert">
41-
<span className="ms-alert-center">
42-
{children}
43-
</span>
44-
</div>
45-
</ResizableModal>
46-
</Portal>);
25+
const footer = (<span role="footer"><div style={{"float": "left"}}></div>
26+
<Button
27+
disabled={running}
28+
className={className}
29+
key="confirmButton"
30+
bsStyle="primary"
31+
bsSize={buttonSize}
32+
onClick={() => {
33+
onConfirm();
34+
}}>{confirmText}</Button>
35+
{<Button
36+
key="cancelButton"
37+
bsSize={buttonSize}
38+
disabled={running}
39+
onClick={onClose}>{cancelText}</Button>}
40+
</span>);
41+
return (
42+
<Modal show={show} onHide={onClose}>
43+
<Modal.Header key="dialogHeader" closeButton>
44+
<Modal.Title>{title}</Modal.Title>
45+
</Modal.Header>
46+
<Modal.Body>
47+
{children}
48+
</Modal.Body>
49+
<Modal.Footer>
50+
{footer}
51+
</Modal.Footer>
52+
</Modal>);
53+
4754
};

web/client/components/resources/modals/__tests__/Confirm-test.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ describe("ConfirmDialog component", () => {
2121
});
2222

2323
it('creates component with content', () => {
24-
ReactDOM.render(<ConfirmModal show options={{ className: "modal-dialog" }}><div id="TEST">some content</div></ConfirmModal>, document.getElementById("container"));
25-
26-
let background = document.getElementsByClassName("modal-fixed").item(0);
24+
ReactDOM.render(<ConfirmModal show><div id="TEST">some content</div></ConfirmModal>, document.getElementById("container"));
2725
let dialog = document.getElementsByClassName("modal-dialog").item(0);
28-
expect(background).toExist();
2926
expect(dialog).toExist();
30-
expect(document.querySelectorAll('button').length).toBe(2); // close, confirm, cancel
27+
expect(document.querySelectorAll('button').length).toBe(3); // close, confirm, cancel
3128
});
3229

3330
});

web/client/epics/__tests__/maps-test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const {
1414
saveDetails, SET_DETAILS_CHANGED, MAPS_LIST_LOADING, MAPS_LIST_LOADED,
1515
CLOSE_DETAILS_PANEL, closeDetailsPanel, loadMaps, MAPS_GET_MAP_RESOURCES_BY_CATEGORY,
1616
openDetailsPanel, UPDATE_DETAILS, DETAILS_LOADED, getMapResourcesByCategory,
17-
MAP_DELETING, MAP_DELETED, deleteMap, TOGGLE_DETAILS_SHEET,
18-
saveMapResource, MAP_CREATED, DISPLAY_METADATA_EDIT, SAVING_MAP, MAP_UPDATING
17+
MAP_DELETING, MAP_DELETED, deleteMap, mapDeleted, TOGGLE_DETAILS_SHEET,
18+
saveMapResource, MAP_CREATED, DISPLAY_METADATA_EDIT, SAVING_MAP, MAP_UPDATING, MAPS_LOAD_MAP
1919
} = require('../../actions/maps');
2020
const { mapInfoLoaded } = require('../../actions/config');
2121
const {SHOW_NOTIFICATION} = require('../../actions/notifications');
@@ -27,7 +27,7 @@ const {
2727
setDetailsChangedEpic, loadMapsEpic, getMapsResourcesByCategoryEpic,
2828
closeDetailsPanelEpic, fetchDataForDetailsPanel,
2929
fetchDetailsFromResourceEpic, deleteMapAndAssociatedResourcesEpic,
30-
storeDetailsInfoEpic, mapSaveMapResourceEpic} = require('../maps');
30+
storeDetailsInfoEpic, mapSaveMapResourceEpic, reloadMapsEpic} = require('../maps');
3131
const rootEpic = combineEpics(setDetailsChangedEpic, closeDetailsPanelEpic);
3232
const epicMiddleware = createEpicMiddleware(rootEpic);
3333
const mockStore = configureMockStore([epicMiddleware]);
@@ -581,4 +581,13 @@ describe('Create and update flow using persistence api', () => {
581581
done();
582582
});
583583
});
584+
585+
it('test reloadMaps', function(done) {
586+
const callback = actions => {
587+
expect(actions.length).toEqual(1);
588+
expect(actions[0].type).toEqual(MAPS_LOAD_MAP);
589+
done();
590+
};
591+
testEpic(reloadMapsEpic, 1, mapDeleted(9, 'success'), callback);
592+
});
584593
});

web/client/epics/dashboards.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
const Rx = require('rxjs');
99
const { MAPS_LIST_LOADING, ATTRIBUTE_UPDATED} = require('../actions/maps');
10+
const { MAP_DELETED } = require('../actions/maps');
1011
const { DASHBOARD_SAVED } = require('../actions/dashboard');
1112

1213
const { SEARCH_DASHBOARDS, DELETE_DASHBOARD, DASHBOARD_DELETED, RELOAD, searchDashboards, dashboardListLoaded, dashboardDeleted, dashboardsLoading } = require('../actions/dashboards');
@@ -73,7 +74,7 @@ module.exports = {
7374
}))
7475
)),
7576
reloadOnDashboards: (action$, { getState = () => { } }) =>
76-
action$.ofType(DASHBOARD_DELETED, RELOAD, ATTRIBUTE_UPDATED, DASHBOARD_SAVED)
77+
action$.ofType(DASHBOARD_DELETED, MAP_DELETED, RELOAD, ATTRIBUTE_UPDATED, DASHBOARD_SAVED)
7778
.delay(1000) // delay as a workaround for geostore issue #178
7879
.switchMap( () => Rx.Observable.of(searchDashboards(
7980
searchTextSelector(getState()),

web/client/epics/maps.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const {isNil, find} = require('lodash');
1616
const {
1717
SAVE_DETAILS, SAVE_RESOURCE_DETAILS, MAPS_GET_MAP_RESOURCES_BY_CATEGORY,
1818
DELETE_MAP, OPEN_DETAILS_PANEL, MAPS_LOAD_MAP,
19-
CLOSE_DETAILS_PANEL, NO_DETAILS_AVAILABLE, SAVE_MAP_RESOURCE,
19+
CLOSE_DETAILS_PANEL, NO_DETAILS_AVAILABLE, SAVE_MAP_RESOURCE, MAP_DELETED,
2020
setDetailsChanged, updateDetails, mapsLoading, mapsLoaded,
2121
mapDeleting, toggleDetailsEditability, mapDeleted, loadError,
2222
doNothing, detailsLoaded, detailsSaving, onDisplayMetadataEdit,
2323
RESET_UPDATING, resetUpdating, toggleDetailsSheet, getMapResourcesByCategory,
24-
mapUpdating, savingMap, mapCreated, mapError
24+
mapUpdating, savingMap, mapCreated, mapError, loadMaps
2525
} = require('../actions/maps');
2626
const {
2727
resetCurrentMap, EDIT_MAP
@@ -30,7 +30,9 @@ const {closeFeatureGrid} = require('../actions/featuregrid');
3030
const {toggleControl} = require('../actions/controls');
3131
const {
3232
mapPermissionsFromIdSelector, mapThumbnailsUriFromIdSelector,
33-
mapDetailsUriFromIdSelector
33+
mapDetailsUriFromIdSelector,
34+
searchTextSelector,
35+
searchParamsSelector
3436
} = require('../selectors/maps');
3537

3638
const {
@@ -187,6 +189,14 @@ const loadMapsEpic = (action$) =>
187189

188190
});
189191

192+
const reloadMapsEpic = (action$, { getState = () => { } }) =>
193+
action$.ofType(MAP_DELETED)
194+
.delay(1000)
195+
.switchMap(() => Rx.Observable.of(loadMaps(false,
196+
searchTextSelector(getState()),
197+
searchParamsSelector(getState())
198+
)));
199+
190200
const getMapsResourcesByCategoryEpic = (action$) =>
191201
action$.ofType(MAPS_GET_MAP_RESOURCES_BY_CATEGORY)
192202
.switchMap((action) => {
@@ -357,5 +367,6 @@ module.exports = {
357367
setDetailsChangedEpic,
358368
fetchDetailsFromResourceEpic,
359369
saveResourceDetailsEpic,
360-
mapSaveMapResourceEpic
370+
mapSaveMapResourceEpic,
371+
reloadMapsEpic
361372
};

web/client/reducers/__tests__/featuredmaps-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
const expect = require('expect');
99
const {attributeUpdated, mapDeleted, mapMetadataUpdated, permissionsUpdated, mapsLoading, setFeaturedMapsEnabled} = require('../../actions/maps');
10+
const {dashboardDeleted} = require('../../actions/dashboards');
1011
const { isFeaturedMapsEnabled } = require('../../selectors/featuredmaps');
1112
const featuredmaps = require('../featuredmaps');
1213

@@ -36,6 +37,17 @@ describe('Test the featuredmaps reducer', () => {
3637
});
3738
});
3839

40+
it('dashboardDeleted action', () => {
41+
const resourceId = 1;
42+
const result = 'result';
43+
const error = null;
44+
const state = featuredmaps({}, dashboardDeleted(resourceId, result, error));
45+
expect(state.latestResource).toEqual({
46+
resourceId,
47+
deleted: true
48+
});
49+
});
50+
3951
it('mapMetadataUpdated action', () => {
4052
const resourceId = 1;
4153
const name = 'name';

web/client/reducers/__tests__/maps-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const expect = require('expect');
1010
const maps = require('../maps');
1111
const {
1212
mapsLoaded, mapsLoading, loadError, mapCreated, mapUpdating,
13-
mapMetadataUpdated, mapDeleting, mapDeleted, attributeUpdated, thumbnailError, permissionsLoading,
13+
mapMetadataUpdated, mapDeleting, attributeUpdated, thumbnailError, permissionsLoading,
1414
permissionsLoaded, saveMap, permissionsUpdated, resetUpdating,
1515
mapsSearchTextChanged, setShowMapDetails} = require('../../actions/maps');
1616

@@ -128,9 +128,7 @@ describe('Test the maps reducer', () => {
128128
expect(state.results.length).toBe(2);
129129
state = maps(state, mapDeleting(42, "success"));
130130
expect(state.results[1].deleting).toBe(true);
131-
state = maps(state, mapDeleted(42, "success"));
132-
expect(state.results.length).toBe(1);
133-
expect(state.totalCount).toBe(1);
131+
expect(state.totalCount).toBe(2);
134132

135133
});
136134
it('on saveMap', () => {

0 commit comments

Comments
 (0)