Skip to content

Commit

Permalink
Review changes (#9)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
allyoucanmap and dsuren1 authored Feb 5, 2025
1 parent f825b9d commit a99389f
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const itemElement = ({ labelId, href, badge, target }) => (

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

const { labelId, href, badge, target, type, Component, className, cfg } = item;
const { labelId, href, badge, target, type, Component, className } = item;

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

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

if (itm.type === 'plugin' && itm.Component) {
return (<li><itm.Component {...itm.cfg} variant="default" className={itm.className} showMessage /></li>);
return (<li><itm.Component variant="default" className={itm.className} showMessage /></li>);
}
if (itm.type === 'divider') {
return <Dropdown.Divider key={idx} />;
Expand Down
37 changes: 0 additions & 37 deletions geonode_mapstore_client/client/js/hooks/usePluginItems.js

This file was deleted.

87 changes: 0 additions & 87 deletions geonode_mapstore_client/client/js/plugins/DatasetDownload.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/js/plugins/DetailViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import Message from '@mapstore/framework/components/I18N/Message';
import { layersSelector } from '@mapstore/framework/selectors/layers';
import { mapSelector } from '@mapstore/framework/selectors/map';
import { parsePluginConfigExpressions } from '@js/utils/MenuUtils';
import usePluginItems from '@js/hooks/usePluginItems';
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
import { getResourceTypesInfo } from '@js/utils/ResourceUtils';
import tabComponents from '@js/plugins/detailviewer/tabComponents';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ export default createPlugin('DownloadResource', {
Component: DownloadResource,
priority: 1
},
DatasetDownload: {
LayerDownload: {
name: 'DownloadResource',
target: 'toolbar',
Component: DownloadResource,
priority: 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import GroupSettings from '@js/plugins/layersettings/GroupSettings';
import BaseLayerSettings from '@js/plugins/layersettings/BaseLayerSettings';
import WMSLayerSettings from '@js/plugins/layersettings/WMSLayerSettings';
import GeoNodeStyleSelector from '@js/plugins/layersettings/GeoNodeStyleSelector';
import usePluginItems from '@js/hooks/usePluginItems';
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
import layersettingsEpics from '@js/epics/layersettings';
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
import { isAnnotationLayer } from '@mapstore/framework/plugins/Annotations/utils/AnnotationsUtils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { processingDownload } from '@js/selectors/resourceservice';
import { resourceHasPermission, getCataloguePath } from '@js/utils/ResourceUtils';
import {downloadResource, setFavoriteResource} from '@js/actions/gnresource';
import FiltersForm from '@js/components/FiltersForm';
import usePluginItems from '@js/hooks/usePluginItems';
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
import { ProcessTypes } from '@js/utils/ResourceServiceUtils';
import { replace } from 'connected-react-router';
import FaIcon from '@js/components/FaIcon';
Expand Down
70 changes: 58 additions & 12 deletions geonode_mapstore_client/client/js/plugins/actionnavbar/buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import React, { useRef } from 'react';
import { PropTypes } from 'prop-types';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import usePluginItems from '@mapstore/framework/hooks/usePluginItems';
import {
setControlProperty
} from '@mapstore/framework/actions/controls';
import {
toggleFullscreen
} from '@mapstore/framework/actions/fullscreen';

import { Dropdown, MenuItem, Glyphicon } from 'react-bootstrap';
import Message from '@mapstore/framework/components/I18N/Message';
import Button from '@js/components/Button';
import FaIcon from '@js/components/FaIcon';
Expand All @@ -23,7 +25,7 @@ import { openQueryBuilder } from '@mapstore/framework/actions/layerFilter';
import { getSelectedLayer } from '@mapstore/framework/selectors/layers';
import { isDashboardEditing } from '@mapstore/framework/selectors/dashboard';
import { createWidget } from '@mapstore/framework/actions/widgets';
import { getResourceData } from '@js/selectors/resource';
import { getResourceData, getSelectedLayerDataset } from '@js/selectors/resource';
import { GXP_PTYPES } from '@js/utils/ResourceUtils';

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

export const LayerDownloadActionButton = connect(
(state) => ({
data: getResourceData(state)
}),
{ onClick: setControlProperty.bind(null, 'layerdownload', 'enabled', true, true) }
)(({
const LayerDownloadActionButtonComponent = ({
onClick,
variant,
size,
data
}) => {
data,
nodeTypes,
items,
status,
statusTypes
}, context) => {
const node = useRef();
const { loadedPlugins } = context;
const configuredItems = usePluginItems({ items, loadedPlugins });
// nodeTypes is included in the TOC plugin as additional prop
const isTOCItem = !!nodeTypes;
// hide button for arcgis sources
if ([GXP_PTYPES.REST_MAP, GXP_PTYPES.REST_IMG].includes(data?.ptype)) {
return null;
}
if (isTOCItem) {
return status === statusTypes.LAYER ? (
<>
<Dropdown
style={{ position: 'absolute' }}
>
<Dropdown.Toggle
noCaret
bsStyle="primary"
className="square-button-md"
>
<Glyphicon glyph="download" />
</Dropdown.Toggle>
<Dropdown.Menu style={{ width: 'auto', minWidth: 'max-content' }}>
{configuredItems.map(({ Component, name }) => {
return (<Component key={name} renderType="menuItem" resource={data} />);
})}
<MenuItem onClick={() => onClick()}>
<Message msgId="gnviewer.exportData" />
</MenuItem>
</Dropdown.Menu>
</Dropdown>
{/* include a placeholder to compute the space */}
<div ref={node} className="square-button-md" style={{ display: 'inline-block', verticalAlign: 'middle' }} />
</>
) : null;
}
return (
<Button
variant={variant}
Expand All @@ -81,7 +114,20 @@ export const LayerDownloadActionButton = connect(
<Message msgId="gnviewer.exportData" />
</Button>
);
});
};

LayerDownloadActionButtonComponent.contextTypes = {
loadedPlugins: PropTypes.object
};

export const LayerDownloadActionButton = connect(
createSelector([getResourceData, getSelectedLayerDataset],
(resourceData, selectedLayerDataset) => ({
data: selectedLayerDataset ? selectedLayerDataset : resourceData
})
),
{ onClick: setControlProperty.bind(null, 'layerdownload', 'enabled', true, true) }
)(LayerDownloadActionButtonComponent);

export const FilterLayerActionButton = connect(
(state) => ({
Expand Down
13 changes: 4 additions & 9 deletions geonode_mapstore_client/client/js/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,20 @@ export const plugins = {
OperationPlugin,
MetadataEditorPlugin,
MetadataViewerPlugin,
DatasetDownloadPlugin: toModulePlugin(
'DatasetDownload',
() => import(/* webpackChunkName: 'plugins/dataset-download' */ '@js/plugins/DatasetDownload')
),
LayerDownloadPlugin: toModulePlugin(
'LayerDownload',
() => import(/* webpackChunkName: 'plugins/layer-download' */ '@mapstore/framework/plugins/LayerDownload'),
{
overrides: {
containers: {
TOC: {},
ActionNavbar: {
TOC: {
name: 'LayerDownload',
target: 'toolbar',
Component: LayerDownloadActionButton
},
DatasetDownload: {
ActionNavbar: {
name: 'LayerDownload',
Component: LayerDownloadActionButton,
target: 'toolbar'
Component: LayerDownloadActionButton
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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


describe('resourceservice selector', () => {
Expand All @@ -34,6 +35,21 @@ describe('resourceservice selector', () => {
};
expect(processingDownload(testState)).toEqual(true);
});
it('test processingDownload when downloding dataset in the maplayers', () => {
const testState = {
gnresource: {
data: {
pk: 1,
resource_type: ResourceTypes.MAP,
maplayers: [{dataset: {pk: 2}}]
}
},
resourceservice: {
downloads: [{ pk: 2 }]
}
};
expect(processingDownload(testState)).toEqual(true);
});

it('test featuredResourceDownload', () => {
const testState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { getResourceData } from '@js/selectors/resource';
import { ProcessTypes } from '@js/utils/ResourceServiceUtils';
import { getSearchResults, getFeaturedResults } from '@js/selectors/search';
import { ResourceTypes } from '@js/utils/ResourceUtils';

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

export const processingDownload = (state) => {
const resource = getResourceData(state);
const pks = (resource.resource_type === ResourceTypes.MAP
? resource?.maplayers?.map(layer => layer?.dataset?.pk)
: [resource?.pk])?.filter(Boolean);
const isProcessingDownload = state?.resourceservice?.downloads?.find((download) =>
download?.pk === resource?.pk
pks.includes(download?.pk)
);
const downloading = isProcessingDownload ? true : false;
return downloading;
Expand Down
Loading

0 comments on commit a99389f

Please sign in to comment.