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

fix(datetimepickerv2): add onClear callback #3761

Merged
merged 2 commits into from
Apr 19, 2023
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
Expand Up @@ -21,6 +21,7 @@ const DateTimePicker = ({
renderPresetTooltipText,
onCancel,
onApply,
onClear,
i18n,
light,
locale,
Expand Down Expand Up @@ -50,6 +51,7 @@ const DateTimePicker = ({
renderPresetTooltipText={renderPresetTooltipText}
onCancel={onCancel}
onApply={onApply}
onClear={onClear}
i18n={i18n}
light={light}
locale={locale}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export const SingleSelect = () => {
hasTimeInput={boolean('hasTimeInput', true)}
onApply={action('onApply')}
onCancel={action('onCancel')}
onClear={action('onClear')}
datePickerType="single"
showRelativeOption={boolean('show relative option', false)}
invalid={boolean('invalid', false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ describe('DateTimePickerV2', () => {
<DateTimePicker
onApply={cy.stub()}
onCancel={cy.stub()}
onClear={cy.stub()}
id="picker-test"
hasTimeInput
useNewTimeSpinner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,13 @@ describe('DateTimePickerV2', () => {
});

it('should clear date and time fields when click clear button in single select', () => {
const mockOnClear = jest.fn();
render(
<DateTimePicker
{...dateTimePickerProps}
useNewTimeSpinner
onApply={jest.fn()}
onClear={mockOnClear}
datePickerType="single"
dateTimeMask="YYYY-MM-DD hh:mm A"
hasTimeInput
Expand All @@ -641,6 +643,18 @@ describe('DateTimePickerV2', () => {

expect(screen.getByText('YYYY-MM-DD hh:mm A')).toBeVisible();
expect(screen.queryByRole('dialog')).toBeNull();
expect(mockOnClear).toHaveBeenCalledWith({
timeRangeKind: 'SINGLE',
timeRangeValue: null,
timeSingleValue: {
ISOStart: null,
start: null,
startDate: null,
startTime: null,
humanValue: 'YYYY-MM-DD hh:mm A',
tooltipValue: 'YYYY-MM-DD hh:mm A',
},
});
});

it('should disable button when clear time picker input in single select', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export const propTypes = {
onCancel: PropTypes.func,
/** triggered on apply with returning object with similar signature to defaultValue */
onApply: PropTypes.func,
/** call back function for clear values in single select */
onClear: PropTypes.func,
/** All the labels that need translation */
i18n: PropTypes.shape({
toLabel: PropTypes.string,
Expand Down Expand Up @@ -251,6 +253,7 @@ export const defaultProps = {
renderPresetTooltipText: null,
onCancel: null,
onApply: null,
onClear: null,
i18n: {
toLabel: 'to',
toNowLabel: 'to Now',
Expand Down Expand Up @@ -308,6 +311,7 @@ const DateTimePicker = ({
renderPresetTooltipText,
onCancel,
onApply,
onClear,
i18n,
light,
locale,
Expand Down Expand Up @@ -810,6 +814,22 @@ const DateTimePicker = ({
setSingleTimeValue(null);
SetDefaultSingleDateValue(true);
setIsExpanded(false);
const returnValue = {
timeRangeKind: PICKER_KINDS.SINGLE,
timeRangeValue: null,
timeSingleValue: null,
};

returnValue.timeSingleValue = {
ISOStart: null,
humanValue: dateTimeMask,
start: null,
startDate: null,
startTime: null,
tooltipValue: dateTimeMask,
};

onClear(returnValue);
};

// Close tooltip if dropdown was closed by click outside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9730,6 +9730,7 @@ Map {
"menuOffset": undefined,
"onApply": null,
"onCancel": null,
"onClear": null,
"presets": Array [
Object {
"id": "item-01",
Expand Down Expand Up @@ -10162,6 +10163,9 @@ Map {
"onCancel": Object {
"type": "func",
},
"onClear": Object {
"type": "func",
},
"presets": Object {
"args": Array [
Object {
Expand Down