Skip to content

Commit 3dcc076

Browse files
authored
Move permissions management back to the Share panel (#2151)
* Move permissions management back to the Share panel * code refactor * unit test path resolve fix * temp * renamed * remove edit permission button from navbar * lint fix * Update share panel style
1 parent 7d6b658 commit 3dcc076

File tree

26 files changed

+149
-169
lines changed

26 files changed

+149
-169
lines changed

geonode_mapstore_client/client/js/plugins/ResourceDetails/ResourceDetails.jsx

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ import ResourcesPanelWrapper from '@mapstore/framework/plugins/ResourcesCatalog/
2727
import TargetSelectorPortal from '@mapstore/framework/plugins/ResourcesCatalog/components/TargetSelectorPortal';
2828
import useResourcePanelWrapper from '@mapstore/framework/plugins/ResourcesCatalog/hooks/useResourcePanelWrapper';
2929
import { getShowDetails } from '@mapstore/framework/plugins/ResourcesCatalog/selectors/resources';
30-
import { setShowDetails, setSelectedResource, setDetailPanelTab } from '@mapstore/framework/plugins/ResourcesCatalog/actions/resources';
30+
import { setShowDetails, setSelectedResource } from '@mapstore/framework/plugins/ResourcesCatalog/actions/resources';
3131
import PendingStatePrompt from '@mapstore/framework/plugins/ResourcesCatalog/containers/PendingStatePrompt';
3232
import DetailsPanel from './containers/DetailsPanel';
3333
import useDetectClickOut from '@js/hooks/useDetectClickOut';
34-
import Button from '@mapstore/framework/components/layout/Button';
35-
import Message from '@mapstore/framework/components/I18N/Message';
3634

3735
/**
3836
* @module ResourceDetails
@@ -390,7 +388,7 @@ const ResourceDetailsPlugin = connect(
390388
export default createPlugin('ResourceDetails', {
391389
component: ResourceDetailsPlugin,
392390
containers: {
393-
ActionNavbar: [{
391+
ActionNavbar: {
394392
name: 'ResourceDetailsButton',
395393
Component: connect((state) => ({resource: getResourceData(state)}), { onShow: setShowDetails })(({ component, resourcesGridId, onShow, resource }) => {
396394
if (!resource?.pk) return null;
@@ -410,31 +408,7 @@ export default createPlugin('ResourceDetails', {
410408
}),
411409
priority: 1,
412410
doNotHide: true
413-
}, {
414-
name: 'ResourceEditPermissions',
415-
Component: connect((state) => ({resource: getResourceData(state)}), { onShow: setShowDetails, onSelectTab: setDetailPanelTab })(
416-
({ resourcesGridId, onShow, resource, onSelectTab }) => {
417-
if (!resource?.pk) return null;
418-
419-
function handleClick() {
420-
onShow(true, resourcesGridId);
421-
onSelectTab('settings');
422-
}
423-
return (
424-
<Button
425-
variant="default"
426-
size="md"
427-
onClick={handleClick}
428-
labelId="gnviewer.editPermissions"
429-
>
430-
<Message msgId="gnviewer.editPermissions" />
431-
</Button>
432-
);
433-
}
434-
),
435-
priority: 1,
436-
doNotHide: true
437-
}],
411+
},
438412
ResourcesGrid: {
439413
priority: 2,
440414
target: 'card-buttons',

geonode_mapstore_client/client/js/plugins/ResourceDetails/components/DetailsSettings.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import FlexBox from '@mapstore/framework/components/layout/FlexBox';
77
import Text from '@mapstore/framework/components/layout/Text';
88
import SelectInfiniteScroll from '@mapstore/framework/plugins/ResourcesCatalog/components/SelectInfiniteScroll';
99
import { getGroups } from '@js/api/geonode/v2';
10-
import { canAccessPermissions, canManageResourceSettings, RESOURCE_MANAGEMENT_PROPERTIES } from '@js/utils/ResourceUtils';
11-
import DetailsPermissions from '@js/plugins/ResourceDetails/containers/Permissions';
10+
import { canManageResourceSettings, RESOURCE_MANAGEMENT_PROPERTIES } from '@js/utils/ResourceUtils';
1211

1312
const MessageTooltip = tooltip(forwardRef(({children, msgId, ...props}, ref) => {
1413
return (
@@ -47,7 +46,6 @@ function DetailsSettings({ resource, onChange }) {
4746
/>
4847
</FormGroup>
4948
</FlexBox.Fill>
50-
{canAccessPermissions(resource) && <DetailsPermissions resource={resource} />}
5149
{canManageResourceSettings(resource) && (
5250
<FlexBox column gap="xs">
5351
<Text strong>

geonode_mapstore_client/client/js/plugins/Share.jsx renamed to geonode_mapstore_client/client/js/plugins/Share/Share.jsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Message from '@mapstore/framework/components/I18N/Message';
1818
import controls from '@mapstore/framework/reducers/controls';
1919
import Button from '@mapstore/framework/components/layout/Button';
2020
import { mapInfoSelector } from '@mapstore/framework/selectors/map';
21+
2122
import OverlayContainer from '@js/components/OverlayContainer';
2223
import {
2324
isNewResource,
@@ -26,12 +27,14 @@ import {
2627
getViewedResourceType
2728
} from '@js/selectors/resource';
2829
import {
29-
formatResourceLinkUrl,
30+
canAccessPermissions,
3031
getDownloadUrlInfo,
3132
getResourceTypesInfo
3233
} from '@js/utils/ResourceUtils';
33-
import SharePageLink from '@js/plugins/share/SharePageLink';
34-
import ShareEmbedLink from '@js/plugins/share/ShareEmbedLink';
34+
import SharePageLink from '@js/plugins/Share/SharePageLink';
35+
import ShareEmbedLink from '@js/plugins/Share/ShareEmbedLink';
36+
import Permissions from '@js/plugins/Share/components/Permissions';
37+
import FlexBox from '@mapstore/framework/components/layout/FlexBox';
3538

3639
const getEmbedUrl = (resource) => {
3740
const { formatEmbedUrl = (_resource) => _resource?.embed_url } = getResourceTypesInfo()[resource?.resource_type] || {};
@@ -40,11 +43,11 @@ const getEmbedUrl = (resource) => {
4043
function Share({
4144
enabled,
4245
onClose,
43-
resourceType,
44-
embedUrl,
45-
downloadUrl,
46-
pageUrl
46+
resource,
47+
resourceType
4748
}) {
49+
const embedUrl = getEmbedUrl(resource);
50+
const downloadUrl = getDownloadUrlInfo(resource)?.url;
4851
return (
4952
<OverlayContainer
5053
enabled={enabled}
@@ -53,15 +56,15 @@ function Share({
5356
<section className="gn-share-panel">
5457
<div className="gn-share-panel-head">
5558
<h2><Message msgId="gnviewer.shareThisResource" /></h2>
56-
<Button className="square-button" onClick={() => onClose()}>
59+
<Button className="square-button gn-share-panel-close" onClick={() => onClose()}>
5760
<Glyphicon glyph="1-close" />
5861
</Button>
5962
</div>
60-
<div className="gn-share-panel-body">
61-
<SharePageLink value={pageUrl} label={<Message msgId="gnviewer.thisPage" />} />
63+
<FlexBox column gap="md" className="gn-share-panel-body">
64+
{canAccessPermissions(resource) && <Permissions resource={resource} />}
65+
{(resourceType === 'document' && !!downloadUrl) && <SharePageLink value={downloadUrl} label={<Message msgId={`gnviewer.directLink`} />} collapsible={false} />}
6266
{embedUrl && <ShareEmbedLink embedUrl={embedUrl} label={<Message msgId={`gnviewer.embed${resourceType}`} />} />}
63-
{(resourceType === 'document' && !!downloadUrl) && <SharePageLink value={downloadUrl} label={<Message msgId={`gnviewer.directLink`} />} />}
64-
</div>
67+
</FlexBox>
6568
</section>
6669
</OverlayContainer>
6770
);
@@ -86,10 +89,8 @@ const SharePlugin = connect(
8689
getViewedResourceType
8790
], (enabled, resource, type) => ({
8891
enabled,
89-
embedUrl: getEmbedUrl(resource),
90-
resourceType: type,
91-
downloadUrl: getDownloadUrlInfo(resource)?.url,
92-
pageUrl: formatResourceLinkUrl(resource)
92+
resource,
93+
resourceType: type
9394
})),
9495
{
9596
onClose: setControlProperty.bind(null, 'rightOverlay', 'enabled', false)

geonode_mapstore_client/client/js/plugins/share/ShareEmbedLink.jsx renamed to geonode_mapstore_client/client/js/plugins/Share/ShareEmbedLink.jsx

File renamed without changes.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2021, GeoSolutions Sas.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import React, { useState, useEffect } from 'react';
10+
import { Glyphicon } from 'react-bootstrap';
11+
12+
import Button from '@mapstore/framework/components/layout/Button';
13+
import CopyToClipboard from 'react-copy-to-clipboard';
14+
import FlexBox from '@mapstore/framework/components/layout/FlexBox';
15+
16+
17+
function SharePageLink({label, value, collapsible = true, children}) {
18+
const [copied, setCopied] = useState(false);
19+
const [isExpanded, setIsExpanded] = useState(false);
20+
21+
useEffect(() => {
22+
if (copied) {
23+
setTimeout(() => {
24+
setCopied(false);
25+
}, 1000);
26+
}
27+
}, [copied]);
28+
29+
return (
30+
<div className="gn-share-link-pad">
31+
<div className="gn-share-link-wrapper">
32+
<div className="gn-share-page-link">
33+
<FlexBox
34+
centerChildrenVertically
35+
className={`gn-share-title-header ${collapsible ? 'collapsible' : ''}`}
36+
{...(collapsible && {
37+
onClick: () => setIsExpanded(!isExpanded),
38+
style: { cursor: 'pointer' }
39+
})}
40+
>
41+
<label className="gn-share-title">{label}</label>
42+
{collapsible && <Glyphicon glyph={isExpanded ? "chevron-down" : "chevron-right"}/>}
43+
</FlexBox>
44+
{(!collapsible || isExpanded) && (
45+
<div className={`gn-share-content ${collapsible ? 'collapsible' : ''}`}>
46+
<div className="gn-share-link">
47+
<input
48+
readOnly
49+
rel="noopener noreferrer"
50+
target="_blank"
51+
value={value}
52+
/>
53+
{!copied && <CopyToClipboard
54+
text={value}
55+
>
56+
<Button
57+
size="sm"
58+
onClick={() => setCopied(true)}
59+
>
60+
<Glyphicon glyph="copy" />
61+
</Button>
62+
</CopyToClipboard>}
63+
{copied && <Button size="sm"><Glyphicon glyph="ok" /></Button>}
64+
</div>
65+
{children}
66+
</div>
67+
)}
68+
</div>
69+
</div>
70+
</div>
71+
);
72+
}
73+
74+
export default SharePageLink;

geonode_mapstore_client/client/js/plugins/ResourceDetails/containers/Permissions/GeoLimits.jsx renamed to geonode_mapstore_client/client/js/plugins/Share/components/Permissions/GeoLimits.jsx

File renamed without changes.

geonode_mapstore_client/client/js/plugins/ResourceDetails/containers/Permissions/index.jsx renamed to geonode_mapstore_client/client/js/plugins/Share/components/Permissions/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const Permissions = ({
116116
});
117117
}, [availableResourceTypes]);
118118
return (
119-
<FlexBox className="permissions-container" column gap="xs">
119+
<FlexBox className="gn-permissions-container" column gap="xs">
120120
<Text strong>
121121
<Message msgId={"gnviewer.permissions"} />
122122
</Text>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright 2025, GeoSolutions Sas.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
export { default } from './Share';

geonode_mapstore_client/client/js/plugins/__tests__/share-test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import expect from 'expect';
1010
import React from 'react';
1111
import ReactDOM from 'react-dom';
1212
import { getPluginForTest } from '@mapstore/framework/plugins/__tests__/pluginsTestUtils';
13-
import Share from '../Share';
1413
import gnresource from '../../reducers/gnresource';
14+
import Share from '../Share';
1515

1616

1717
describe('Share Plugin', () => {

geonode_mapstore_client/client/js/plugins/share/SharePageLink.jsx

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

0 commit comments

Comments
 (0)