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-882 user can't select future time in calendar #1224

Merged
merged 11 commits into from
Mar 19, 2024
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');
PengxiWPix marked this conversation as resolved.
Show resolved Hide resolved
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
Loading