mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Lens] Fix infinite loop when loading rejected data view (#113375)
* [Lens] Fix infinite loop when loading rejected index pattern * Update x-pack/plugins/lens/public/app_plugin/app.test.tsx
This commit is contained in:
parent
c8223bf4f6
commit
23e55b3270
2 changed files with 31 additions and 5 deletions
|
@ -336,7 +336,18 @@ describe('Lens App', () => {
|
|||
{}
|
||||
);
|
||||
});
|
||||
|
||||
it('handles rejected index pattern', async () => {
|
||||
const customServices = makeDefaultServices(sessionIdSubject);
|
||||
customServices.data.indexPatterns.get = jest
|
||||
.fn()
|
||||
.mockImplementation((id) => Promise.reject({ reason: 'Could not locate that data view' }));
|
||||
const customProps = makeDefaultProps();
|
||||
const { services } = await mountWith({ props: customProps, services: customServices });
|
||||
expect(services.navigation.ui.TopNavMenu).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ indexPatterns: [] }),
|
||||
{}
|
||||
);
|
||||
});
|
||||
describe('save buttons', () => {
|
||||
interface SaveProps {
|
||||
newCopyOnSave: boolean;
|
||||
|
|
|
@ -169,6 +169,7 @@ export const LensTopNavMenu = ({
|
|||
);
|
||||
|
||||
const [indexPatterns, setIndexPatterns] = useState<IndexPattern[]>([]);
|
||||
const [rejectedIndexPatterns, setRejectedIndexPatterns] = useState<string[]>([]);
|
||||
|
||||
const {
|
||||
isSaveable,
|
||||
|
@ -200,17 +201,31 @@ export const LensTopNavMenu = ({
|
|||
datasourceStates,
|
||||
});
|
||||
const hasIndexPatternsChanged =
|
||||
indexPatterns.length !== indexPatternIds.length ||
|
||||
indexPatternIds.some((id) => !indexPatterns.find((indexPattern) => indexPattern.id === id));
|
||||
indexPatterns.length + rejectedIndexPatterns.length !== indexPatternIds.length ||
|
||||
indexPatternIds.some(
|
||||
(id) =>
|
||||
![...indexPatterns.map((ip) => ip.id), ...rejectedIndexPatterns].find(
|
||||
(loadedId) => loadedId === id
|
||||
)
|
||||
);
|
||||
|
||||
// Update the cached index patterns if the user made a change to any of them
|
||||
if (hasIndexPatternsChanged) {
|
||||
getIndexPatternsObjects(indexPatternIds, data.indexPatterns).then(
|
||||
({ indexPatterns: indexPatternObjects }) => {
|
||||
({ indexPatterns: indexPatternObjects, rejectedIds }) => {
|
||||
setIndexPatterns(indexPatternObjects);
|
||||
setRejectedIndexPatterns(rejectedIds);
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [datasourceStates, activeDatasourceId, data.indexPatterns, datasourceMap, indexPatterns]);
|
||||
}, [
|
||||
datasourceStates,
|
||||
activeDatasourceId,
|
||||
rejectedIndexPatterns,
|
||||
datasourceMap,
|
||||
indexPatterns,
|
||||
data.indexPatterns,
|
||||
]);
|
||||
|
||||
const { TopNavMenu } = navigation.ui;
|
||||
const { from, to } = data.query.timefilter.timefilter.getTime();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue