From 02207feb0260f538a5d039a385807941d62fc4f9 Mon Sep 17 00:00:00 2001 From: Suren Date: Tue, 18 Apr 2023 15:58:27 +0530 Subject: [PATCH] #182: DetailView - Add link to the metadata page --- .../components/DetailsPanel/DetailsInfo.jsx | 29 +++--- .../client/js/utils/ResourceUtils.js | 2 +- .../js/utils/__tests__/ResourceUtils-test.js | 99 ++++++++++++++++++- .../themes/geonode/less/_details-panel.less | 7 ++ .../themes/geonode/less/_resources-grid.less | 4 + .../static/mapstore/configs/localConfig.json | 42 ++++++++ .../mapstore/gn-translations/data.de-DE.json | 1 + .../mapstore/gn-translations/data.en-US.json | 1 + .../mapstore/gn-translations/data.es-ES.json | 1 + .../mapstore/gn-translations/data.fi-FI.json | 1 + .../mapstore/gn-translations/data.fr-FR.json | 1 + .../mapstore/gn-translations/data.hr-HR.json | 1 + .../mapstore/gn-translations/data.it-IT.json | 1 + .../mapstore/gn-translations/data.nl-NL.json | 1 + .../mapstore/gn-translations/data.pt-PT.json | 1 + .../mapstore/gn-translations/data.sk-SK.json | 1 + .../mapstore/gn-translations/data.sv-SE.json | 1 + .../mapstore/gn-translations/data.vi-VN.json | 1 + .../mapstore/gn-translations/data.zh-ZH.json | 1 + 19 files changed, 183 insertions(+), 13 deletions(-) diff --git a/geonode_mapstore_client/client/js/components/DetailsPanel/DetailsInfo.jsx b/geonode_mapstore_client/client/js/components/DetailsPanel/DetailsInfo.jsx index 8d59765009..e7d97815a7 100644 --- a/geonode_mapstore_client/client/js/components/DetailsPanel/DetailsInfo.jsx +++ b/geonode_mapstore_client/client/js/components/DetailsPanel/DetailsInfo.jsx @@ -26,19 +26,28 @@ const getDateRangeValue = (startValue, endValue, format) => { } return moment(startValue ? startValue : endValue).format(format); }; +const isEmptyValue = (value) => (value?.length === 0 || value === 'None' || !value); +const isStyleLabel = (style) => style === "label"; +const isFieldLabelOnly = ({style, value}) => isEmptyValue(value) && isStyleLabel(style); const DetailInfoFieldLabel = ({ field }) => { - return (<>{field.labelId ? : field.label}); + const label = field.labelId ? : field.label; + return isStyleLabel(field.style) && field.href + ? ({label}) + : label; }; -function DetailsInfoField({ - field, - children -}) { +function DetailsInfoField({ field, children }) { const values = castArray(field.value); - return ( + const isLinkLabel = isFieldLabelOnly(field); + const detailInfoFieldLabel = ( +
+ +
+ ); + return isLinkLabel ? detailInfoFieldLabel : (
-
+ {detailInfoFieldLabel}
{children(values)}
); @@ -125,10 +134,8 @@ function DetailsInfoFields({ fields, formatHref }) { } const parseTabItems = (items) => { - return (items || []).filter(({ value }) => { - if (value?.length === 0 - || value === 'None' - || !value) { + return (items || []).filter(({value, style}) => { + if (isEmptyValue(value) && !isStyleLabel(style)) { return false; } return true; diff --git a/geonode_mapstore_client/client/js/utils/ResourceUtils.js b/geonode_mapstore_client/client/js/utils/ResourceUtils.js index 26b039aa06..02bc2fe1d9 100644 --- a/geonode_mapstore_client/client/js/utils/ResourceUtils.js +++ b/geonode_mapstore_client/client/js/utils/ResourceUtils.js @@ -266,7 +266,7 @@ export const getResourceTypesInfo = () => ({ })), formatDetailUrl: (resource) => resource?.detail_url && parseDevHostname(resource.detail_url), name: 'Dataset', - formatMetadataUrl: (resource) => (`/datasets/${resource.store}:${resource.alternate}/metadata`) + formatMetadataUrl: (resource) => (`/datasets/${resource.store ? resource.store + ":" : ''}${resource.alternate}/metadata`) }, [ResourceTypes.MAP]: { icon: 'map', diff --git a/geonode_mapstore_client/client/js/utils/__tests__/ResourceUtils-test.js b/geonode_mapstore_client/client/js/utils/__tests__/ResourceUtils-test.js index c68a88097c..eeb6ca9843 100644 --- a/geonode_mapstore_client/client/js/utils/__tests__/ResourceUtils-test.js +++ b/geonode_mapstore_client/client/js/utils/__tests__/ResourceUtils-test.js @@ -23,7 +23,9 @@ import { processUploadResponse, parseUploadResponse, cleanUrl, - parseUploadFiles + parseUploadFiles, + getResourceTypesInfo, + ResourceTypes } from '../ResourceUtils'; describe('Test Resource Utils', () => { @@ -817,4 +819,99 @@ describe('Test Resource Utils', () => { expect(parsedFiles[baseName].addMissingFiles).toEqual(true); }); + describe('Test getResourceTypesInfo', () => { + it('test dataset of getResourceTypesInfo', () => { + const { + icon, + canPreviewed, + formatMetadataUrl, + name + } = getResourceTypesInfo()[ResourceTypes.DATASET]; + let resource = { + perms: ['view_resourcebase'], + store: "workspace", + alternate: 'name:test' + }; + expect(icon).toBe('database'); + expect(canPreviewed(resource)).toBeTruthy(); + expect(name).toBe('Dataset'); + + // Test with store + expect(formatMetadataUrl(resource)).toBe('/datasets/workspace:name:test/metadata'); + + // Test with no store + resource = {...resource, store: undefined}; + expect(formatMetadataUrl(resource)).toBe('/datasets/name:test/metadata'); + + }); + it('test map of getResourceTypesInfo', () => { + const { + icon, + canPreviewed, + formatMetadataUrl, + name + } = getResourceTypesInfo()[ResourceTypes.MAP]; + let resource = { + perms: ['view_resourcebase'], + pk: "100" + }; + expect(icon).toBe('map'); + expect(canPreviewed(resource)).toBeTruthy(); + expect(name).toBe('Map'); + expect(formatMetadataUrl(resource)).toBe('/maps/100/metadata'); + }); + it('test document of getResourceTypesInfo', () => { + const { + icon, + canPreviewed, + hasPermission, + formatMetadataUrl, + metadataPreviewUrl, + name + } = getResourceTypesInfo()[ResourceTypes.DOCUMENT]; + let resource = { + perms: ['download_resourcebase'], + pk: "100", + extension: "pdf" + }; + expect(icon).toBe('file'); + expect(canPreviewed(resource)).toBeTruthy(); + expect(hasPermission(resource)).toBeTruthy(); + expect(name).toBe('Document'); + expect(formatMetadataUrl(resource)).toBe('/documents/100/metadata'); + expect(metadataPreviewUrl(resource)).toBe('/documents/100/metadata_detail?preview'); + }); + it('test geostory of getResourceTypesInfo', () => { + const { + icon, + canPreviewed, + formatMetadataUrl, + name + } = getResourceTypesInfo()[ResourceTypes.GEOSTORY]; + let resource = { + perms: ['view_resourcebase'], + pk: "100" + }; + expect(icon).toBe('book'); + expect(canPreviewed(resource)).toBeTruthy(); + expect(name).toBe('GeoStory'); + expect(formatMetadataUrl(resource)).toBe('/apps/100/metadata'); + }); + it('test dashboard of getResourceTypesInfo', () => { + const { + icon, + canPreviewed, + formatMetadataUrl, + name + } = getResourceTypesInfo()[ResourceTypes.DASHBOARD]; + let resource = { + perms: ['view_resourcebase'], + pk: "100" + }; + expect(icon).toBe('dashboard'); + expect(canPreviewed(resource)).toBeTruthy(); + expect(name).toBe('Dashboard'); + expect(formatMetadataUrl(resource)).toBe('/apps/100/metadata'); + }); + }); }); diff --git a/geonode_mapstore_client/client/themes/geonode/less/_details-panel.less b/geonode_mapstore_client/client/themes/geonode/less/_details-panel.less index 9037ca0e6d..ddf7b6617b 100644 --- a/geonode_mapstore_client/client/themes/geonode/less/_details-panel.less +++ b/geonode_mapstore_client/client/themes/geonode/less/_details-panel.less @@ -439,6 +439,10 @@ } } } + .gn-details-info-label-link { + padding: 0.25rem; + font-weight: bold; + } } .gn-details-panel-content-img { > img, @@ -477,6 +481,9 @@ max-width: 100%; } } + .gn-details-info-label-link { + width: 100%; + } } } diff --git a/geonode_mapstore_client/client/themes/geonode/less/_resources-grid.less b/geonode_mapstore_client/client/themes/geonode/less/_resources-grid.less index 4f063003cd..756abb2b1a 100644 --- a/geonode_mapstore_client/client/themes/geonode/less/_resources-grid.less +++ b/geonode_mapstore_client/client/themes/geonode/less/_resources-grid.less @@ -66,6 +66,10 @@ max-width: calc(100% - 200px); } } + .gn-details-info-label-link { + padding: 0.25rem; + font-weight: bold; + } } .gn-main-event-container.gn-main-grid-loader { diff --git a/geonode_mapstore_client/static/mapstore/configs/localConfig.json b/geonode_mapstore_client/static/mapstore/configs/localConfig.json index 22135ea433..b52006caca 100644 --- a/geonode_mapstore_client/static/mapstore/configs/localConfig.json +++ b/geonode_mapstore_client/static/mapstore/configs/localConfig.json @@ -759,6 +759,13 @@ "type": "html", "labelId": "gnviewer.supplementalInformation", "value": "{context.get(state('gnResourceData'), 'supplemental_information')}" + }, + { + "type": "link", + "style": "label", + "labelId": "gnviewer.viewFullMetadata", + "href": "{context.getMetadataDetailUrl(state('gnResourceData'))}", + "disableIf": "{!context.getMetadataDetailUrl(state('gnResourceData'))}" } ] } @@ -1614,6 +1621,13 @@ "type": "html", "labelId": "gnviewer.supplementalInformation", "value": "{context.get(state('gnResourceData'), 'supplemental_information')}" + }, + { + "type": "link", + "style": "label", + "labelId": "gnviewer.viewFullMetadata", + "href": "{context.getMetadataDetailUrl(state('gnResourceData'))}", + "disableIf": "{!context.getMetadataDetailUrl(state('gnResourceData'))}" } ] } @@ -2245,6 +2259,13 @@ "type": "html", "labelId": "gnviewer.supplementalInformation", "value": "{context.get(state('gnResourceData'), 'supplemental_information')}" + }, + { + "type": "link", + "style": "label", + "labelId": "gnviewer.viewFullMetadata", + "href": "{context.getMetadataDetailUrl(state('gnResourceData'))}", + "disableIf": "{!context.getMetadataDetailUrl(state('gnResourceData'))}" } ] } @@ -2534,6 +2555,13 @@ "type": "html", "labelId": "gnviewer.supplementalInformation", "value": "{context.get(state('gnResourceData'), 'supplemental_information')}" + }, + { + "type": "link", + "style": "label", + "labelId": "gnviewer.viewFullMetadata", + "href": "{context.getMetadataDetailUrl(state('gnResourceData'))}", + "disableIf": "{!context.getMetadataDetailUrl(state('gnResourceData'))}" } ] } @@ -2741,6 +2769,13 @@ "type": "html", "labelId": "gnviewer.supplementalInformation", "value": "{context.get(state('gnResourceData'), 'supplemental_information')}" + }, + { + "type": "link", + "style": "label", + "labelId": "gnviewer.viewFullMetadata", + "href": "{context.getMetadataDetailUrl(state('gnResourceData'))}", + "disableIf": "{!context.getMetadataDetailUrl(state('gnResourceData'))}" } ] } @@ -3241,6 +3276,13 @@ "type": "html", "labelId": "gnviewer.supplementalInformation", "value": "{context.get(state('gnResourceData'), 'supplemental_information')}" + }, + { + "type": "link", + "style": "label", + "labelId": "gnviewer.viewFullMetadata", + "href": "{context.getMetadataDetailUrl(state('gnResourceData'))}", + "disableIf": "{!context.getMetadataDetailUrl(state('gnResourceData'))}" } ] } diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.de-DE.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.de-DE.json index 749d7e8a03..bf2a0c91fa 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.de-DE.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.de-DE.json @@ -318,6 +318,7 @@ "temporalExtent": "Zeitliche Ausdehnung", "spatialRepresentationType": "Räumlicher darstellungstyp", "supplementalInformation": "Zusätzliche informationen", + "viewFullMetadata": "Vollständige Metadaten anzeigen", "abstract": "Zusammenfassung", "readMore": "Weiterlesen", "readLess": "Weniger lesen" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.en-US.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.en-US.json index d0e1431000..84282920dc 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.en-US.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.en-US.json @@ -318,6 +318,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.es-ES.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.es-ES.json index 130e46f548..220cecc5d5 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.es-ES.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.es-ES.json @@ -317,6 +317,7 @@ "temporalExtent": "Extensión temporal", "spatialRepresentationType": "Tipo de representación espacial", "supplementalInformation": "Información Suplementaria", + "viewFullMetadata": "Ver metadatos completos", "abstract": "Resumen", "readMore": "Leer más", "readLess": "Leer menos" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.fi-FI.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.fi-FI.json index 43f4a07335..0461ff7ad8 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.fi-FI.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.fi-FI.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.fr-FR.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.fr-FR.json index 9812c8879c..c81563455c 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.fr-FR.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.fr-FR.json @@ -318,6 +318,7 @@ "temporalExtent": "Etendue temporelle", "spatialRepresentationType": "Type de représentation spatiale", "supplementalInformation": "Informations supplémentaires", + "viewFullMetadata": "Afficher les métadonnées complètes", "abstract": "Résumé", "readMore": "En savoir plus", "readLess": "Lire moins" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.hr-HR.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.hr-HR.json index a6a2815353..24275f4d9d 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.hr-HR.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.hr-HR.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.it-IT.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.it-IT.json index a1b7a6f902..c5e2fbde3b 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.it-IT.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.it-IT.json @@ -320,6 +320,7 @@ "temporalExtent": "Estensione temporale", "spatialRepresentationType": "Tipo di rappresentazione spaziale", "supplementalInformation": "Informazioni supplementari", + "viewFullMetadata": "Visualizza i metadati completi", "abstract": "Astratto", "readMore": "Leggi di più", "readLess": "Leggi di meno" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.nl-NL.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.nl-NL.json index b28ad5ea53..e56a9e95a8 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.nl-NL.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.nl-NL.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.pt-PT.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.pt-PT.json index 5f3e1f6568..3801613870 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.pt-PT.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.pt-PT.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.sk-SK.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.sk-SK.json index 41874a2b1f..1439e691ee 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.sk-SK.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.sk-SK.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.sv-SE.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.sv-SE.json index 3d8950a9f4..88df306195 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.sv-SE.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.sv-SE.json @@ -291,6 +291,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.vi-VN.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.vi-VN.json index a28340fc3e..2ee3f0f10b 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.vi-VN.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.vi-VN.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less" diff --git a/geonode_mapstore_client/static/mapstore/gn-translations/data.zh-ZH.json b/geonode_mapstore_client/static/mapstore/gn-translations/data.zh-ZH.json index 47d7425839..52ed4f8aa9 100644 --- a/geonode_mapstore_client/static/mapstore/gn-translations/data.zh-ZH.json +++ b/geonode_mapstore_client/static/mapstore/gn-translations/data.zh-ZH.json @@ -290,6 +290,7 @@ "temporalExtent": "Temporal Extent", "spatialRepresentationType": "Spatial representation type", "supplementalInformation": "Supplemental information", + "viewFullMetadata": "View full metadata", "abstract": "Abstract", "readMore": "Read more", "readLess": "Read less"