Skip to content

Commit a99389f

Browse files
Review changes (#9)
* review changes * Check dataset in maplayers are processing download * Update geonode_mapstore_client/client/js/plugins/actionnavbar/buttons.jsx Co-authored-by: Suren <[email protected]> --------- Co-authored-by: Suren <[email protected]>
1 parent f825b9d commit a99389f

File tree

13 files changed

+96
-192
lines changed

13 files changed

+96
-192
lines changed

geonode_mapstore_client/client/js/components/Menu/DropdownList.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const itemElement = ({ labelId, href, badge, target }) => (
2828

2929
const itemsList = (items) => (items && items.map((item) => {
3030

31-
const { labelId, href, badge, target, type, Component, className, cfg } = item;
31+
const { labelId, href, badge, target, type, Component, className } = item;
3232

3333
if (type === 'plugin' && Component) {
34-
return (<li><Component {...cfg} variant="default" className={className} showMessage /></li>);
34+
return (<li><Component variant="default" className={className} showMessage /></li>);
3535
}
3636

3737
return itemElement({ labelId, href, badge, target });
@@ -97,7 +97,7 @@ const DropdownList = ({
9797
.map((itm, idx) => {
9898

9999
if (itm.type === 'plugin' && itm.Component) {
100-
return (<li><itm.Component {...itm.cfg} variant="default" className={itm.className} showMessage /></li>);
100+
return (<li><itm.Component variant="default" className={itm.className} showMessage /></li>);
101101
}
102102
if (itm.type === 'divider') {
103103
return <Dropdown.Divider key={idx} />;

geonode_mapstore_client/client/js/hooks/usePluginItems.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

geonode_mapstore_client/client/js/plugins/DatasetDownload.jsx

Lines changed: 0 additions & 87 deletions
This file was deleted.

geonode_mapstore_client/client/js/plugins/DetailViewer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import Message from '@mapstore/framework/components/I18N/Message';
4545
import { layersSelector } from '@mapstore/framework/selectors/layers';
4646
import { mapSelector } from '@mapstore/framework/selectors/map';
4747
import { parsePluginConfigExpressions } from '@js/utils/MenuUtils';
48-
import usePluginItems from '@js/hooks/usePluginItems';
48+
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
4949
import { getResourceTypesInfo } from '@js/utils/ResourceUtils';
5050
import tabComponents from '@js/plugins/detailviewer/tabComponents';
5151

geonode_mapstore_client/client/js/plugins/DownloadResource.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ export default createPlugin('DownloadResource', {
137137
Component: DownloadResource,
138138
priority: 1
139139
},
140-
DatasetDownload: {
140+
LayerDownload: {
141141
name: 'DownloadResource',
142-
target: 'toolbar',
143142
Component: DownloadResource,
144143
priority: 1
145144
}

geonode_mapstore_client/client/js/plugins/LayerSettings.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import GroupSettings from '@js/plugins/layersettings/GroupSettings';
2424
import BaseLayerSettings from '@js/plugins/layersettings/BaseLayerSettings';
2525
import WMSLayerSettings from '@js/plugins/layersettings/WMSLayerSettings';
2626
import GeoNodeStyleSelector from '@js/plugins/layersettings/GeoNodeStyleSelector';
27-
import usePluginItems from '@js/hooks/usePluginItems';
27+
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
2828
import layersettingsEpics from '@js/epics/layersettings';
2929
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
3030
import { isAnnotationLayer } from '@mapstore/framework/plugins/Annotations/utils/AnnotationsUtils';

geonode_mapstore_client/client/js/plugins/ResourcesGrid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { processingDownload } from '@js/selectors/resourceservice';
4646
import { resourceHasPermission, getCataloguePath } from '@js/utils/ResourceUtils';
4747
import {downloadResource, setFavoriteResource} from '@js/actions/gnresource';
4848
import FiltersForm from '@js/components/FiltersForm';
49-
import usePluginItems from '@js/hooks/usePluginItems';
49+
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
5050
import { ProcessTypes } from '@js/utils/ResourceServiceUtils';
5151
import { replace } from 'connected-react-router';
5252
import FaIcon from '@js/components/FaIcon';

geonode_mapstore_client/client/js/plugins/actionnavbar/buttons.jsx

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
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
*/
8-
import React from 'react';
8+
import React, { useRef } from 'react';
9+
import { PropTypes } from 'prop-types';
910
import { connect } from 'react-redux';
1011
import { createSelector } from 'reselect';
12+
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
1113
import {
1214
setControlProperty
1315
} from '@mapstore/framework/actions/controls';
1416
import {
1517
toggleFullscreen
1618
} from '@mapstore/framework/actions/fullscreen';
17-
19+
import { Dropdown, MenuItem, Glyphicon } from 'react-bootstrap';
1820
import Message from '@mapstore/framework/components/I18N/Message';
1921
import Button from '@js/components/Button';
2022
import FaIcon from '@js/components/FaIcon';
@@ -23,7 +25,7 @@ import { openQueryBuilder } from '@mapstore/framework/actions/layerFilter';
2325
import { getSelectedLayer } from '@mapstore/framework/selectors/layers';
2426
import { isDashboardEditing } from '@mapstore/framework/selectors/dashboard';
2527
import { createWidget } from '@mapstore/framework/actions/widgets';
26-
import { getResourceData } from '@js/selectors/resource';
28+
import { getResourceData, getSelectedLayerDataset } from '@js/selectors/resource';
2729
import { GXP_PTYPES } from '@js/utils/ResourceUtils';
2830

2931
// buttons override to use in ActionNavbar for plugin imported from mapstore
@@ -57,21 +59,52 @@ export const FullScreenActionButton = connect(createSelector([
5759
);
5860
});
5961

60-
export const LayerDownloadActionButton = connect(
61-
(state) => ({
62-
data: getResourceData(state)
63-
}),
64-
{ onClick: setControlProperty.bind(null, 'layerdownload', 'enabled', true, true) }
65-
)(({
62+
const LayerDownloadActionButtonComponent = ({
6663
onClick,
6764
variant,
6865
size,
69-
data
70-
}) => {
66+
data,
67+
nodeTypes,
68+
items,
69+
status,
70+
statusTypes
71+
}, context) => {
72+
const node = useRef();
73+
const { loadedPlugins } = context;
74+
const configuredItems = usePluginItems({ items, loadedPlugins });
75+
// nodeTypes is included in the TOC plugin as additional prop
76+
const isTOCItem = !!nodeTypes;
7177
// hide button for arcgis sources
7278
if ([GXP_PTYPES.REST_MAP, GXP_PTYPES.REST_IMG].includes(data?.ptype)) {
7379
return null;
7480
}
81+
if (isTOCItem) {
82+
return status === statusTypes.LAYER ? (
83+
<>
84+
<Dropdown
85+
style={{ position: 'absolute' }}
86+
>
87+
<Dropdown.Toggle
88+
noCaret
89+
bsStyle="primary"
90+
className="square-button-md"
91+
>
92+
<Glyphicon glyph="download" />
93+
</Dropdown.Toggle>
94+
<Dropdown.Menu style={{ width: 'auto', minWidth: 'max-content' }}>
95+
{configuredItems.map(({ Component, name }) => {
96+
return (<Component key={name} renderType="menuItem" resource={data} />);
97+
})}
98+
<MenuItem onClick={() => onClick()}>
99+
<Message msgId="gnviewer.exportData" />
100+
</MenuItem>
101+
</Dropdown.Menu>
102+
</Dropdown>
103+
{/* include a placeholder to compute the space */}
104+
<div ref={node} className="square-button-md" style={{ display: 'inline-block', verticalAlign: 'middle' }} />
105+
</>
106+
) : null;
107+
}
75108
return (
76109
<Button
77110
variant={variant}
@@ -81,7 +114,20 @@ export const LayerDownloadActionButton = connect(
81114
<Message msgId="gnviewer.exportData" />
82115
</Button>
83116
);
84-
});
117+
};
118+
119+
LayerDownloadActionButtonComponent.contextTypes = {
120+
loadedPlugins: PropTypes.object
121+
};
122+
123+
export const LayerDownloadActionButton = connect(
124+
createSelector([getResourceData, getSelectedLayerDataset],
125+
(resourceData, selectedLayerDataset) => ({
126+
data: selectedLayerDataset ? selectedLayerDataset : resourceData
127+
})
128+
),
129+
{ onClick: setControlProperty.bind(null, 'layerdownload', 'enabled', true, true) }
130+
)(LayerDownloadActionButtonComponent);
85131

86132
export const FilterLayerActionButton = connect(
87133
(state) => ({

geonode_mapstore_client/client/js/plugins/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,20 @@ export const plugins = {
6969
OperationPlugin,
7070
MetadataEditorPlugin,
7171
MetadataViewerPlugin,
72-
DatasetDownloadPlugin: toModulePlugin(
73-
'DatasetDownload',
74-
() => import(/* webpackChunkName: 'plugins/dataset-download' */ '@js/plugins/DatasetDownload')
75-
),
7672
LayerDownloadPlugin: toModulePlugin(
7773
'LayerDownload',
7874
() => import(/* webpackChunkName: 'plugins/layer-download' */ '@mapstore/framework/plugins/LayerDownload'),
7975
{
8076
overrides: {
8177
containers: {
82-
TOC: {},
83-
ActionNavbar: {
78+
TOC: {
8479
name: 'LayerDownload',
80+
target: 'toolbar',
8581
Component: LayerDownloadActionButton
8682
},
87-
DatasetDownload: {
83+
ActionNavbar: {
8884
name: 'LayerDownload',
89-
Component: LayerDownloadActionButton,
90-
target: 'toolbar'
85+
Component: LayerDownloadActionButton
9186
}
9287
}
9388
}

geonode_mapstore_client/client/js/selectors/__tests__/resourceservice-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import expect from 'expect';
1010
import { getCurrentProcesses, processingDownload, generalResourceDownload, featuredResourceDownload } from '../resourceservice';
11+
import { ResourceTypes } from '@js/utils/ResourceUtils';
1112

1213

1314
describe('resourceservice selector', () => {
@@ -34,6 +35,21 @@ describe('resourceservice selector', () => {
3435
};
3536
expect(processingDownload(testState)).toEqual(true);
3637
});
38+
it('test processingDownload when downloding dataset in the maplayers', () => {
39+
const testState = {
40+
gnresource: {
41+
data: {
42+
pk: 1,
43+
resource_type: ResourceTypes.MAP,
44+
maplayers: [{dataset: {pk: 2}}]
45+
}
46+
},
47+
resourceservice: {
48+
downloads: [{ pk: 2 }]
49+
}
50+
};
51+
expect(processingDownload(testState)).toEqual(true);
52+
});
3753

3854
it('test featuredResourceDownload', () => {
3955
const testState = {

geonode_mapstore_client/client/js/selectors/resourceservice.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { getResourceData } from '@js/selectors/resource';
1010
import { ProcessTypes } from '@js/utils/ResourceServiceUtils';
1111
import { getSearchResults, getFeaturedResults } from '@js/selectors/search';
12+
import { ResourceTypes } from '@js/utils/ResourceUtils';
1213

1314
export const isProcessCompleted = (state, payload) => {
1415
const completedProcess = state?.resourceservice?.processes?.find(process =>
@@ -21,8 +22,11 @@ export const isProcessCompleted = (state, payload) => {
2122

2223
export const processingDownload = (state) => {
2324
const resource = getResourceData(state);
25+
const pks = (resource.resource_type === ResourceTypes.MAP
26+
? resource?.maplayers?.map(layer => layer?.dataset?.pk)
27+
: [resource?.pk])?.filter(Boolean);
2428
const isProcessingDownload = state?.resourceservice?.downloads?.find((download) =>
25-
download?.pk === resource?.pk
29+
pks.includes(download?.pk)
2630
);
2731
const downloading = isProcessingDownload ? true : false;
2832
return downloading;

0 commit comments

Comments
 (0)