-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Lens] Infinite reference accumulation #245317
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2fab40
fix: ES|QL infinite references
nickofthyme 8a12ff2
fix: use `attributes.references` as source refs, only update from das…
nickofthyme 66aa602
Merge branch 'main' into fix-infinite-refs
nickofthyme e50fc31
Merge branch 'main' into fix-infinite-refs
nickofthyme 2f4ebd2
chore: move name override to lookup logic
nickofthyme 19547a8
Merge branch 'main' into fix-infinite-refs
nickofthyme c29adec
Merge branch 'main' into fix-infinite-refs
nickofthyme c70799e
Merge branch 'main' into fix-infinite-refs
nickofthyme c7201fc
chore: replace dashboard naming logic with panel refs
nickofthyme aaca1b4
Merge branch 'main' into fix-infinite-refs
nickofthyme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
x-pack/platform/plugins/shared/lens/common/references/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { v4 as uuidv4 } from 'uuid'; | ||
|
|
||
| import type { Reference } from '@kbn/content-management-utils'; | ||
|
|
||
| import type { LensSerializedState } from '../../public'; | ||
| import { extractLensReferences, injectLensReferences } from '.'; | ||
|
|
||
| /** | ||
| * A typical lens reference (i.e. `<ref-type>-<ref-id>`) | ||
| */ | ||
| const getMockPanelReference = (): Reference => ({ | ||
| type: 'some-panel-ref', | ||
| id: uuidv4(), | ||
| name: `lens-ref-type-${uuidv4()}`, | ||
| }); | ||
|
|
||
| const getMockLensState = ( | ||
| references: Reference[], | ||
| overrides: Partial<LensSerializedState> = {} | ||
| ): LensSerializedState => | ||
| ({ | ||
| attributes: { | ||
| references, | ||
| }, | ||
| ...overrides, | ||
| } as LensSerializedState); | ||
|
|
||
| describe('references', () => { | ||
| describe('injectLensReferences', () => { | ||
| it('should return by-ref state', () => { | ||
| const state = getMockLensState([getMockPanelReference()], { savedObjectId: uuidv4() }); | ||
| const references = [getMockPanelReference()]; | ||
| const injected = injectLensReferences(state, references); | ||
|
|
||
| expect(injected).toEqual(state); | ||
| }); | ||
|
|
||
| it('should not inject erroneous panel references from dashboard', () => { | ||
| const dashboardReferences = [getMockPanelReference(), getMockPanelReference()]; | ||
| const state = getMockLensState([]); | ||
| const injected = injectLensReferences(state, dashboardReferences); | ||
|
|
||
| expect(injected!.attributes!.references).toEqual([]); | ||
| }); | ||
|
|
||
| it('should fallback to attribute references when dashboard references are empty/missing', () => { | ||
| const panelReferences = [getMockPanelReference(), getMockPanelReference()]; | ||
| const state = getMockLensState(panelReferences); | ||
| const injected = injectLensReferences(state, []); | ||
|
|
||
| expect(injected!.attributes!.references).toEqual(panelReferences); | ||
| }); | ||
|
|
||
| it('should update panel references with dashboard reference id', () => { | ||
| const dashboardReference = getMockPanelReference(); | ||
| const panelReference: Reference = { | ||
| ...dashboardReference, | ||
| id: 'old-lens-reference-id', | ||
| }; | ||
| const state = getMockLensState([panelReference]); | ||
| const injected = injectLensReferences(state, [dashboardReference]); | ||
|
|
||
| expect(injected!.attributes!.references).toEqual([dashboardReference]); | ||
| }); | ||
|
|
||
| it('should not update reference for different reference type from dashboard', () => { | ||
| const dashboardReference = getMockPanelReference(); | ||
| const panelReference: Reference = { | ||
| ...dashboardReference, | ||
| id: 'old-lens-reference-id', | ||
| type: 'wrong-type', | ||
| }; | ||
| const state = getMockLensState([panelReference]); | ||
| const injected = injectLensReferences(state, [dashboardReference]); | ||
|
|
||
| expect(injected!.attributes!.references).toEqual([panelReference]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractLensReferences', () => { | ||
| it('should extract references from state attributes', () => { | ||
| const references = [getMockPanelReference(), getMockPanelReference()]; | ||
| const state = getMockLensState(references); | ||
| const extracted = extractLensReferences(state); | ||
|
|
||
| expect(extracted.references).toEqual(references); | ||
| expect(extracted.state).toEqual(state); | ||
| }); | ||
|
|
||
| it('should extract references from state deprecated state', () => { | ||
| const references = [getMockPanelReference(), getMockPanelReference()]; | ||
| const state = getMockLensState([], { | ||
| references, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| attributes: {} as any, | ||
| }); | ||
| const extracted = extractLensReferences(state); | ||
|
|
||
| expect(extracted.references).toEqual(references); | ||
| expect(extracted.state).toEqual(state); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.