From 50bdae1579f7bf4f48720975f10eeb5304f1cb25 Mon Sep 17 00:00:00 2001 From: Angela The Date: Fri, 20 Dec 2024 09:31:18 -0800 Subject: [PATCH] Update dateRangelabels Co-authored-by: Mary McGrath --- .../src/app/view-data/utils/date-utils.ts | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/containers/ecr-viewer/src/app/view-data/utils/date-utils.ts b/containers/ecr-viewer/src/app/view-data/utils/date-utils.ts index 9228ea343..10810d8db 100644 --- a/containers/ecr-viewer/src/app/view-data/utils/date-utils.ts +++ b/containers/ecr-viewer/src/app/view-data/utils/date-utils.ts @@ -14,26 +14,13 @@ export enum DateRangeOptions { LastYear = "last-year", } -export const dateRangeLabels: { [key in DateRangeOptions]: string } = { - [DateRangeOptions.Last24Hours]: toSentenceCase( - DateRangeOptions.Last24Hours.replace(/-/g, " "), - ) as string, - [DateRangeOptions.Last7Days]: toSentenceCase( - DateRangeOptions.Last7Days.replace(/-/g, " "), - ) as string, - [DateRangeOptions.Last30Days]: toSentenceCase( - DateRangeOptions.Last30Days.replace(/-/g, " "), - ) as string, - [DateRangeOptions.Last3Months]: toSentenceCase( - DateRangeOptions.Last3Months.replace(/-/g, " "), - ) as string, - [DateRangeOptions.Last6Months]: toSentenceCase( - DateRangeOptions.Last6Months.replace(/-/g, " "), - ) as string, - [DateRangeOptions.LastYear]: toSentenceCase( - DateRangeOptions.LastYear.replace(/-/g, " "), - ) as string, -}; +export const dateRangeLabels = Object.keys(DateRangeOptions).reduce((res, k) => { + if (typeof DateRangeOptions[k] === 'number') { + res[k] = toSentenceCase(k.replace(/-/g, " ")) + } + return res +}, {} +) /** * Calculates the date a specified number of days ago from the given date