From 4ef0353f8aa0cdf1a9d6320ddcc2c1ab878e2598 Mon Sep 17 00:00:00 2001 From: Matt Bevilacqua Date: Mon, 15 Nov 2021 15:23:41 -0500 Subject: [PATCH] Merge HHS (#487) * Bump validator from 13.6.0 to 13.7.0 Bumps [validator](https://github.com/validatorjs/validator.js) from 13.6.0 to 13.7.0. - [Release notes](https://github.com/validatorjs/validator.js/releases) - [Changelog](https://github.com/validatorjs/validator.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/validatorjs/validator.js/compare/13.6.0...13.7.0) --- updated-dependencies: - dependency-name: validator dependency-type: direct:production ... Signed-off-by: dependabot[bot] * welcoming robots in certain situations * Update known vulnerabilities * trying a different approach in the config * is this how we set vars? * fix var name * test on dev since sandbox does not do what I thought * update trusworks with modal changes * need to learn how to do bash * more bash better * for christmas sake * testing complete * fix bash script var names * updated file uploader modal * updated external resource modal * move logic to circlci config * awaken robot on prod * Update .circleci/config.yml Co-authored-by: Josh Salisbury * add approvedat migration * update approvedAt on approval * clean up constants, add new one * add approved and created dates to fe landing page * add approved and created date to csv download * remove console statement * fixing tests * fixed modal unit tests * updated my alert test * fixed modal tests for external resource * partial fixes for ui tests * clean up prop type * cleanup UI tests * more unit test fixes for trussworks2 * idle modal test fixes * add backend tests * fixed accessibility issue and added test coverage * add target populations to ar * add approved and created date to ar, table css fixes * fix failing ui test * fix failing tooltip test * unique id value * update known issues * fix axe * Update known vulnerabilities * fix axe again * fix axe issues again * try heading axe fix * update test for axe * update * see if remvoing display none fixes issue * hide headings * limit number of headings * added cusom accordion with heading size prop * added test for accordion * fix capitalizations while we're here * fixes based on Kryss comments * linter fixes * audit vuln * change unlock report button css to outline * remove to be deleted files from test coverage Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: unknown Co-authored-by: Adam Levin Co-authored-by: Josh Salisbury Co-authored-by: Adam Levin <84350609+AdamAdHocTeam@users.noreply.github.com> --- frontend/package.json | 4 +- .../src/pages/RegionalDashboard/constants.js | 15 +++++++ .../RegionalDashboard/formatDateRange.js | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 frontend/src/pages/RegionalDashboard/constants.js create mode 100644 frontend/src/pages/RegionalDashboard/formatDateRange.js diff --git a/frontend/package.json b/frontend/package.json index 33fe869394..2255fbf039 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -157,7 +157,9 @@ "/src/pages/NotFound/index.js", "/src/polyfills.js", "/src/pages/Widgets/index.js", - "/src/widgets/Example.js" + "/src/widgets/Example.js", + "/src/pages/RegionalDashboard/formatDateRange.js", + "/src/pages/RegionalDashboard/constants.js" ], "coverageThreshold": { "global": { diff --git a/frontend/src/pages/RegionalDashboard/constants.js b/frontend/src/pages/RegionalDashboard/constants.js new file mode 100644 index 0000000000..b2a57f9465 --- /dev/null +++ b/frontend/src/pages/RegionalDashboard/constants.js @@ -0,0 +1,15 @@ +export const DATETIME_DATE_FORMAT = 'YYYY/MM/DD'; + +export const DATE_OPTIONS = [ + { + label: 'Last 30 Days', + value: 1, + }, + { + label: 'Custom Date Range', + value: 2, + }, +]; + +export const LAST_THIRTY_DAYS = DATE_OPTIONS[0].value; +export const CUSTOM_DATE_RANGE = DATE_OPTIONS[1].value; diff --git a/frontend/src/pages/RegionalDashboard/formatDateRange.js b/frontend/src/pages/RegionalDashboard/formatDateRange.js new file mode 100644 index 0000000000..0e4a82926c --- /dev/null +++ b/frontend/src/pages/RegionalDashboard/formatDateRange.js @@ -0,0 +1,39 @@ +import moment from 'moment'; +import { DATETIME_DATE_FORMAT } from './constants'; +import { DATE_DISPLAY_FORMAT as DATE_FORMAT } from '../../Constants'; + +export default function formatDateRange(format = { + lastThirtyDays: false, withSpaces: false, forDateTime: false, sep: '-', string: '', +}) { + const selectedFormat = format.forDateTime ? DATETIME_DATE_FORMAT : DATE_FORMAT; + + let { sep } = format; + + if (!format.sep) { + sep = '-'; + } + if (format.lastThirtyDays) { + const today = moment(); + const thirtyDaysAgo = moment().subtract(30, 'days'); + + if (format.withSpaces) { + return `${thirtyDaysAgo.format(selectedFormat)} ${sep} ${today.format(selectedFormat)}`; + } + + return `${thirtyDaysAgo.format(selectedFormat)}${sep}${today.format(selectedFormat)}`; + } + + if (format.string) { + const dates = format.string.split('-'); + + if (dates && dates.length > 1) { + if (format.withSpaces) { + return `${moment(dates[0], DATETIME_DATE_FORMAT).format(selectedFormat)} ${sep} ${moment(dates[1], DATETIME_DATE_FORMAT).format(selectedFormat)}`; + } + + return `${moment(dates[0], DATETIME_DATE_FORMAT).format(selectedFormat)}${sep}${moment(dates[1], DATETIME_DATE_FORMAT).format(selectedFormat)}`; + } + } + + return ''; +}