Skip to content

Commit 2625543

Browse files
committed
review changes
1 parent 79c8603 commit 2625543

12 files changed

Lines changed: 110 additions & 26 deletions

File tree

web/client/api/ResourcesCatalog.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { castArray } from 'lodash';
1111
import GeoStoreDAO from './GeoStoreDAO';
1212
import { addFilters, getFilterByField, splitFilterValue } from '../utils/ResourcesFiltersUtils';
1313
import { parseResourceProperties } from '../utils/GeostoreUtils';
14+
import { getSupportedResourceTypes } from '../utils/ResourcesUtils';
1415

1516
const applyDoubleQuote = value => `"${value}"`;
1617

@@ -142,7 +143,7 @@ const getFilter = ({
142143
export const requestResources = ({
143144
params,
144145
config
145-
} = {}, { user } = {}, categoriesDict) => {
146+
} = {}, { user } = {}, resourceTypes) => {
146147

147148
const {
148149
page = 1,
@@ -154,7 +155,7 @@ export const requestResources = ({
154155
const sortBy = sort.replace('-', '');
155156
const sortOrder = sort.includes('-') ? 'desc' : 'asc';
156157
const f = castArray(query.f || []);
157-
const categories = user && user?.role ? categoriesDict[user.role] : categoriesDict.COMMON;
158+
const categories = getSupportedResourceTypes(resourceTypes, user?.role);
158159

159160
return searchListByAttributes(getFilter({
160161
q,

web/client/configs/localConfig.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
{
7979
"name": "resourceDetails",
8080
"path": "resources.initialSelectedResource.attributes.details"
81+
},
82+
{
83+
"name": "resourceTypes",
84+
"path": "resources.resourceTypes"
8185
}
8286
],
8387
"userSessions": {
@@ -860,22 +864,26 @@
860864
{
861865
"labelId": "resourcesCatalog.createMap",
862866
"type": "link",
863-
"href": "#/viewer/new"
867+
"href": "#/viewer/new",
868+
"disableIf": "{!context.isResourceTypeSupported('MAP', state('resourceTypes'), state('userrole'))}"
864869
},
865870
{
866871
"labelId": "resourcesCatalog.createDashboard",
867872
"type": "link",
868-
"href": "#/dashboard/"
873+
"href": "#/dashboard/",
874+
"disableIf": "{!context.isResourceTypeSupported('DASHBOARD', state('resourceTypes'), state('userrole'))}"
869875
},
870876
{
871877
"labelId": "resourcesCatalog.createGeoStory",
872878
"type": "link",
873-
"href": "#/geostory/newgeostory/"
879+
"href": "#/geostory/newgeostory/",
880+
"disableIf": "{!context.isResourceTypeSupported('GEOSTORY', state('resourceTypes'), state('userrole'))}"
874881
},
875882
{
876883
"labelId": "resourcesCatalog.createContext",
877884
"type": "link",
878-
"href": "#/context-creator/new"
885+
"href": "#/context-creator/new",
886+
"disableIf": "{!context.isResourceTypeSupported('CONTEXT', state('resourceTypes'), state('userrole'))}"
879887
}
880888
]
881889
}

web/client/plugins/ResourcesCatalog/ResourcesFiltersForm.jsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React from 'react';
10+
import PropTypes from 'prop-types';
1011
import { createPlugin } from '../../utils/PluginsUtils';
1112
import url from 'url';
1213
import { connect } from 'react-redux';
@@ -145,22 +146,26 @@ function ResourcesFiltersForm({
145146
{
146147
id: 'map',
147148
labelId: 'resourcesCatalog.mapsFilter',
148-
type: 'filter'
149+
type: 'filter',
150+
disableIf: '{!context.isResourceTypeSupported("MAP", state("resourceTypes"), state("userrole"))}'
149151
},
150152
{
151153
id: 'dashboard',
152154
labelId: 'resourcesCatalog.dashboardsFilter',
153-
type: 'filter'
155+
type: 'filter',
156+
disableIf: '{!context.isResourceTypeSupported("DASHBOARD", state("resourceTypes"), state("userrole"))}'
154157
},
155158
{
156159
id: 'geostory',
157160
labelId: 'resourcesCatalog.geostoriesFilter',
158-
type: 'filter'
161+
type: 'filter',
162+
disableIf: '{!context.isResourceTypeSupported("GEOSTORY", state("resourceTypes"), state("userrole"))}'
159163
},
160164
{
161165
id: 'context',
162166
labelId: 'resourcesCatalog.contextsFilter',
163-
type: 'filter'
167+
type: 'filter',
168+
disableIf: '{!context.isResourceTypeSupported("CONTEXT", state("resourceTypes"), state("userrole"))}'
164169
}
165170
]
166171
},
@@ -196,14 +201,14 @@ function ResourcesFiltersForm({
196201
width,
197202
height,
198203
user
199-
}) {
204+
}, context) {
200205

201206
const { query } = url.parse(location.search, true);
202207

203208
const parsedConfig = useParsePluginConfigExpressions(monitoredState, {
204209
extent,
205210
fields: fieldsProp
206-
});
211+
}, context?.plugins?.requires);
207212

208213
const {
209214
stickyTop,
@@ -250,6 +255,10 @@ function ResourcesFiltersForm({
250255
);
251256
}
252257

258+
ResourcesFiltersForm.contextTypes = {
259+
plugins: PropTypes.object
260+
};
261+
253262
const ResourcesGridPlugin = connect(
254263
createStructuredSelector({
255264
user: userSelector,

web/client/plugins/ResourcesCatalog/ResourcesGrid.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
import React, { useRef } from 'react';
9+
import React, { useEffect, useRef } from 'react';
1010
import { createPlugin } from '../../utils/PluginsUtils';
1111
import { connect } from 'react-redux';
1212
import { createStructuredSelector } from 'reselect';
@@ -19,6 +19,7 @@ import { getCatalogResources } from '../../api/persistence';
1919
import {
2020
loadingResources,
2121
resetSearchResources,
22+
setResourceTypes,
2223
updateResources,
2324
updateResourcesMetadata
2425
} from './actions/resources';
@@ -412,18 +413,26 @@ function ResourcesGrid({
412413
}
413414
]
414415
},
415-
categories = {
416-
"ADMIN": ["MAP", "DASHBOARD", "GEOSTORY", "CONTEXT"],
417-
"USER": ["MAP", "DASHBOARD", "GEOSTORY"],
418-
"COMMON": ["MAP", "DASHBOARD", "GEOSTORY"]
416+
resourceTypes = {
417+
ADMIN: ["MAP", "DASHBOARD", "GEOSTORY", "CONTEXT"],
418+
anonymous: ["MAP", "DASHBOARD", "GEOSTORY"]
419419
},
420+
onSetResourceTypes,
420421
...props
421422
}, context) {
422423

423424
const { loadedPlugins } = context;
424425

425426
const configuredItems = usePluginItems({ items, loadedPlugins }, []);
426427

428+
const init = useRef(false);
429+
430+
useEffect(() => {
431+
if (!init.current) {
432+
init.current = true;
433+
onSetResourceTypes(resourceTypes);
434+
}
435+
});
427436

428437
const updatedLocation = useRef();
429438
updatedLocation.current = props.location;
@@ -439,7 +448,7 @@ function ResourcesGrid({
439448
<ConnectedResourcesGrid
440449
{...props}
441450
order={order}
442-
requestResources={(...args) => getCatalogResources(...args, categories).toPromise()}
451+
requestResources={(...args) => getCatalogResources(...args, resourceTypes).toPromise()}
443452
configuredItems={configuredItems}
444453
metadata={metadata}
445454
formatHref={handleFormatHref}
@@ -464,7 +473,8 @@ const ResourcesGridPlugin = connect(
464473
setLoading: loadingResources,
465474
setResources: updateResources,
466475
setResourcesMetadata: updateResourcesMetadata,
467-
onResetSearch: resetSearchResources
476+
onResetSearch: resetSearchResources,
477+
onSetResourceTypes: setResourceTypes
468478
}
469479
)(ResourcesGrid);
470480

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const UPDATE_SELECTED_RESOURCE = 'RESOURCES:UPDATE_SELECTED_RESOURCE';
1717
export const SEARCH_RESOURCES = 'RESOURCES:SEARCH_RESOURCES';
1818
export const RESET_SEARCH_RESOURCES = 'RESOURCES:RESET_SEARCH_RESOURCES';
1919
export const RESET_SELECTED_RESOURCE = 'RESOURCES:RESET_SELECTED_RESOURCE';
20+
export const SET_RESOURCE_TYPES = 'RESOURCES:SET_RESOURCES_TYPES';
2021

2122
export function updateResources(resources, id) {
2223
return {
@@ -103,3 +104,10 @@ export function setShowDetails(show, id) {
103104
id
104105
};
105106
}
107+
108+
export function setResourceTypes(resourceTypes) {
109+
return {
110+
type: SET_RESOURCE_TYPES,
111+
resourceTypes
112+
};
113+
}

web/client/plugins/ResourcesCatalog/containers/ResourceDetails.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React, { useRef } from 'react';
10+
import PropTypes from 'prop-types';
1011
import { Alert } from 'react-bootstrap';
1112
import useRequestResource from '../hooks/useRequestResource';
1213
import DetailsInfo from '../components/DetailsInfo';
@@ -50,9 +51,9 @@ function ResourceDetails({
5051
facets,
5152
resourceType,
5253
enableFilters
53-
}) {
54+
}, context) {
5455

55-
const parsedConfig = useParsePluginConfigExpressions(monitoredState, { tabs });
56+
const parsedConfig = useParsePluginConfigExpressions(monitoredState, { tabs }, context?.plugins?.requires);
5657

5758
const {
5859
resource,
@@ -161,4 +162,9 @@ function ResourceDetails({
161162
);
162163
}
163164

165+
ResourceDetails.contextTypes = {
166+
plugins: PropTypes.object
167+
};
168+
169+
164170
export default ResourceDetails;

web/client/plugins/ResourcesCatalog/containers/ResourcesGrid.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React from 'react';
10+
import PropTypes from 'prop-types';
1011
import { connect } from 'react-redux';
1112
import url from 'url';
1213
import { createStructuredSelector } from 'reselect';
@@ -88,7 +89,7 @@ function ResourcesGrid({
8889
hideThumbnail,
8990
openInNewTab,
9091
resourcesFoundMsgId
91-
}) {
92+
}, context) {
9293

9394
const { query } = url.parse(location.search, true);
9495
const _page = queryPage ? query.page : pageProp;
@@ -142,7 +143,7 @@ function ResourcesGrid({
142143
menuItems,
143144
order,
144145
metadata: metadataProp
145-
});
146+
}, context?.plugins?.requires);
146147

147148
const isValidItem = (target) => (item) => item.target === target && (!item?.cfg?.resourcesGridId || item?.cfg?.resourcesGridId === id);
148149
const cardOptions = configuredItems.filter(isValidItem('card-options')).sort((a, b) => a.position - b.position);
@@ -245,6 +246,10 @@ function ResourcesGrid({
245246
);
246247
}
247248

249+
ResourcesGrid.contextTypes = {
250+
plugins: PropTypes.object
251+
};
252+
248253
const ConnectedResourcesGrid = connect(
249254
createStructuredSelector({
250255
user: userSelector,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
SEARCH_RESOURCES,
2323
RESET_SEARCH_RESOURCES,
2424
RESET_SELECTED_RESOURCE,
25-
SET_SHOW_DETAILS
25+
SET_SHOW_DETAILS,
26+
SET_RESOURCE_TYPES
2627
} from '../actions/resources';
2728

2829
import { parseResourceProperties } from '../../../utils/GeostoreUtils';
@@ -147,6 +148,11 @@ function resources(state = defaultState, action) {
147148
return setStateById(state, action, {
148149
search: null
149150
});
151+
case SET_RESOURCE_TYPES:
152+
return {
153+
...state,
154+
resourceTypes: action.resourceTypes
155+
};
150156
default:
151157
return state;
152158
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ export const getSearch = (state) => state?.resources?.search || null;
4848
export const getMonitoredStateSelector = state => getMonitoredState(state, getConfigProp('monitorState'));
4949
export const getRouterLocation = state => state?.router?.location;
5050

51-
51+
export const getAvailableResourceTypes = state => state?.resources?.resourceTypes;

web/client/product/plugins.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import SearchServicesConfig from "../plugins/SearchServicesConfig";
2525
import SecurityPopup from "../plugins/SecurityPopup";
2626

2727
import {toModulePlugin} from "../utils/ModulePluginsUtils";
28+
import { getPluginsContextRequires } from "../utils/PluginsContextUtils";
2829

2930
/**
3031
* Please, keep them sorted alphabetically
@@ -144,7 +145,8 @@ const pluginsDefinition = {
144145
plugins,
145146
requires: {
146147
ReactSwipe: require('react-swipeable-views').default,
147-
SwipeHeader: require('../components/data/identify/SwipeHeader').default
148+
SwipeHeader: require('../components/data/identify/SwipeHeader').default,
149+
...getPluginsContextRequires()
148150
}
149151
};
150152

0 commit comments

Comments
 (0)