Skip to content

Commit

Permalink
[dashboard] fix Upgraded dashboard with image embeddable shows 'unsav…
Browse files Browse the repository at this point in the history
…ed changes' badge when opening editor (#183539)

Fixes #183524

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
nreese and kibanamachine committed May 15, 2024
1 parent 8e91181 commit 076e32d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { SerializedEvent } from '@kbn/ui-actions-enhanced-plugin/common/types';
import { getDynamicActionsState } from './get_dynamic_actions_state';

describe('getDynamicActionsState', () => {
test('should return empty state when enhancements is undefined', () => {
expect(getDynamicActionsState()).toEqual({ dynamicActions: { events: [] } });
});

test('should return empty state when enhancements is empty object', () => {
expect(getDynamicActionsState({})).toEqual({ dynamicActions: { events: [] } });
});

test('should return empty state when enhancements.dynamicActions is undefined', () => {
expect(getDynamicActionsState({ dynamicActions: undefined })).toEqual({
dynamicActions: { events: [] },
});
});

test('should return empty state when enhancements.dynamicActions is empty object', () => {
expect(getDynamicActionsState({ dynamicActions: {} })).toEqual({
dynamicActions: { events: [] },
});
});

test('should return state when enhancements.dynamicActions is provided', () => {
expect(
getDynamicActionsState({ dynamicActions: { events: [{} as unknown as SerializedEvent] } })
).toEqual({ dynamicActions: { events: [{}] } });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 type { DynamicActionsState } from '@kbn/ui-actions-enhanced-plugin/public';

export function getDynamicActionsState(enhancements?: {
dynamicActions?: Partial<DynamicActionsState>;
}) {
return {
dynamicActions: {
events: [],
...(enhancements?.dynamicActions ?? {}),
},
};
}
5 changes: 3 additions & 2 deletions x-pack/plugins/embeddable_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from './embeddables/dynamic_action_storage';
import { HasDynamicActions } from './embeddables/interfaces/has_dynamic_actions';
import { EnhancedEmbeddable } from './types';
import { getDynamicActionsState } from './get_dynamic_actions_state';

export interface SetupDependencies {
embeddable: EmbeddableSetup;
Expand Down Expand Up @@ -148,7 +149,7 @@ export class EmbeddableEnhancedPlugin
startDynamicActions: () => { stopDynamicActions: () => void };
} {
const dynamicActionsState$ = new BehaviorSubject<DynamicActionsSerializedState['enhancements']>(
{ dynamicActions: { events: [] }, ...(state.enhancements ?? {}) }
getDynamicActionsState(state.enhancements)
);
const api: DynamicActionStorageApi = {
dynamicActionsState$,
Expand All @@ -173,7 +174,7 @@ export class EmbeddableEnhancedPlugin
dynamicActionsState$,
api.setDynamicActions,
(a, b) => {
return deepEqual(a, b);
return deepEqual(getDynamicActionsState(a), getDynamicActionsState(b));
},
],
},
Expand Down

0 comments on commit 076e32d

Please sign in to comment.