Skip to content

Commit

Permalink
ADM-882 user can't select future time in calendar (#1224)
Browse files Browse the repository at this point in the history
* ADM-882:[frontend]feat: disable future dates in DatePicker

* ADM-882:[frontend]feat: validate start date add interval to end date

* ADM-882:[frontend]feat: add max date interval 30 days

* ADM-882:[frontend]fix: fix prettier

* ADM-882:[frontend]fix: fix prettier again

* ADM-882:[frontend]fix: fix tests

* ADM-882:[frontend]fix: fix prettier

* ADM-882:[backend]fix: add trivy ignore

* ADM-882:[frontend]fix: remove moment and extract constant

* ADM-882:[frontend]fix: fix lint
  • Loading branch information
PengxiWPix authored and WSSsssss33 committed Mar 19, 2024
1 parent fcae189 commit 6be149f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ CVE-2023-49468
CVE-2024-0553
CVE-2024-0567
CVE-2024-22201
CVE-2024-22259
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,11 @@ describe('MetricsStepper', () => {
board: { boardId: '', email: '', site: '', token: '', type: 'Jira' },
calendarType: 'Regular Calendar(Weekend Considered)',
dateRange: {
endDate: dayjs().endOf('date').add(13, 'day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
endDate: dayjs().endOf('date').add(0, 'day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
startDate: dayjs().startOf('date').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
},
metrics: ['Velocity'],
pipelineCrews: undefined,
pipelineTool: undefined,
projectName: 'test project Name',
sourceControl: undefined,
Expand Down Expand Up @@ -377,18 +378,27 @@ describe('MetricsStepper', () => {
board: { boardId: '', email: '', site: '', token: '', type: 'Jira' },
calendarType: 'Regular Calendar(Weekend Considered)',
dateRange: {
endDate: dayjs().endOf('date').add(13, 'day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
endDate: dayjs().endOf('date').add(0, 'day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
startDate: dayjs().startOf('date').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
},
metrics: ['Velocity'],
pipelineCrews: undefined,
pipelineTool: undefined,
projectName: 'test project Name',
sourceControl: undefined,
classification: undefined,
crews: undefined,
cycleTime: undefined,
classification: ['mockClassification'],
crews: ['mockUsers'],
cycleTime: {
jiraColumns: [
{
Testing: 'Done',
},
],
treatFlagCardAsBlock: false,
type: 'byColumn',
},
deployment: undefined,
doneStatus: undefined,
doneStatus: ['Done', 'Canceled'],
leadTime: undefined,
reworkTimesSettings: {
rework2State: null,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/constants/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,5 @@ export const ALL_OPTION_META: Record<string, string> = {
label: 'All',
key: 'all',
};

export const DEFAULT_SPRINT_INTERVAL_OFFSET_DAYS = 13;
17 changes: 16 additions & 1 deletion frontend/src/containers/ConfigStep/DateRangePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { selectDateRange, updateDateRange } from '@src/context/config/configSlice';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { StyledDateRangePicker, StyledDateRangePickerContainer } from './style';
import { DEFAULT_SPRINT_INTERVAL_OFFSET_DAYS } from '@src/constants/resources';
import { useAppDispatch, useAppSelector } from '@src/hooks/useAppDispatch';
import CalendarTodayIcon from '@mui/icons-material/CalendarToday';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
Expand All @@ -24,7 +25,18 @@ export const DateRangePicker = () => {
dispatch(initDeploymentFrequencySettings());
dispatch(saveUsers([]));
};

const changeStartDate = (value: Nullable<Dayjs>) => {
let daysAddToEndDate = DEFAULT_SPRINT_INTERVAL_OFFSET_DAYS;
if (value) {
const currentDate = dayjs(new Date());
const valueToStartDate = value.startOf('date').format('YYYY-MM-DDTHH:mm:ss.SSSZ');
const daysBetweenCurrentAndStartDate = currentDate.diff(valueToStartDate, 'days');
daysAddToEndDate =
daysBetweenCurrentAndStartDate >= DEFAULT_SPRINT_INTERVAL_OFFSET_DAYS
? DEFAULT_SPRINT_INTERVAL_OFFSET_DAYS
: daysBetweenCurrentAndStartDate;
}
dispatch(
updateDateRange(
isNull(value)
Expand All @@ -34,7 +46,7 @@ export const DateRangePicker = () => {
}
: {
startDate: value.startOf('date').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
endDate: value.endOf('date').add(13, 'day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
endDate: value.endOf('date').add(daysAddToEndDate, 'day').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
},
),
);
Expand All @@ -55,6 +67,7 @@ export const DateRangePicker = () => {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<StyledDateRangePickerContainer>
<StyledDateRangePicker
disableFuture
label='From *'
value={startDate ? dayjs(startDate) : null}
onChange={(newValue) => changeStartDate(newValue as unknown as Dayjs)}
Expand All @@ -71,8 +84,10 @@ export const DateRangePicker = () => {
}}
/>
<StyledDateRangePicker
disableFuture
label='To *'
value={endDate ? dayjs(endDate) : null}
maxDate={dayjs(startDate).add(30, 'day')}
minDate={dayjs(startDate)}
onChange={(newValue) => changeEndDate(newValue as unknown as Dayjs)}
slots={{
Expand Down

0 comments on commit 6be149f

Please sign in to comment.