Skip to content

Commit

Permalink
update 'create new' menu links and fix metadata link (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Aug 11, 2021
1 parent 07ff17e commit 359823f
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 25 deletions.
3 changes: 3 additions & 0 deletions geonode_mapstore_client/client/js/plugins/ActionNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { hasPermissionsTo, reduceArrayRecursive } from '@js/utils/MenuUtils';
import { getResourceTypesInfo } from '@js/utils/ResourceUtils';

function checkResourcePerms(menuItem, resourcePerms) {
if (menuItem.disableIf) {
return false;
}
if (menuItem.type && menuItem.perms) {
return hasPermissionsTo(resourcePerms, menuItem.perms, 'resource');
}
Expand Down
10 changes: 6 additions & 4 deletions geonode_mapstore_client/client/js/plugins/ViewerLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { createPlugin } from '@mapstore/framework/utils/PluginsUtils';
import usePluginItems from '@js/hooks/usePluginItems';
import {
getResourceId,
getSelectedLayerPermissions
getSelectedLayerPermissions,
isNewResource
} from '@js/selectors/resource';
import { withResizeDetector } from 'react-resize-detector';

Expand Down Expand Up @@ -132,9 +133,10 @@ const MemoizeViewerLayout = memo(ViewerLayout, arePropsEqual);
const ViewerLayoutPlugin = connect(
createSelector([
getResourceId,
getSelectedLayerPermissions
], (resourcePk, selectedLayerPermissions) => ({
resourcePk,
getSelectedLayerPermissions,
isNewResource
], (resourcePk, selectedLayerPermissions, isNew) => ({
resourcePk: isNew ? 'new' : resourcePk,
selectedLayerPermissions
})),
{}
Expand Down
5 changes: 4 additions & 1 deletion geonode_mapstore_client/client/js/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LayerDownloadActionButton,
AnnotationsActionButton
} from '@js/plugins/actionnavbar/buttons';
import { getMetadataUrl } from '@js/utils/ResourceUtils';

const EXCLUDED_EPICS_NAMES = [
'loadGeostoryEpic',
Expand Down Expand Up @@ -368,7 +369,9 @@ export const plugins = {

const pluginsDefinition = {
plugins,
requires: {},
requires: {
getMetadataUrl
},
epics: {},
reducers: {}
};
Expand Down
23 changes: 18 additions & 5 deletions geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export const getResourceTypesInfo = () => ({
theme: 'preview'
})),
formatDetailUrl: (resource) => (`/catalogue/#/dataset/${resource.pk}`),
name: 'Dataset'
name: 'Dataset',
formatMetadataUrl: (resource) => (`/datasets/${resource.alternate}/metadata`)
},
[ResourceTypes.MAP]: {
icon: 'map',
Expand All @@ -184,24 +185,36 @@ export const getResourceTypesInfo = () => ({
config: 'map_preview',
theme: 'preview'
})),
formatDetailUrl: (resource) => (`/catalogue/#/map/${resource.pk}`)
formatDetailUrl: (resource) => (`/catalogue/#/map/${resource.pk}`),
formatMetadataUrl: (resource) => (`/maps/${resource.pk}/metadata`)
},
[ResourceTypes.DOCUMENT]: {
icon: 'file',
name: 'Document',
formatEmbedUrl: (resource) => resource?.embed_url && parseDevHostname(resource.embed_url),
formatDetailUrl: (resource) => (`/catalogue/#/document/${resource.pk}`)
formatDetailUrl: (resource) => (`/catalogue/#/document/${resource.pk}`),
formatMetadataUrl: (resource) => (`/documents/${resource.pk}/metadata`)
},
[ResourceTypes.GEOSTORY]: {
icon: 'book',
name: 'GeoStory',
formatEmbedUrl: (resource) => resource?.embed_url && parseDevHostname(resource.embed_url),
formatDetailUrl: (resource) => (`/catalogue/#/geostory/${resource.pk}`)
formatDetailUrl: (resource) => (`/catalogue/#/geostory/${resource.pk}`),
formatMetadataUrl: (resource) => (`/apps/${resource.pk}/metadata`)
},
[ResourceTypes.DASHBOARD]: {
icon: 'dashboard',
name: 'Dashboard',
formatEmbedUrl: (resource) => resource?.embed_url && parseDevHostname(resource.embed_url),
formatDetailUrl: (resource) => (`/catalogue/#/dashboard/${resource.pk}`)
formatDetailUrl: (resource) => (`/catalogue/#/dashboard/${resource.pk}`),
formatMetadataUrl: (resource) => (`/apps/${resource.pk}/metadata`)
}
});

export const getMetadataUrl = (resource) => {
if (resource) {
const { formatMetadataUrl = () => '' } = getResourceTypesInfo()[resource?.resource_type] || {};
return formatMetadataUrl(resource);
}
return '';
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
{
"name": "gnResourceData",
"path": "gnresource.data"
},
{
"name": "isNewResource",
"path": "gnresource.isNew"
}
],
"projectionDefs": [
Expand Down Expand Up @@ -392,7 +396,7 @@
],
"items": [
{
"labelId": "gnhome.dataset",
"labelId": "gnhome.uploadDataset",
"value": "layer",
"type": "link",
"href": "/datasets/upload",
Expand All @@ -405,7 +409,20 @@
]
},
{
"labelId": "gnhome.document",
"labelId": "gnhome.createDataset",
"value": "layer",
"type": "link",
"href": "/createlayer/",
"authenticated": true,
"perms": [
{
"type": "user",
"value": "add_resource"
}
]
},
{
"labelId": "gnhome.uploadDocument",
"value": "document",
"type": "link",
"href": "/documents/upload",
Expand All @@ -418,7 +435,7 @@
]
},
{
"labelId": "gnhome.map",
"labelId": "gnhome.createMap",
"value": "map",
"type": "link",
"href": "/catalogue/#/map/new",
Expand All @@ -431,7 +448,7 @@
]
},
{
"labelId": "gnhome.geostory",
"labelId": "gnhome.createGeostory",
"value": "geostory",
"type": "link",
"href": "/catalogue/#/geostory/new",
Expand All @@ -444,7 +461,7 @@
]
},
{
"labelId": "gnhome.dashboard",
"labelId": "gnhome.createDashboard",
"value": "dashboard",
"type": "link",
"href": "/catalogue/#/dashboard/new",
Expand Down Expand Up @@ -2429,7 +2446,7 @@
"items": [
{
"type": "link",
"href": "{(state('gnResourceData') || {}).detail_url + '/metadata'}",
"href": "{context.getMetadataUrl(state('gnResourceData'))}",
"labelId": "gnviewer.editMetadata"
},
{
Expand Down Expand Up @@ -2988,6 +3005,7 @@
{
"labelId": "gnviewer.edit",
"type": "dropdown",
"disableIf": "{state('isNewResource')}",
"perms": [
{
"type": "resource",
Expand All @@ -2997,7 +3015,7 @@
"items": [
{
"type": "link",
"href": "{(state('gnResourceData') || {}).detail_url + '/metadata'}",
"href": "{context.getMetadataUrl(state('gnResourceData'))}",
"labelId": "gnviewer.editMetadata"
}
]
Expand Down Expand Up @@ -3445,6 +3463,7 @@
{
"labelId": "gnviewer.edit",
"type": "dropdown",
"disableIf": "{state('isNewResource')}",
"perms": [
{
"type": "resource",
Expand All @@ -3454,7 +3473,7 @@
"items": [
{
"type": "link",
"href": "{(state('gnResourceData') || {}).detail_url + '/metadata'}",
"href": "{context.getMetadataUrl(state('gnResourceData'))}",
"labelId": "gnviewer.editMetadata"
}
]
Expand Down Expand Up @@ -3631,7 +3650,7 @@
"items": [
{
"type": "link",
"href": "{(state('gnResourceData') || {}).detail_url + '/metadata'}",
"href": "{context.getMetadataUrl(state('gnResourceData'))}",
"labelId": "gnviewer.editMetadata"
}
]
Expand Down Expand Up @@ -3707,6 +3726,7 @@
{
"labelId": "gnviewer.edit",
"type": "dropdown",
"disableIf": "{state('isNewResource')}",
"perms": [
{
"type": "resource",
Expand All @@ -3716,7 +3736,7 @@
"items": [
{
"type": "link",
"href": "{(state('gnResourceData') || {}).detail_url + '/metadata'}",
"href": "{context.getMetadataUrl(state('gnResourceData'))}",
"labelId": "gnviewer.editMetadata"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
"customFiltersTitle": "Ressourcen",
"myResources": "Meine Ressourcen",
"pendingApproval": "Ausstehende Genehmigung",
"featuredList": "Vorgestellt"
"featuredList": "Vorgestellt",
"uploadDataset": "Datensatz hochladen",
"createDataset": "Dataset erstellen"
},
"viewer": {
"document": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
"customFiltersTitle": "Resources",
"myResources": "My resources",
"pendingApproval": "Pending approval",
"featuredList": "Featured"
"featuredList": "Featured",
"uploadDataset": "Upload dataset",
"createDataset": "Create dataset"
},
"viewer": {
"document": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
"customFiltersTitle": "Recursos",
"myResources": "Mis recursos",
"pendingApproval": "Aprobación pendiente",
"featuredList": "Presentada"
"featuredList": "Presentada",
"uploadDataset": "Subir conjunto de datos",
"createDataset": "Crear conjunto de datos"
},
"viewer": {
"document": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
"customFiltersTitle": "Ressources",
"myResources": "Mes ressources",
"pendingApproval": "En attente de validation",
"featuredList": "Mis en exergue"
"featuredList": "Mis en exergue",
"uploadDataset": "Télécharger l'ensemble de données",
"createDataset": "Créer un ensemble de données"
},
"viewer": {
"document": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@
"customFiltersTitle": "Risorse",
"myResources": "Le mie risorse",
"pendingApproval": "In attesa di approvazione",
"featuredList": "In primo piano"
"featuredList": "In primo piano",
"uploadDataset": "Carica dataset",
"createDataset": "Crea dataset"
},
"viewer": {
"document": {
Expand Down

0 comments on commit 359823f

Please sign in to comment.