From 97089b795b8fb8c1545e864d272cb601fcb9c461 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 discovered this upon looking at the mers
example dataset provided by get-data.sh.
---
bundlesize.config.json | 2 +-
package-lock.json | 14 ++++++++++++++
package.json | 1 +
src/components/framework/fine-print.js | 3 ++-
src/components/info/byline.js | 3 ++-
webpack.config.js | 1 +
6 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/bundlesize.config.json b/bundlesize.config.json
index dae3c6ef9..f356d72b4 100644
--- a/bundlesize.config.json
+++ b/bundlesize.config.json
@@ -10,7 +10,7 @@
},
{
"path": "./dist/auspice.?(chunk.)core-vendors.bundle.*.js",
- "maxSize": "220 kB"
+ "maxSize": "250 kB"
},
{
"path": "./dist/auspice.?(chunk.)other-vendors.bundle.*.js",
diff --git a/package-lock.json b/package-lock.json
index 57293b22d..7e4749472 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -59,6 +59,7 @@
"linspace": "^1.0.0",
"lodash": "^4.17.21",
"lodash-webpack-plugin": "^0.11.6",
+ "luxon": "^3.4.4",
"marked": "^0.7.0",
"mousetrap": "^1.6.2",
"null-loader": "^4.0.0",
@@ -10787,6 +10788,14 @@
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="
},
+ "node_modules/luxon": {
+ "version": "3.4.4",
+ "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz",
+ "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==",
+ "engines": {
+ "node": ">=12"
+ }
+ },
"node_modules/make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
@@ -22579,6 +22588,11 @@
}
}
},
+ "luxon": {
+ "version": "3.4.4",
+ "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz",
+ "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA=="
+ },
"make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
diff --git a/package.json b/package.json
index c826d9d01..f67c6b79c 100644
--- a/package.json
+++ b/package.json
@@ -89,6 +89,7 @@
"linspace": "^1.0.0",
"lodash": "^4.17.21",
"lodash-webpack-plugin": "^0.11.6",
+ "luxon": "^3.4.4",
"marked": "^0.7.0",
"mousetrap": "^1.6.2",
"null-loader": "^4.0.0",
diff --git a/src/components/framework/fine-print.js b/src/components/framework/fine-print.js
index 0ae7c0e9d..ab2f2e563 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 { DateTime } from "luxon";
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 (DateTime.fromISO(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..0dc9d17a6 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 { DateTime } from "luxon";
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 (DateTime.fromISO(metadata.updated).isValid) {
return (
{`${t("Data updated")} ${metadata.updated}. `}
diff --git a/webpack.config.js b/webpack.config.js
index cf332a42d..e9020ee51 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -133,6 +133,7 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
"style-loader",
"@hot-loader/react-dom",
"react(-(redux|select|helmet|i18next))?",
+ "luxon",
"leaflet",
"redux",
"leaflet(-gesture-handling)?",