Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADM-878:[frontend]refactor: rename date range #1381

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import DateRangeViewer from '@src/components/Common/DateRangeViewer';
import { TDateRange } from '@src/context/config/configSlice';
import { DateRange } from '@src/context/config/configSlice';
import userEvent from '@testing-library/user-event';
import { render } from '@testing-library/react';

describe('DateRangeViewer', () => {
const setup = (dateRanges: TDateRange) => {
const setup = (dateRanges: DateRange) => {
return render(<DateRangeViewer dateRanges={dateRanges} />);
};
const mockDateRanges = [
Expand Down
4 changes: 2 additions & 2 deletions frontend/__tests__/containers/ReportStep/ReportStep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
SHOW_MORE,
} from '../../fixtures';
import {
TDateRange,
DateRange,
updateDateRange,
updateJiraVerifyResponse,
updateMetrics,
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Report Step', () => {
reportHook.current.reportData = { ...MOCK_REPORT_RESPONSE, exportValidityTime: 30 };
};
const handleSaveMock = jest.fn();
const setup = (params: string[], dateRange?: TDateRange) => {
const setup = (params: string[], dateRange?: DateRange) => {
store = setupStore();
dateRange && store.dispatch(updateDateRange(dateRange));
store.dispatch(
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/clients/board/dto/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TDateRange } from '@src/context/config/configSlice';
import { DateRange } from '@src/context/config/configSlice';

export interface BoardRequestDTO {
token: string;
Expand All @@ -20,6 +20,6 @@ export interface BoardInfoRequestDTO {
}

export interface BoardInfoConfigDTO extends BoardRequestDTO {
dateRanges: TDateRange | null;
dateRanges: DateRange | null;
projectKey: string;
}
4 changes: 2 additions & 2 deletions frontend/src/components/Common/DateRangeViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
StyledExpandMoreIcon,
} from './style';
import React, { useRef, useState, forwardRef, useEffect, useCallback } from 'react';
import { TDateRange } from '@src/context/config/configSlice';
import { DateRange } from '@src/context/config/configSlice';
import { formatDate } from '@src/utils/util';
import { theme } from '@src/theme';

type Props = {
dateRanges: TDateRange;
dateRanges: DateRange;
expandColor?: string;
expandBackgroundColor?: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import dayjsSameOrBeforePlugin from 'dayjs/plugin/isSameOrBefore';
import dayjsSameOrAfterPlugin from 'dayjs/plugin/isSameOrAfter';
import { TDateRange } from '@src/context/config/configSlice';
import { DateRange } from '@src/context/config/configSlice';
import dayjs, { Dayjs } from 'dayjs';

dayjs.extend(dayjsSameOrBeforePlugin);
dayjs.extend(dayjsSameOrAfterPlugin);

export const calculateLastAvailableDate = (date: Dayjs, coveredRange: TDateRange) => {
export const calculateLastAvailableDate = (date: Dayjs, coveredRange: DateRange) => {
let lastAvailableDate = dayjs(new Date()).startOf('date');
let minimumDiffDays = lastAvailableDate.diff(date, 'days');

Expand All @@ -24,7 +24,7 @@ export const calculateLastAvailableDate = (date: Dayjs, coveredRange: TDateRange
return lastAvailableDate;
};

export const isDateDisabled = (coveredRange: TDateRange, date: Dayjs) =>
export const isDateDisabled = (coveredRange: DateRange, date: Dayjs) =>
coveredRange.some(
({ startDate, endDate }) => date.isSameOrAfter(startDate, 'date') && date.isSameOrBefore(endDate, 'date'),
);
4 changes: 2 additions & 2 deletions frontend/src/context/config/configSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import merge from 'lodash/merge';
import { isArray } from 'lodash';
import dayjs from 'dayjs';

export type TDateRange = {
export type DateRange = {
startDate: string | null;
endDate: string | null;
}[];
Expand All @@ -28,7 +28,7 @@ export interface BasicConfigState {
basic: {
projectName: string;
calendarType: string;
dateRange: TDateRange;
dateRange: DateRange;
metrics: string[];
};
board: IBoardState;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ICycleTimeSetting, IPipelineConfig } from '@src/context/Metrics/metrics
import { ITargetFieldType } from '@src/components/Common/MultiAutoComplete/styles';
import { BoardInfoResponse } from '@src/hooks/useGetBoardInfo';
import { DATE_FORMAT_TEMPLATE } from '@src/constants/template';
import { TDateRange } from '@src/context/config/configSlice';
import { DateRange } from '@src/context/config/configSlice';
import { includes, isEqual, sortBy, uniqBy } from 'lodash';
import duration from 'dayjs/plugin/duration';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -102,7 +102,7 @@ export const formatDateToTimestampString = (date: string) => {
return dayjs(date).valueOf().toString();
};

export const sortDateRanges = (dateRanges: TDateRange, descending = true) => {
export const sortDateRanges = (dateRanges: DateRange, descending = true) => {
const result = [...dateRanges].sort((a, b) => {
return dayjs(b.startDate as string).diff(dayjs(a.startDate as string));
});
Expand Down
Loading