mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Handle merge conflicts with 6.2 backport (#17159)
This commit is contained in:
parent
2582ab6060
commit
5fc4fc1b69
2 changed files with 61 additions and 7 deletions
|
@ -9,7 +9,13 @@ jest.mock('../components/status_message', () => ({ StatusMessage: 'StatusMessage
|
|||
jest.mock('../components/header', () => ({ Header: 'Header' }));
|
||||
jest.mock('../../../lib/create_reasonable_wait', () => ({ createReasonableWait: fn => fn() }));
|
||||
jest.mock('../../../lib/get_indices', () => ({
|
||||
getIndices: () => {
|
||||
getIndices: (service, query) => {
|
||||
if (query.startsWith('e')) {
|
||||
return [
|
||||
{ name: 'es' },
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
{ name: 'kibana' },
|
||||
];
|
||||
|
@ -133,4 +139,35 @@ describe('StepIndexPattern', () => {
|
|||
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('ensures the response of the latest request is persisted', async () => {
|
||||
const component = shallow(
|
||||
<StepIndexPattern
|
||||
allIndices={allIndices}
|
||||
isIncludingSystemIndices={false}
|
||||
esService={esService}
|
||||
goToNextStep={goToNextStep}
|
||||
initialQuery="k"
|
||||
/>
|
||||
);
|
||||
|
||||
const instance = component.instance();
|
||||
instance.onQueryChanged({ target: { value: 'e' } });
|
||||
instance.lastQuery = 'k';
|
||||
await new Promise(resolve => process.nextTick(resolve));
|
||||
|
||||
// Honesty, the state would match the result of the `k` query but
|
||||
// it's hard to mock this in tests but if remove our fix
|
||||
// (the early return if the queries do not match) then this
|
||||
// equals [{name: 'es'}]
|
||||
expect(component.state('exactMatchedIndices')).toEqual([{ name: 'kibana' }]);
|
||||
|
||||
// Ensure it works in the other code flow too (the other early return)
|
||||
|
||||
// Provide `es` so we do not auto append * and enter our other code flow
|
||||
instance.onQueryChanged({ target: { value: 'es' } });
|
||||
instance.lastQuery = 'k';
|
||||
await new Promise(resolve => process.nextTick(resolve));
|
||||
expect(component.state('exactMatchedIndices')).toEqual([{ name: 'kibana' }]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -41,10 +41,13 @@ export class StepIndexPattern extends Component {
|
|||
appendedWildcard: false,
|
||||
showingIndexPatternQueryErrors: false,
|
||||
};
|
||||
|
||||
this.lastQuery = null;
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
if (this.state.query) {
|
||||
this.lastQuery = this.state.query;
|
||||
this.fetchIndices(this.state.query);
|
||||
}
|
||||
}
|
||||
|
@ -55,16 +58,29 @@ export class StepIndexPattern extends Component {
|
|||
this.setState({ isLoadingIndices: true, indexPatternExists: false });
|
||||
if (query.endsWith('*')) {
|
||||
const exactMatchedIndices = await getIndices(esService, query, MAX_SEARCH_SIZE);
|
||||
createReasonableWait(() => this.setState({ exactMatchedIndices, isLoadingIndices: false }));
|
||||
createReasonableWait(() => {
|
||||
// If the search changed, discard this state
|
||||
if (query !== this.lastQuery) {
|
||||
return;
|
||||
}
|
||||
this.setState({ exactMatchedIndices, isLoadingIndices: false });
|
||||
});
|
||||
}
|
||||
else {
|
||||
const partialMatchedIndices = await getIndices(esService, `${query}*`, MAX_SEARCH_SIZE);
|
||||
const exactMatchedIndices = await getIndices(esService, query, MAX_SEARCH_SIZE);
|
||||
createReasonableWait(() => this.setState({
|
||||
partialMatchedIndices,
|
||||
exactMatchedIndices,
|
||||
isLoadingIndices: false
|
||||
}));
|
||||
createReasonableWait(() => {
|
||||
// If the search changed, discard this state
|
||||
if (query !== this.lastQuery) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
partialMatchedIndices,
|
||||
exactMatchedIndices,
|
||||
isLoadingIndices: false
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +101,7 @@ export class StepIndexPattern extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
this.lastQuery = query;
|
||||
this.setState({ query, showingIndexPatternQueryErrors: !!query.length });
|
||||
this.fetchIndices(query);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue