From 4e29303c6e54bbf62c5d1c171c14517a825c5ba0 Mon Sep 17 00:00:00 2001
From: Victor Lin <13424970+victorlin@users.noreply.github.com>
Date: Mon, 11 Dec 2023 16:36:33 -0800
Subject: [PATCH] Hide "Data updated" for invalid dates
A bad value could show as an inaccuracy such as "Data updated today",
which shouldn't be allowed. I found this out upon looking at the mers
example dataset provided by get-data.sh.
---
package-lock.json | 14 ++++++++++++++
package.json | 1 +
src/components/framework/fine-print.js | 3 ++-
src/components/info/byline.js | 3 ++-
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 57293b22d..f9d64b650 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -60,6 +60,7 @@
"lodash": "^4.17.21",
"lodash-webpack-plugin": "^0.11.6",
"marked": "^0.7.0",
+ "moment": "^2.29.4",
"mousetrap": "^1.6.2",
"null-loader": "^4.0.0",
"outer-product": "0.0.4",
@@ -11030,6 +11031,14 @@
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
"dev": true
},
+ "node_modules/moment": {
+ "version": "2.29.4",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
+ "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/mousetrap": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.5.tgz",
@@ -22762,6 +22771,11 @@
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
"dev": true
},
+ "moment": {
+ "version": "2.29.4",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
+ "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
+ },
"mousetrap": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.5.tgz",
diff --git a/package.json b/package.json
index c826d9d01..8ac19c717 100644
--- a/package.json
+++ b/package.json
@@ -90,6 +90,7 @@
"lodash": "^4.17.21",
"lodash-webpack-plugin": "^0.11.6",
"marked": "^0.7.0",
+ "moment": "^2.29.4",
"mousetrap": "^1.6.2",
"null-loader": "^4.0.0",
"outer-product": "0.0.4",
diff --git a/src/components/framework/fine-print.js b/src/components/framework/fine-print.js
index 0ae7c0e9d..a07265360 100644
--- a/src/components/framework/fine-print.js
+++ b/src/components/framework/fine-print.js
@@ -3,6 +3,7 @@ import { connect } from "react-redux";
import styled from 'styled-components';
import { withTranslation } from "react-i18next";
import { FaDownload } from "react-icons/fa";
+import moment from "moment";
import { dataFont, medGrey, materialButton } from "../../globalStyles";
import { TRIGGER_DOWNLOAD_MODAL } from "../../actions/types";
import Flex from "./flex";
@@ -72,7 +73,7 @@ class FinePrint extends React.Component {
getUpdated() {
const { t } = this.props;
- if (this.props.metadata.updated) {
+ if (moment(this.props.metadata.updated).isValid()) {
return ({t("Data updated")} {this.props.metadata.updated});
}
return null;
diff --git a/src/components/info/byline.js b/src/components/info/byline.js
index 83f136611..fc9f2f9b4 100644
--- a/src/components/info/byline.js
+++ b/src/components/info/byline.js
@@ -2,6 +2,7 @@ import React from "react";
import { connect } from "react-redux";
import { withTranslation } from 'react-i18next';
import styled from 'styled-components';
+import moment from "moment";
import { headerFont } from "../../globalStyles";
/**
@@ -107,7 +108,7 @@ function renderMaintainers(t, metadata) {
* Renders a containing "Data updated X", where X derives from `metadata.updated`
*/
function renderDataUpdated(t, metadata) {
- if (metadata.updated) {
+ if (moment(metadata.updated).isValid()) {
return (
{`${t("Data updated")} ${metadata.updated}. `}