Skip to content

Commit

Permalink
feat(metadata): add resolution description and validate content_date …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
willian-viana committed Nov 28, 2024
1 parent afe9890 commit 9a48558
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
35 changes: 31 additions & 4 deletions components/modals/meta/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 } =
Expand All @@ -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 (
<div className="modal-meta-content">
{error && !loading && (
Expand All @@ -76,16 +103,16 @@ class ModalMeta extends PureComponent {
dangerouslySetInnerHTML={{ __html: subtitle }} // eslint-disable-line
/>
<div className="meta-table element-fullwidth">
{tableData &&
Object.keys(tableData).map((key) =>
tableData[key] ? (
{tableDataWithContentDate &&
Object.keys(tableDataWithContentDate).map((key) =>
tableDataWithContentDate[key] ? (
<div key={key} className="table-row">
<div
className="title-column"
dangerouslySetInnerHTML={{ __html: lowerCase(key) }} // eslint-disable-line
/>
<div className="description-column">
<Remark>{tableData[key]}</Remark>
<Remark>{tableDataWithContentDate[key]}</Remark>
</div>
</div>
) : null
Expand Down
4 changes: 3 additions & 1 deletion components/modals/meta/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 9a48558

Please sign in to comment.