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 for Vis Editor] Revert setting time field to empty string when it's undefined #58873

Merged
merged 7 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -292,4 +292,28 @@ describe('StepTimeField', () => {
error: 'foobar',
});
});

it('should call createIndexPattern with undefined time field when no time filter chosen', async () => {
const createIndexPattern = jest.fn();

const component = shallowWithI18nProvider(
<StepTimeField
indexPattern="ki*"
indexPatternsService={indexPatternsService}
goToPreviousStep={noop}
createIndexPattern={createIndexPattern}
indexPatternCreationType={mockIndexPatternCreationType}
/>
);

(component.instance() as StepTimeField).onTimeFieldChanged(({
target: { value: undefined },
} as unknown) as React.ChangeEvent<HTMLSelectElement>);
component.update();

await (component.instance() as StepTimeField).createIndexPattern();
component.update();

expect(createIndexPattern).toHaveBeenCalledWith(undefined, '');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface StepTimeFieldProps {
indexPattern: string;
indexPatternsService: DataPublicPluginStart['indexPatterns'];
goToPreviousStep: () => void;
createIndexPattern: (selectedTimeField: string, indexPatternId: string) => void;
createIndexPattern: (selectedTimeField: string | undefined, indexPatternId: string) => void;
indexPatternCreationType: IndexPatternCreationConfig;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ export class StepTimeField extends Component<StepTimeFieldProps, StepTimeFieldSt
const { selectedTimeField, indexPatternId } = this.state;
this.setState({ isCreating: true });
try {
await createIndexPattern(selectedTimeField || '', indexPatternId);
await createIndexPattern(selectedTimeField, indexPatternId);
} catch (error) {
if (!this.mounted) return;
this.setState({
Expand Down