Skip to content

Commit

Permalink
[Embeddable] Always send value input from edit panel action (#155283)
Browse files Browse the repository at this point in the history
ensures that the by value input is passed into the editors regardless of whether the panel is by value or by reference.
  • Loading branch information
ThomThomson authored Apr 21, 2023
1 parent f0106b1 commit 8039fec
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EditPanelAction } from './edit_panel_action';
import { Embeddable, EmbeddableInput, SavedObjectEmbeddableInput } from '../embeddables';
import { Embeddable, EmbeddableInput } from '../embeddables';
import { ViewMode } from '../types';
import { ContactCardEmbeddable } from '../test_samples';
import { embeddablePluginMock } from '../../mocks';
Expand Down Expand Up @@ -42,7 +42,7 @@ test('is compatible when edit url is available, in edit mode and editable', asyn
).toBe(true);
});

test('redirects to app using state transfer with by value mode', async () => {
test('redirects to app using state transfer', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const testPath = '/test-path';
const action = new EditPanelAction(
Expand Down Expand Up @@ -78,32 +78,6 @@ test('redirects to app using state transfer with by value mode', async () => {
});
});

test('redirects to app using state transfer without by value mode', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const testPath = '/test-path';
const action = new EditPanelAction(
getFactory,
applicationMock,
stateTransferMock,
() => testPath
);
const embeddable = new EditableEmbeddable(
{ id: '123', viewMode: ViewMode.EDIT, savedObjectId: '1234' } as SavedObjectEmbeddableInput,
true
);
embeddable.getOutput = jest.fn(() => ({ editApp: 'ultraVisualize', editPath: '/123' }));
await action.execute({ embeddable });
expect(stateTransferMock.navigateToEditor).toHaveBeenCalledWith('ultraVisualize', {
path: '/123',
state: {
originatingApp: 'superCoolCurrentApp',
embeddableId: '123',
valueInput: undefined,
originatingPath: testPath,
},
});
});

test('getHref returns the edit urls', async () => {
const action = new EditPanelAction(getFactory, applicationMock, stateTransferMock);
expect(action.getHref).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
IEmbeddable,
EmbeddableEditorState,
EmbeddableStateTransfer,
SavedObjectEmbeddableInput,
EmbeddableInput,
Container,
} from '../..';
Expand Down Expand Up @@ -124,13 +123,11 @@ export class EditPanelAction implements Action<ActionContext> {

if (app && path) {
if (this.currentAppId) {
const byValueMode = !(embeddable.getInput() as SavedObjectEmbeddableInput).savedObjectId;

const originatingPath = this.getOriginatingPath?.();

const state: EmbeddableEditorState = {
originatingApp: this.currentAppId,
valueInput: byValueMode ? this.getExplicitInput({ embeddable }) : undefined,
valueInput: this.getExplicitInput({ embeddable }),
embeddableId: embeddable.id,
searchSessionId: embeddable.getInput().searchSessionId,
originatingPath,
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/maps/public/render_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export async function renderApp(
mapEmbeddableInput = {
savedObjectId: routeProps.match.params.savedMapId,
} as MapByReferenceInput;
}
if (valueInput) {
} else if (valueInput) {
mapEmbeddableInput = valueInput as MapByValueInput;
}

Expand Down

0 comments on commit 8039fec

Please sign in to comment.