Skip to content

Commit

Permalink
Hide "Data updated" for invalid dates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
victorlin committed Dec 12, 2023
1 parent 19f5c2c commit 4e29303
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/components/framework/fine-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (<span>{t("Data updated")} {this.props.metadata.updated}</span>);
}
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/components/info/byline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ function renderMaintainers(t, metadata) {
* Renders a <span> containing "Data updated X", where X derives from `metadata.updated`
*/
function renderDataUpdated(t, metadata) {
if (metadata.updated) {
if (moment(metadata.updated).isValid()) {
return (
<span>
{`${t("Data updated")} ${metadata.updated}. `}
Expand Down

0 comments on commit 4e29303

Please sign in to comment.