[fix] handle null value in date filter (#11655)

This commit is contained in:
Grace Guo
2020-11-11 09:32:26 -08:00
committed by GitHub
parent 77dff0e4e0
commit a9f9c4bbd5
2 changed files with 15 additions and 2 deletions

View File

@@ -81,6 +81,19 @@ describe('DateFilterControl', () => {
expect(close).toBeCalled();
});
it('should handle null value', () => {
const open = jest.fn();
const close = jest.fn();
const props = {
...defaultProps,
value: null,
onOpenDateFilterControl: open,
onCloseDateFilterControl: close,
};
expect(mount(<DateFilterControl {...props} />)).toExist();
});
it('renders two tabs in popover', () => {
const popoverContent = wrapper.find(Popover).first().props().content;
const popoverContentWrapper = mount(popoverContent);

View File

@@ -236,11 +236,11 @@ class DateFilterControl extends React.Component {
};
const { value } = props;
if (value.indexOf(SEPARATOR) >= 0) {
if (value && value.indexOf(SEPARATOR) >= 0) {
this.state = { ...this.state, ...getStateFromSeparator(value) };
} else if (COMMON_TIME_FRAMES.indexOf(value) >= 0) {
this.state = { ...this.state, ...getStateFromCommonTimeFrame(value) };
} else {
} else if (value) {
this.state = { ...this.state, ...getStateFromCustomRange(value) };
}