Skip to content

Commit

Permalink
GeoNode#182: DetailView - Add link to the metadata page
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuren1 committed Apr 18, 2023
1 parent 1fd91ff commit 02207fe
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? <Message msgId={field.labelId} /> : field.label}</>);
const label = field.labelId ? <Message msgId={field.labelId} /> : field.label;
return isStyleLabel(field.style) && field.href
? (<a href={field.href} target={field.target}>{label}</a>)
: label;
};

function DetailsInfoField({
field,
children
}) {
function DetailsInfoField({ field, children }) {
const values = castArray(field.value);
return (
const isLinkLabel = isFieldLabelOnly(field);
const detailInfoFieldLabel = (
<div className={`gn-details-info-label${isLinkLabel ? '-link' : ''}`}>
<DetailInfoFieldLabel field={field} />
</div>
);
return isLinkLabel ? detailInfoFieldLabel : (
<div className="gn-details-info-row">
<div className="gn-details-info-label"><DetailInfoFieldLabel field={field} /></div>
{detailInfoFieldLabel}
<div className="gn-details-info-value">{children(values)}</div>
</div>
);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
processUploadResponse,
parseUploadResponse,
cleanUrl,
parseUploadFiles
parseUploadFiles,
getResourceTypesInfo,
ResourceTypes
} from '../ResourceUtils';

describe('Test Resource Utils', () => {
Expand Down Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@
}
}
}
.gn-details-info-label-link {
padding: 0.25rem;
font-weight: bold;
}
}
.gn-details-panel-content-img {
> img,
Expand Down Expand Up @@ -477,6 +481,9 @@
max-width: 100%;
}
}
.gn-details-info-label-link {
width: 100%;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 42 additions & 0 deletions geonode_mapstore_client/static/mapstore/configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'))}"
}
]
}
Expand Down Expand Up @@ -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'))}"
}
]
}
Expand Down Expand Up @@ -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'))}"
}
]
}
Expand Down Expand Up @@ -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'))}"
}
]
}
Expand Down Expand Up @@ -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'))}"
}
]
}
Expand Down Expand Up @@ -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'))}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 02207fe

Please sign in to comment.