diff --git a/smart-frontend/app/src/api/adh/actions.ts b/smart-frontend/app/src/api/adh/actions.ts index e1ba904520..75a4f1f01a 100644 --- a/smart-frontend/app/src/api/adh/actions.ts +++ b/smart-frontend/app/src/api/adh/actions.ts @@ -18,7 +18,7 @@ import type { AdhAction, AdhActionsFilter } from '@models/adh'; import type { PaginationParams, SortParams } from '@models/table'; import type { PaginateCollection } from '@models/collection'; -import { prepareDateRange, prepareQueryParams } from '@utils/requestUtils'; +import { prepareNamedDateRange, prepareQueryParams } from '@utils/requestUtils'; import { httpClient } from '@api/httpClient'; import qs from 'qs'; @@ -28,14 +28,11 @@ export class AdhActionsApi { sortParams: SortParams, paginationParams: PaginationParams, ): Promise> { - const { from: submissionTimeFrom, to: submissionTimeTo } = prepareDateRange(submissionTime); - const { from: completionTimeFrom, to: completionTimeTo } = prepareDateRange(completionTime); - const queryParams = prepareQueryParams( { ...filter, - submissionTime: { submissionTimeFrom, submissionTimeTo }, - completionTime: { completionTimeFrom, completionTimeTo }, + ...prepareNamedDateRange(submissionTime, 'submissionTime'), + ...prepareNamedDateRange(completionTime, 'completionTime'), }, sortParams, paginationParams, diff --git a/smart-frontend/app/src/api/adh/auditEvents.ts b/smart-frontend/app/src/api/adh/auditEvents.ts index e1c4eb74cd..501e7261f1 100644 --- a/smart-frontend/app/src/api/adh/auditEvents.ts +++ b/smart-frontend/app/src/api/adh/auditEvents.ts @@ -17,7 +17,7 @@ */ import type { PaginationParams, SortParams } from '@models/table'; import type { PaginateCollection } from '@models/collection'; -import { prepareDateRange, prepareQueryParams } from '@utils/requestUtils'; +import { prepareNamedDateRange, prepareQueryParams } from '@utils/requestUtils'; import { httpClient } from '@api/httpClient'; import qs from 'qs'; import type { AdhAuditEvent, AdhAuditEventsFilter } from '@models/adh/auditEvent'; @@ -28,12 +28,10 @@ export class AdhAuditEventsApi { sortParams: SortParams, paginationParams: PaginationParams, ): Promise> { - const { from: eventTimeTimeFrom, to: eventTimeTimeTo } = prepareDateRange(eventTime); - const queryParams = prepareQueryParams( { ...filter, - eventTimeTime: { eventTimeTimeFrom, eventTimeTimeTo }, + ...prepareNamedDateRange(eventTime, 'eventTime'), }, sortParams, paginationParams, diff --git a/smart-frontend/app/src/api/adh/clusterInfo.ts b/smart-frontend/app/src/api/adh/clusterInfo.ts index a05f65f6ef..b23771b48a 100644 --- a/smart-frontend/app/src/api/adh/clusterInfo.ts +++ b/smart-frontend/app/src/api/adh/clusterInfo.ts @@ -19,7 +19,7 @@ import type { PaginateCollection } from '@models/collection'; import { httpClient } from '@api/httpClient'; import type { AdhClusterNodesFilter, AdhClusterNode } from '@models/adh'; import type { PaginationParams, SortParams } from '@models/table'; -import { prepareDateRange, prepareQueryParams } from '@utils/requestUtils'; +import { prepareNamedDateRange, prepareQueryParams } from '@utils/requestUtils'; import qs from 'qs'; export class AdhClusterInfoApi { @@ -28,12 +28,10 @@ export class AdhClusterInfoApi { sortParams?: SortParams, paginationParams?: PaginationParams, ): Promise> { - const { from: registrationTimeFrom, to: registrationTimeTo } = prepareDateRange(registrationTime); - const queryParams = prepareQueryParams( { ...filter, - registrationTime: { registrationTimeFrom, registrationTimeTo }, + ...prepareNamedDateRange(registrationTime, 'registrationTime'), }, sortParams, paginationParams, diff --git a/smart-frontend/app/src/api/adh/files.ts b/smart-frontend/app/src/api/adh/files.ts index bfd57b56de..b7777439e8 100644 --- a/smart-frontend/app/src/api/adh/files.ts +++ b/smart-frontend/app/src/api/adh/files.ts @@ -18,7 +18,7 @@ import type { AdhFileInfo, AdhFileInfoFilter, AdhCachedFileInfo, AdhCachedFileInfoFilter } from '@models/adh'; import type { PaginationParams, SortParams } from '@models/table'; import type { PaginateCollection } from '@models/collection'; -import { prepareDateRange, prepareQueryParams } from '@utils/requestUtils'; +import { prepareNamedDateRange, prepareQueryParams } from '@utils/requestUtils'; import { httpClient } from '@api/httpClient'; import qs from 'qs'; @@ -28,12 +28,10 @@ export class AdhFilesApi { sortParams: SortParams, paginationParams: PaginationParams, ): Promise> { - const { from: lastAccessedTimeFrom, to: lastAccessedTimeTo } = prepareDateRange(lastAccessedTime); - const queryParams = prepareQueryParams( { ...filter, - lastAccessedTime: { lastAccessedTimeFrom, lastAccessedTimeTo }, + ...prepareNamedDateRange(lastAccessedTime, 'lastAccessedTime'), }, sortParams, paginationParams, @@ -50,14 +48,11 @@ export class AdhFilesApi { sortParams: SortParams, paginationParams: PaginationParams, ): Promise> { - const { from: lastAccessedTimeFrom, to: lastAccessedTimeTo } = prepareDateRange(lastAccessedTime); - const { from: cachedTimeFrom, to: cachedTimeTo } = prepareDateRange(cachedTime); - const queryParams = prepareQueryParams( { ...filter, - lastAccessedTime: { lastAccessedTimeFrom, lastAccessedTimeTo }, - cachedTime: { cachedTimeFrom, cachedTimeTo }, + ...prepareNamedDateRange(lastAccessedTime, 'lastAccessedTime'), + ...prepareNamedDateRange(cachedTime, 'cachedTime'), }, sortParams, paginationParams, diff --git a/smart-frontend/app/src/api/adh/rules.ts b/smart-frontend/app/src/api/adh/rules.ts index 5517c7db2a..7428929ec9 100644 --- a/smart-frontend/app/src/api/adh/rules.ts +++ b/smart-frontend/app/src/api/adh/rules.ts @@ -18,7 +18,7 @@ import type { AdhRule, AdhRuleFilter } from '@models/adh'; import type { PaginationParams, SortParams } from '@models/table'; import type { PaginateCollection } from '@models/collection'; -import { prepareDateRange, prepareQueryParams } from '@utils/requestUtils'; +import { prepareNamedDateRange, prepareQueryParams } from '@utils/requestUtils'; import { httpClient } from '@api/httpClient'; import qs from 'qs'; @@ -28,14 +28,11 @@ export class AdhRulesApi { sortParams?: SortParams, paginationParams?: PaginationParams, ): Promise> { - const { from: submissionTimeFrom, to: submissionTimeTo } = prepareDateRange(submissionTime); - const { from: lastActivationTimeFrom, to: lastActivationTimeTo } = prepareDateRange(lastActivationTime); - const queryParams = prepareQueryParams( { ...filter, - submissionTime: { submissionTimeFrom, submissionTimeTo }, - lastActivationTime: { lastActivationTimeFrom, lastActivationTimeTo }, + ...prepareNamedDateRange(submissionTime, 'submissionTime'), + ...prepareNamedDateRange(lastActivationTime, 'lastActivationTime'), }, sortParams, paginationParams, diff --git a/smart-frontend/app/src/utils/date/dateConvertUtils.ts b/smart-frontend/app/src/utils/date/dateConvertUtils.ts index e55027d38f..a05aaf6fb2 100644 --- a/smart-frontend/app/src/utils/date/dateConvertUtils.ts +++ b/smart-frontend/app/src/utils/date/dateConvertUtils.ts @@ -62,14 +62,14 @@ export const millisecondsToDuration = (milliseconds: number) => { return dateDuration(curDate, new Date(curDate.getTime() + milliseconds)); }; -export const secondsToDate = (seconds: number): Date => { - return new Date(Math.floor(seconds * 1000)); +export const millisecondsToDate = (milliseconds: number): Date => { + return new Date(milliseconds); }; -export const dateToSeconds = (date: Date): number => { +export const dateToMilliseconds = (date: Date): number => { if (date === null) return 0; - return Math.floor(date.getTime() / 1000); + return date.getTime(); }; -export const deserializeDate = (seconds: SerializedDate): Date => secondsToDate(seconds); -export const serializeDate = (date: Date): SerializedDate => dateToSeconds(date); +export const deserializeDate = (milliseconds: SerializedDate): Date => millisecondsToDate(milliseconds); +export const serializeDate = (date: Date): SerializedDate => dateToMilliseconds(date); diff --git a/smart-frontend/app/src/utils/requestUtils.ts b/smart-frontend/app/src/utils/requestUtils.ts index bdd8ec4c18..9831a7d553 100644 --- a/smart-frontend/app/src/utils/requestUtils.ts +++ b/smart-frontend/app/src/utils/requestUtils.ts @@ -104,3 +104,11 @@ export const prepareDateRange = ( to: utcDateToLocal(to), }) as StaticDateRange; }; + +export const prepareNamedDateRange = (dateRange: DateRange | undefined, keyName: string) => { + const dateObject = prepareDateRange(dateRange); + return { + [`${keyName}From`]: dateObject.from, + [`${keyName}To`]: dateObject.to, + }; +};