Skip to content

Commit dfe2022

Browse files
committed
review changes
1 parent bc3d1b8 commit dfe2022

4 files changed

Lines changed: 41 additions & 19 deletions

File tree

web/client/plugins/ResourcesCatalog/DeleteResource.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { searchResources } from './actions/resources';
1616
import { getPendingChanges } from './selectors/save';
1717
import { push } from 'connected-react-router';
1818
import useIsMounted from '../../hooks/useIsMounted';
19+
import { userSelector } from '../../selectors/security';
1920

2021
/**
2122
* Plugin to delete a resource
@@ -26,6 +27,7 @@ import useIsMounted from '../../hooks/useIsMounted';
2627
* @prop {string} cfg.redirectTo optional redirect path after delete completion
2728
*/
2829
function DeleteResource({
30+
user,
2931
resource,
3032
component,
3133
onRefresh,
@@ -65,7 +67,7 @@ function DeleteResource({
6567
}));
6668
}
6769
}
68-
if (!(resource?.id && resource?.canDelete)) {
70+
if (!(user && resource?.id && resource?.canDelete)) {
6971
return null;
7072
}
7173
return (
@@ -101,7 +103,8 @@ const deleteResourcesConnect = connect(
101103
}
102104
const pendingChanges = getPendingChanges(state, { resourceType: 'MAP', ...props });
103105
return pendingChanges?.resource;
104-
}
106+
},
107+
user: userSelector
105108
}),
106109
{
107110
onRefresh: searchResources.bind(null, { refresh: true }),

web/client/plugins/ResourcesCatalog/actions/resources.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export function loadingResources(loading, id) {
5353
};
5454
}
5555

56-
// TODO PR
5756
export function unloadResources() {
5857
return {
5958
type: UNLOAD_RESOURCES

web/client/plugins/ResourcesCatalog/epics/__tests__/resources-test.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,40 @@
77
*/
88
import expect from 'expect';
99

10+
import { SET_SHOW_DETAILS, UNLOAD_RESOURCES } from '../../actions/resources';
1011

11-
import { UNLOAD_RESOURCES } from '../../actions/resources';
12-
import { LOGOUT } from '../../../../actions/security';
13-
14-
import {unloadCatalogResourcesOnLogout} from '../resources';
12+
import { unloadCatalogResourcesOnAuthentication } from '../resources';
1513

1614
import { testEpic } from '../../../../epics/__tests__/epicTestUtils';
15+
import { loginSuccess, logout } from '../../../../actions/security';
1716

1817
describe('resources Epics', () => {
19-
it('unloadResources epic', (done) => {
20-
const action = { type: LOGOUT };
21-
testEpic(unloadCatalogResourcesOnLogout, 1, action, ([update]) => {
22-
expect(update).toExist();
23-
expect(update.type).toBe(UNLOAD_RESOURCES);
24-
done();
18+
it('unloadResources on logout epic', (done) => {
19+
testEpic(unloadCatalogResourcesOnAuthentication, 2, logout(), ([showDetailsAction, unloadResourcesAction]) => {
20+
try {
21+
expect(showDetailsAction).toBeTruthy();
22+
expect(showDetailsAction.type).toBe(SET_SHOW_DETAILS);
23+
expect(showDetailsAction.show).toBe(false);
24+
expect(unloadResourcesAction).toBeTruthy();
25+
expect(unloadResourcesAction.type).toBe(UNLOAD_RESOURCES);
26+
done();
27+
} catch (e) {
28+
done(e);
29+
}
30+
}, {});
31+
});
32+
it('unloadResources on login success epic', (done) => {
33+
testEpic(unloadCatalogResourcesOnAuthentication, 2, loginSuccess(), ([showDetailsAction, unloadResourcesAction]) => {
34+
try {
35+
expect(showDetailsAction).toBeTruthy();
36+
expect(showDetailsAction.type).toBe(SET_SHOW_DETAILS);
37+
expect(showDetailsAction.show).toBe(false);
38+
expect(unloadResourcesAction).toBeTruthy();
39+
expect(unloadResourcesAction.type).toBe(UNLOAD_RESOURCES);
40+
done();
41+
} catch (e) {
42+
done(e);
43+
}
2544
}, {});
2645
});
2746
});
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
/*
2-
* Copyright 2017, GeoSolutions Sas.
2+
* Copyright 2025, GeoSolutions Sas.
33
* All rights reserved.
44
*
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree.
77
*/
88
import Rx from 'rxjs';
99

10-
import { LOGOUT } from '../../../actions/security';
10+
import { LOGOUT, LOGIN_SUCCESS } from '../../../actions/security';
1111

12-
import { unloadResources } from '../actions/resources';
12+
import { setShowDetails, unloadResources } from '../actions/resources';
1313

14-
export const unloadCatalogResourcesOnLogout = (actions$) =>
15-
actions$.ofType(LOGOUT)
14+
export const unloadCatalogResourcesOnAuthentication = (actions$) =>
15+
actions$.ofType(LOGOUT, LOGIN_SUCCESS)
1616
.switchMap(() => {
1717
return Rx.Observable.of(
18+
setShowDetails(false),
1819
unloadResources()
1920
);
2021
});
2122

22-
export default { unloadCatalogResourcesOnLogout };
23+
export default { unloadCatalogResourcesOnAuthentication };

0 commit comments

Comments
 (0)