Skip to content

Commit

Permalink
INTLY-1362 Validate walkthrough date field before displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden Keating committed Apr 15, 2019
1 parent ea3f779 commit b521367
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/walkthroughDetails/walkthroughDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ class WalkthroughDetails extends React.Component {
this.state = {};
}

static validWalkthroughDate(dateString) {
try {
// We need to modify the returned string to allow for Firefox compatibility. This just keeps the date section, removes the time and everything after.
return new Date(dateString.split(' ')[0]).toISOString().slice(0, 10);
} catch (e) {
return null;
}
}

render() {
const { walkthroughInfo } = this.props;

return (
<Card>
<CardBody>
Expand All @@ -22,7 +32,8 @@ class WalkthroughDetails extends React.Component {
<div className="pf-u-display-flex pf-u-justify-content-space-between">
<div>Source: </div>
<div>
{walkthroughInfo.type === 'path' ? (
{walkthroughInfo.type === 'path' ||
!WalkthroughDetails.validWalkthroughDate(walkthroughInfo.commitDate) ? (
<div>---</div>
) : (
<div>
Expand All @@ -39,7 +50,7 @@ class WalkthroughDetails extends React.Component {
{walkthroughInfo.type === 'path' ? (
<div>---</div>
) : (
<div>{new Date(walkthroughInfo.commitDate).toISOString().slice(0, 10)}</div>
<div>{WalkthroughDetails.validWalkthroughDate(walkthroughInfo.commitDate)}</div>
)}
</div>
</div>
Expand Down

0 comments on commit b521367

Please sign in to comment.