-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[TSVB] Fix missing unsaved changes on linked visualizations #228685
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
Changes from all commits
2eb9972
bf7fe07
83460ad
5e03366
93d6eda
f23ffb3
b55564a
4e7a613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @markov00 The Visualize Embeddable does not use |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,9 @@ import { | |
| } from '@kbn/presentation-publishing'; | ||
| import { MaybePromise } from '@kbn/utility-types'; | ||
| import { Observable, combineLatestWith, debounceTime, map, of } from 'rxjs'; | ||
| import { isEqual, sortBy } from 'lodash'; | ||
| import { apiHasLastSavedChildState } from '../last_saved_child_state'; | ||
| import { PresentationContainer } from '../presentation_container'; | ||
|
|
||
| const UNSAVED_CHANGES_DEBOUNCE = 100; | ||
|
|
||
| export const initializeUnsavedChanges = <StateType extends object = object>({ | ||
|
|
@@ -29,6 +29,7 @@ export const initializeUnsavedChanges = <StateType extends object = object>({ | |
| defaultState, | ||
| serializeState, | ||
| anyStateChange$, | ||
| checkRefEquality, | ||
| }: { | ||
| uuid: string; | ||
| parentApi: unknown; | ||
|
|
@@ -37,6 +38,7 @@ export const initializeUnsavedChanges = <StateType extends object = object>({ | |
| getComparators: () => StateComparators<StateType>; | ||
| defaultState?: Partial<StateType>; | ||
| onReset: (lastSavedPanelState?: SerializedPanelState<StateType>) => MaybePromise<void>; | ||
| checkRefEquality?: boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason checking ref equality on links causes an erroneous diff where the Not sure why this is but also to err on the side of caution, we made this ref equality check opt-in. |
||
| }): PublishesUnsavedChanges => { | ||
| if (!apiHasLastSavedChildState<StateType>(parentApi)) { | ||
| return { | ||
|
|
@@ -46,16 +48,25 @@ export const initializeUnsavedChanges = <StateType extends object = object>({ | |
| } | ||
|
|
||
| const hasUnsavedChanges$ = anyStateChange$.pipe( | ||
| combineLatestWith( | ||
| parentApi.lastSavedStateForChild$(uuid).pipe(map((panelState) => panelState?.rawState)) | ||
| ), | ||
| combineLatestWith(parentApi.lastSavedStateForChild$(uuid)), | ||
| debounceTime(UNSAVED_CHANGES_DEBOUNCE), | ||
| map(([, lastSavedState]) => { | ||
| const currentState = serializeState().rawState; | ||
| const currentState = serializeState(); | ||
|
|
||
| // check ref equality | ||
| if (checkRefEquality) { | ||
| const lastSavedRefs = sortBy(lastSavedState?.references ?? [], 'id'); | ||
| const currentRefs = sortBy(currentState?.references ?? [], 'id'); | ||
| const equalRefs = isEqual(lastSavedRefs, currentRefs); | ||
|
|
||
| if (!equalRefs) return true; | ||
| } | ||
|
|
||
| // check state equality | ||
| return !areComparatorsEqual( | ||
| getComparators(), | ||
| lastSavedState, | ||
| currentState, | ||
| lastSavedState?.rawState, | ||
| currentState.rawState, | ||
| defaultState, | ||
| (key: string) => { | ||
| const childApi = (parentApi as Partial<PresentationContainer>).children$?.getValue()[ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3198,6 +3198,11 @@ | |
| "type": "visualization", | ||
| "id": "50643b60-3dd3-11e8-b2b9-5d5dc1715159" | ||
| }, | ||
| { | ||
| "name":"ffc13252-56b4-4e3f-847e-61373fa0be86:kibanaSavedObjectMeta.searchSourceJSON.index", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixture update LGTM. |
||
| "type":"index-pattern", | ||
| "id":"a0f483a0-3dc9-11e8-8660-4d65aa086b3c" | ||
| }, | ||
| { | ||
| "name": "controlGroup_41827e70-5285-4d44-8375-4c498449b9a7:optionsListControlDataView", | ||
| "type": "index-pattern", | ||
|
|
@@ -3317,4 +3322,4 @@ | |
| "managed": false, | ||
| "coreMigrationVersion": "8.8.0", | ||
| "typeMigrationVersion": "10.2.0" | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.