Skip to content

Commit

Permalink
Merge pull request #75 from arenadata/feature/ADH-4753
Browse files Browse the repository at this point in the history
feature/ADH-4753 request date range object to independent fields
  • Loading branch information
remizov-arena authored Jul 26, 2024
2 parents fec409c + 69e87c0 commit 9eaecad
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
9 changes: 3 additions & 6 deletions smart-frontend/app/src/api/adh/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,14 +28,11 @@ export class AdhActionsApi {
sortParams: SortParams,
paginationParams: PaginationParams,
): Promise<PaginateCollection<AdhAction>> {
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,
Expand Down
6 changes: 2 additions & 4 deletions smart-frontend/app/src/api/adh/auditEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,12 +28,10 @@ export class AdhAuditEventsApi {
sortParams: SortParams,
paginationParams: PaginationParams,
): Promise<PaginateCollection<AdhAuditEvent>> {
const { from: eventTimeTimeFrom, to: eventTimeTimeTo } = prepareDateRange(eventTime);

const queryParams = prepareQueryParams(
{
...filter,
eventTimeTime: { eventTimeTimeFrom, eventTimeTimeTo },
...prepareNamedDateRange(eventTime, 'eventTime'),
},
sortParams,
paginationParams,
Expand Down
6 changes: 2 additions & 4 deletions smart-frontend/app/src/api/adh/clusterInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,12 +28,10 @@ export class AdhClusterInfoApi {
sortParams?: SortParams,
paginationParams?: PaginationParams,
): Promise<PaginateCollection<AdhClusterNode>> {
const { from: registrationTimeFrom, to: registrationTimeTo } = prepareDateRange(registrationTime);

const queryParams = prepareQueryParams(
{
...filter,
registrationTime: { registrationTimeFrom, registrationTimeTo },
...prepareNamedDateRange(registrationTime, 'registrationTime'),
},
sortParams,
paginationParams,
Expand Down
13 changes: 4 additions & 9 deletions smart-frontend/app/src/api/adh/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,12 +28,10 @@ export class AdhFilesApi {
sortParams: SortParams,
paginationParams: PaginationParams,
): Promise<PaginateCollection<AdhFileInfo>> {
const { from: lastAccessedTimeFrom, to: lastAccessedTimeTo } = prepareDateRange(lastAccessedTime);

const queryParams = prepareQueryParams(
{
...filter,
lastAccessedTime: { lastAccessedTimeFrom, lastAccessedTimeTo },
...prepareNamedDateRange(lastAccessedTime, 'lastAccessedTime'),
},
sortParams,
paginationParams,
Expand All @@ -50,14 +48,11 @@ export class AdhFilesApi {
sortParams: SortParams,
paginationParams: PaginationParams,
): Promise<PaginateCollection<AdhCachedFileInfo>> {
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,
Expand Down
9 changes: 3 additions & 6 deletions smart-frontend/app/src/api/adh/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,14 +28,11 @@ export class AdhRulesApi {
sortParams?: SortParams,
paginationParams?: PaginationParams,
): Promise<PaginateCollection<AdhRule>> {
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,
Expand Down
12 changes: 6 additions & 6 deletions smart-frontend/app/src/utils/date/dateConvertUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 8 additions & 0 deletions smart-frontend/app/src/utils/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@ export const prepareDateRange = (
to: utcDateToLocal(to),
}) as StaticDateRange<SerializedDate>;
};

export const prepareNamedDateRange = (dateRange: DateRange<SerializedDate> | undefined, keyName: string) => {
const dateObject = prepareDateRange(dateRange);
return {
[`${keyName}From`]: dateObject.from,
[`${keyName}To`]: dateObject.to,
};
};

0 comments on commit 9eaecad

Please sign in to comment.