fix(Dashboard): DatePicker to not autoclose modal (#30702)

This commit is contained in:
Geido 2024-10-24 19:26:42 +03:00 committed by GitHub
parent c9ff09a418
commit 19f840cde7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 118 additions and 1 deletions

View File

@ -307,7 +307,11 @@ export default function DateFilterLabel(props: DateFilterControlProps) {
<AdvancedFrame value={timeRangeValue} onChange={setTimeRangeValue} /> <AdvancedFrame value={timeRangeValue} onChange={setTimeRangeValue} />
)} )}
{frame === 'Custom' && ( {frame === 'Custom' && (
<CustomFrame value={timeRangeValue} onChange={setTimeRangeValue} /> <CustomFrame
value={timeRangeValue}
onChange={setTimeRangeValue}
isOverflowingFilterBar={isOverflowingFilterBar}
/>
)} )}
{frame === 'No filter' && <div data-test={DateFilterTestKey.NoFilter} />} {frame === 'No filter' && <div data-test={DateFilterTestKey.NoFilter} />}
<Divider /> <Divider />

View File

@ -166,6 +166,11 @@ export function CustomFrame(props: FrameComponentProps) {
} }
allowClear={false} allowClear={false}
locale={datePickerLocale} locale={datePickerLocale}
getPopupContainer={triggerNode =>
props.isOverflowingFilterBar
? (triggerNode.parentNode as HTMLElement)
: document.body
}
/> />
</Row> </Row>
)} )}
@ -219,6 +224,11 @@ export function CustomFrame(props: FrameComponentProps) {
} }
allowClear={false} allowClear={false}
locale={datePickerLocale} locale={datePickerLocale}
getPopupContainer={triggerNode =>
props.isOverflowingFilterBar
? (triggerNode.parentNode as HTMLElement)
: document.body
}
/> />
</Row> </Row>
)} )}
@ -277,6 +287,11 @@ export function CustomFrame(props: FrameComponentProps) {
allowClear={false} allowClear={false}
className="control-anchor-to-datetime" className="control-anchor-to-datetime"
locale={datePickerLocale} locale={datePickerLocale}
getPopupContainer={triggerNode =>
props.isOverflowingFilterBar
? (triggerNode.parentNode as HTMLElement)
: document.body
}
/> />
</Col> </Col>
)} )}

View File

@ -28,7 +28,9 @@ import {
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { CustomFrame } from '../components'; import { CustomFrame } from '../components';
const TODAY = '2024-06-03';
jest.useFakeTimers(); jest.useFakeTimers();
jest.setSystemTime(new Date(TODAY).getTime());
const emptyValue = ''; const emptyValue = '';
const nowValue = 'now : now'; const nowValue = 'now : now';
@ -280,3 +282,98 @@ test('should translate Date Picker', async () => {
expect(screen.getByText('sa')).toBeInTheDocument(); expect(screen.getByText('sa')).toBeInTheDocument();
expect(screen.getByText('di')).toBeInTheDocument(); expect(screen.getByText('di')).toBeInTheDocument();
}); });
test('calls onChange when START Specific Date/Time is selected', async () => {
const onChange = jest.fn();
render(
<Provider store={store}>
<CustomFrame
onChange={onChange}
value={specificValue}
isOverflowingFilterBar
/>
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
const specificDateTimeOptions = screen.getAllByText('Specific Date/Time');
expect(specificDateTimeOptions.length).toBe(2);
const calendarIcons = screen.getAllByRole('img', { name: 'calendar' });
userEvent.click(calendarIcons[0]);
const randomDate = screen.getByTitle('2021-03-11');
userEvent.click(randomDate);
const okButton = screen.getByText('Ok');
userEvent.click(okButton);
expect(onChange).toHaveBeenCalled();
});
test('calls onChange when END Specific Date/Time is selected', async () => {
const onChange = jest.fn();
render(
<Provider store={store}>
<CustomFrame
onChange={onChange}
value={specificValue}
isOverflowingFilterBar
/>
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
const specificDateTimeOptions = screen.getAllByText('Specific Date/Time');
expect(specificDateTimeOptions.length).toBe(2);
const calendarIcons = screen.getAllByRole('img', { name: 'calendar' });
userEvent.click(calendarIcons[1]);
const randomDate = screen.getByTitle('2021-03-28');
userEvent.click(randomDate);
const okButton = screen.getByText('Ok');
userEvent.click(okButton);
expect(onChange).toHaveBeenCalled();
});
test('calls onChange when a date is picked from anchor mode date picker', async () => {
const onChange = jest.fn();
render(
<Provider store={store}>
<CustomFrame
onChange={onChange}
value={relativeTodayValue}
isOverflowingFilterBar
/>
</Provider>,
);
await waitForElementToBeRemoved(() => screen.queryByLabelText('Loading'));
const relativeDateTimeOptions = screen.getAllByText('Relative Date/Time');
expect(relativeDateTimeOptions.length).toBe(2);
await waitFor(() =>
expect(screen.getByText('Anchor to')).toBeInTheDocument(),
);
const dateTimeRadio = screen.getByRole('radio', { name: 'Date/Time' });
expect(dateTimeRadio).toBeChecked();
const calendarIcon = screen.getByRole('img', { name: 'calendar' });
userEvent.click(calendarIcon);
const randomDate = screen.getByTitle('2024-06-05');
userEvent.click(randomDate);
const okButton = screen.getByText('Ok');
userEvent.click(okButton);
expect(onChange).toHaveBeenCalled();
});

View File

@ -101,6 +101,7 @@ export type CurrentRangeType =
export type FrameComponentProps = { export type FrameComponentProps = {
onChange: (timeRange: string) => void; onChange: (timeRange: string) => void;
value: string; value: string;
isOverflowingFilterBar?: boolean;
}; };
export interface DateFilterControlProps { export interface DateFilterControlProps {