From 9a48558ff5c22c43e0be52d90216ddd9cf4ff323 Mon Sep 17 00:00:00 2001 From: Willian Viana Date: Thu, 28 Nov 2024 13:52:55 -0300 Subject: [PATCH] feat(metadata): add resolution description and validate content_date properties We have three different properties to display the content date: content_date_description, content_date_range, and content_date, in this order of priority. --- components/modals/meta/component.jsx | 35 ++++++++++++++++++++++++---- components/modals/meta/selectors.js | 4 +++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/components/modals/meta/component.jsx b/components/modals/meta/component.jsx index 846c6d66f1..8616912d66 100644 --- a/components/modals/meta/component.jsx +++ b/components/modals/meta/component.jsx @@ -50,6 +50,31 @@ class ModalMeta extends PureComponent { } } + /** + * We have 3 different properties to display the content date: + * content_date_description, content_date_range and content_date, in this order of priority + * @returns An object cointaing metadata rows with the correct content_date + */ + setContentDate() { + const { + tableData: { content_date_range, content_date_description, ...rest }, + } = this.props; + + if (content_date_description) { + return { ...rest, content_date: content_date_description }; + } + + if (content_date_description && content_date_range) { + const { start_date, end_date } = content_date_range; + return { + ...rest, + content_date: `${start_date.slice(0, 4)}-${end_date.slice(0, 4)}`, + }; + } + + return rest; + } + getContent() { const { metaData, tableData, loading, error, locationName } = this.props; const { subtitle, overview, citation, learn_more, download_data } = @@ -61,6 +86,8 @@ class ModalMeta extends PureComponent { .replaceAll('[selected area name]', locationName) .replaceAll('[date]', moment().format('DD/MM/YYYY')); + const tableDataWithContentDate = this.setContentDate(tableData); + return (
{error && !loading && ( @@ -76,16 +103,16 @@ class ModalMeta extends PureComponent { dangerouslySetInnerHTML={{ __html: subtitle }} // eslint-disable-line />
- {tableData && - Object.keys(tableData).map((key) => - tableData[key] ? ( + {tableDataWithContentDate && + Object.keys(tableDataWithContentDate).map((key) => + tableDataWithContentDate[key] ? (
- {tableData[key]} + {tableDataWithContentDate[key]}
) : null diff --git a/components/modals/meta/selectors.js b/components/modals/meta/selectors.js index d43daca4ff..95e8849c05 100644 --- a/components/modals/meta/selectors.js +++ b/components/modals/meta/selectors.js @@ -13,10 +13,12 @@ const META_FIELDS = [ ]; const TABLE_FIELDS = [ 'function', - 'resolution', + 'resolution_description', 'geographic_coverage', 'source', 'content_date', + 'content_date_description', + 'content_date_range', 'update_frequency', 'cautions', 'license',