Skip to content
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

[Time to Visualize] Lens By Value With AttributeService #77561

Merged
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
297dba0
Made lens work with the attribute service copied from #68719
ThomThomson Jun 25, 2020
168825a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 25, 2020
0039a97
Editing lens by value now works.
ThomThomson Jun 26, 2020
8ec8020
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 26, 2020
681625f
Allow by value lens embeddable to be made by reference via the save a…
ThomThomson Jun 26, 2020
473a052
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 29, 2020
3ee8263
fixed up some jest tests
ThomThomson Jun 29, 2020
a34d585
functional and jest test fixes
ThomThomson Jun 30, 2020
b7ff957
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 30, 2020
5d05ac9
fix for visualize by value
ThomThomson Jun 30, 2020
adc1298
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 7, 2020
a3d0adc
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 13, 2020
3ecb3d9
Restructured adding and editing to minimize deletion of embeddables a…
ThomThomson Jul 14, 2020
72a068a
eslint changes
ThomThomson Jul 14, 2020
d1ab683
cleanup continued...
ThomThomson Jul 15, 2020
9cb9a7c
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 15, 2020
a0fffd0
Finished cleanup - separated embeddableId and savedObjectId in lens t…
ThomThomson Jul 17, 2020
4d64d5e
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 17, 2020
9e5f7a9
Test fixes
ThomThomson Jul 17, 2020
580fbba
More test fixes, started on feature flag creation
ThomThomson Jul 17, 2020
df5fad0
Finished feature flag
ThomThomson Jul 17, 2020
c6d87c7
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 20, 2020
cd61dfc
Updated jest test - because the newly created prop is now set correctly.
ThomThomson Jul 20, 2020
7f86d23
remove byValueMode from editorState in favor of using the embeddableI…
ThomThomson Jul 22, 2020
43657f9
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 22, 2020
888ca49
rename edit mode for clarity. Update ternary
ThomThomson Jul 22, 2020
b9d9c5c
Type fixes
ThomThomson Jul 23, 2020
c823217
Jest fix
ThomThomson Jul 23, 2020
87a780c
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 23, 2020
d3d2cfd
merge fix
ThomThomson Jul 23, 2020
b793ca3
Merge branch 'master' into feature/lensByValue
elasticmachine Jul 27, 2020
ef65220
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 29, 2020
ee625ec
merge fix
ThomThomson Jul 29, 2020
4e39564
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 30, 2020
ed461d3
cleaned up visualize state transfer package, set new lens flow defaul…
ThomThomson Jul 30, 2020
c9878c5
cleaned up visualize state transfer package, set new lens flow defaul…
ThomThomson Jul 30, 2020
cb72a3e
Merge branch 'feature/lensByValue' of github.com:ThomThomson/kibana i…
ThomThomson Jul 30, 2020
a5910f2
Added an interface for all by value or by reference embeddables to in…
ThomThomson Jul 31, 2020
ac5c91a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 31, 2020
068ebaf
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 4, 2020
c1435e0
Removed lens by value config in favor of the dashboard-wide config fr…
ThomThomson Aug 4, 2020
ac94aec
removed unused config related code from lens
ThomThomson Aug 5, 2020
642eea8
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 6, 2020
9af2c06
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 12, 2020
8b43747
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 17, 2020
df876af
Merge continued...
ThomThomson Aug 17, 2020
aeb25ee
Merge continued...
ThomThomson Aug 17, 2020
6fc1f00
Maps Update
ThomThomson Aug 17, 2020
9598011
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 18, 2020
10d98e3
Finished merge with visualize editor
ThomThomson Aug 18, 2020
e85caeb
Merge branch 'master' into feature/lensByValue
elasticmachine Aug 20, 2020
2ef26c6
Merge branch 'feature/lensByValue' of github.com:ThomThomson/kibana i…
ThomThomson Aug 20, 2020
ff13e40
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 20, 2020
3411c36
Added custom save method to attribute service to allow lens specific …
ThomThomson Aug 20, 2020
1d5b123
Small fix for lens embeddables on canvas, made cancel button show up …
ThomThomson Aug 20, 2020
f497244
Test fix
ThomThomson Aug 20, 2020
5b6d397
Removed accidental duplication of ref_or_val_embeddable. Added tests …
ThomThomson Aug 21, 2020
d345571
M o n s t e r M e r g e branch 'master' of github.com:elastic/kibana…
ThomThomson Aug 21, 2020
0dee8a7
Made attribute service unwrap references as well
ThomThomson Aug 22, 2020
12b9aa4
type and jest fix
ThomThomson Aug 22, 2020
e3dc91a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 24, 2020
29ae393
Simplified and separated redirectTo method, made dashboard merge inco…
ThomThomson Aug 24, 2020
719d67c
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 24, 2020
3470c63
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 25, 2020
566500c
changed feature flag config to match dashboard
ThomThomson Aug 25, 2020
8796ab0
cleaned up types after 75560
ThomThomson Aug 25, 2020
216fd7f
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 25, 2020
d0e3fd8
Type cleanup continued
ThomThomson Aug 25, 2020
6f28a7f
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 31, 2020
cf74955
update eslint
ThomThomson Aug 31, 2020
19c3c96
Placed the same instance of AttributeService in lens mounter and embe…
ThomThomson Sep 2, 2020
4291689
Exploring lens.... for a better future...
ThomThomson Sep 3, 2020
a517986
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 4, 2020
555ac5f
Continue updating lens
ThomThomson Sep 4, 2020
1d9954b
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 8, 2020
e0feaf9
Got editor working properly in by reference mode
ThomThomson Sep 8, 2020
23976f5
Editor works properly by value and by reference, including switching …
ThomThomson Sep 9, 2020
5544727
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 14, 2020
b7aafb7
reworking app.test
ThomThomson Sep 15, 2020
fbc3eee
Cleanup and rework lens app tests
ThomThomson Sep 15, 2020
3da65f7
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 15, 2020
b2c03ea
Fixed set state when redirecting to
ThomThomson Sep 15, 2020
f0260c5
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 16, 2020
e51aa29
Stopped exporting mocks via dashboard/public/index.ts, removed unused…
ThomThomson Sep 16, 2020
ea83530
added setHeaderActionMenu to app.tsx
ThomThomson Sep 16, 2020
7bc8e1b
removed the mock export from attribute_service/index as well
ThomThomson Sep 16, 2020
dfd7b4a
removed extra copy from dashboard_app_controller. Added better option…
ThomThomson Sep 16, 2020
6bc45fb
run save -> save to library is now required.
ThomThomson Sep 16, 2020
dbca606
removed set state before redirectTo in order to avoid a double-load i…
ThomThomson Sep 16, 2020
cbdea3b
removed validateOnAppLeave in favor of resetting the onAppLeave callb…
ThomThomson Sep 16, 2020
9ecb01f
type fix
ThomThomson Sep 16, 2020
0cd183b
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 17, 2020
14ef72b
lens app menu showSaveAndReturn changes when allowByValueEmbeddables…
ThomThomson Sep 17, 2020
38225f3
Added new test for edit by reference mode expected menu items.
ThomThomson Sep 17, 2020
d569181
used initialized boolean to stop by value lens embeddables from flash…
ThomThomson Sep 17, 2020
921b46a
Implemented review suggestions
ThomThomson Sep 17, 2020
98d2837
Made cancel button show up any time originatingApp is set.
ThomThomson Sep 18, 2020
73a02e8
Fixed lens embeddable on canvas when feature flag is on
ThomThomson Sep 18, 2020
20aa18b
Deleted attributes from original input in getInputAsRefType to avoid …
ThomThomson Sep 18, 2020
3a25f1f
aria labels for lens topNavMenu items
ThomThomson Sep 18, 2020
c4fa61a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 21, 2020
fdd75b7
Review changes
ThomThomson Sep 21, 2020
d08ff4e
Changed copy on save button and save modal return switch for edits in…
ThomThomson Sep 21, 2020
6a1c208
uncommit config flag... again
ThomThomson Sep 22, 2020
2f9c843
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 22, 2020
82e89a8
workaround for serializing filters
ThomThomson Sep 22, 2020
a437335
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Sep 23, 2020
27ce740
Merge branch 'master' into feature/lensByValueAttributeServiceOnly
elasticmachine Sep 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class LibraryNotificationAction implements ActionByType<typeof ACTION_LIB

public isCompatible = async ({ embeddable }: LibraryNotificationActionContext) => {
return (
embeddable.getRoot() &&
embeddable.getRoot().isContainer &&
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
embeddable.getInput()?.viewMode !== ViewMode.VIEW &&
isReferenceOrValueEmbeddable(embeddable) &&
embeddable.inputIsRefType(embeddable.getInput())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import {
ViewMode,
ContainerOutput,
EmbeddableInput,
SavedObjectEmbeddableInput,
} from '../../../embeddable/public';
import { NavAction, SavedDashboardPanel } from '../types';

Expand Down Expand Up @@ -178,7 +177,7 @@ export class DashboardAppController {
chrome.docTitle.change(dash.title);
}

const incomingEmbeddable = embeddable
let incomingEmbeddable = embeddable
.getStateTransfer(scopedHistory())
.getIncomingEmbeddablePackage();

Expand Down Expand Up @@ -344,6 +343,22 @@ export class DashboardAppController {
dashboardStateManager.getPanels().forEach((panel: SavedDashboardPanel) => {
embeddablesMap[panel.panelIndex] = convertSavedDashboardPanelToPanelState(panel);
});

// If the incoming embeddable state's id already exists in the embeddables map, replace the input, retaining the existing gridData for that panel.
if (incomingEmbeddable?.embeddableId && embeddablesMap[incomingEmbeddable.embeddableId]) {
const originalPanelState = embeddablesMap[incomingEmbeddable.embeddableId];
embeddablesMap[incomingEmbeddable.embeddableId] = {
gridData: originalPanelState.gridData,
type: incomingEmbeddable.type,
explicitInput: {
...originalPanelState.explicitInput,
...incomingEmbeddable.input,
id: incomingEmbeddable.embeddableId,
},
};
incomingEmbeddable = undefined;
}

let expandedPanelId;
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
expandedPanelId = dashboardContainer.getInput().expandedPanelId;
Expand Down Expand Up @@ -482,32 +497,16 @@ export class DashboardAppController {
refreshDashboardContainer();
});

if (incomingEmbeddable) {
if ('id' in incomingEmbeddable) {
container.addOrUpdateEmbeddable<SavedObjectEmbeddableInput>(
incomingEmbeddable.type,
{
savedObjectId: incomingEmbeddable.id,
}
);
} else if ('input' in incomingEmbeddable) {
const input = incomingEmbeddable.input;
// @ts-expect-error
delete input.id;
const explicitInput = {
savedVis: input,
};
const embeddableId =
'embeddableId' in incomingEmbeddable
? incomingEmbeddable.embeddableId
: undefined;
container.addOrUpdateEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
// This ugly solution is temporary - https://github.com/elastic/kibana/pull/70272 fixes this whole section
(explicitInput as unknown) as EmbeddableInput,
embeddableId
);
}
// If the incomingEmbeddable does not yet exist in the panels listing, create a new panel using the container's addEmbeddable method.
if (
incomingEmbeddable &&
(!incomingEmbeddable.embeddableId ||
!container.getInput().panels[incomingEmbeddable.embeddableId])
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
) {
container.addNewEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
incomingEmbeddable.input
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { ATTRIBUTE_SERVICE_KEY } from './attribute_service';
import { mockAttributeService } from './attribute_service_mock';
import { mockAttributeService } from './attribute_service.mock';
import { coreMock } from '../../../../core/public/mocks';

interface TestAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,8 @@ export class AttributeService<
};

public getExplicitInputFromEmbeddable(embeddable: IEmbeddable): ValType | RefType {
return embeddable.getRoot() &&
(embeddable.getRoot() as Container).getInput().panels[embeddable.id].explicitInput
? ((embeddable.getRoot() as Container).getInput().panels[embeddable.id].explicitInput as
| ValType
| RefType)
: (embeddable.getInput() as ValType | RefType);
return ((embeddable.getRoot() as Container)?.getInput()?.panels?.[embeddable.id]
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
?.explicitInput ?? embeddable.getInput()) as ValType | RefType;
}

getInputAsValueType = async (input: ValType | RefType): Promise<ValType> => {
Expand Down Expand Up @@ -204,7 +200,14 @@ export class AttributeService<
const newAttributes = { ...input[ATTRIBUTE_SERVICE_KEY] };
newAttributes.title = props.newTitle;
const wrappedInput = (await this.wrapAttributes(newAttributes, true)) as RefType;
resolve(wrappedInput);

// Remove unneeded attributes from the original input.
delete (input as { [ATTRIBUTE_SERVICE_KEY]?: SavedObjectAttributes })[
ATTRIBUTE_SERVICE_KEY
];

// Combine input and wrapped input to preserve any passed in explicit Input.
resolve({ ...input, ...wrappedInput });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to preserve explicit input like panel title or time range. Otherwise it would get lost in translation when going between 'by reference' and 'by value' and back.

return { id: wrappedInput.savedObjectId };
} catch (error) {
reject(error);
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/dashboard/public/attribute_service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './attribute_service';
4 changes: 2 additions & 2 deletions src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export {
} from './application';
export { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';

export { DashboardStart, DashboardUrlGenerator } from './plugin';
export { DashboardStart, DashboardUrlGenerator, DashboardFeatureFlagConfig } from './plugin';
export {
DASHBOARD_APP_URL_GENERATOR,
createDashboardUrlGenerator,
Expand All @@ -40,7 +40,7 @@ export {
export { addEmbeddableToDashboardUrl } from './url_utils/url_helper';
export { SavedObjectDashboard } from './saved_dashboards';
export { SavedDashboardPanel } from './types';
export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './attribute_service/attribute_service';
export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './attribute_service';

export function plugin(initializerContext: PluginInitializerContext) {
return new DashboardPlugin(initializerContext);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dashboard/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { DashboardStart } from './plugin';

export type Start = jest.Mocked<DashboardStart>;
export { mockAttributeService } from './attribute_service/attribute_service.mock';

const createStartContract = (): DashboardStart => {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ declare module '../../share/public' {

export type DashboardUrlGenerator = UrlGeneratorContract<typeof DASHBOARD_APP_URL_GENERATOR>;

interface DashboardFeatureFlagConfig {
export interface DashboardFeatureFlagConfig {
allowByValueEmbeddables: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

test('redirects to app using state transfer', async () => {
test('redirects to app using state transfer with by value mode', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const action = new EditPanelAction(getFactory, applicationMock, stateTransferMock);
const input = { id: '123', viewMode: ViewMode.EDIT };
const embeddable = new EditableEmbeddable(input, true);
const embeddable = new EditableEmbeddable(
({
id: '123',
viewMode: ViewMode.EDIT,
coolInput1: 1,
coolInput2: 2,
} as unknown) as EmbeddableInput,
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: {
id: '123',
viewMode: ViewMode.EDIT,
coolInput1: 1,
coolInput2: 2,
},
},
});
});

test('redirects to app using state transfer without by value mode', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const action = new EditPanelAction(getFactory, applicationMock, stateTransferMock);
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',
byValueMode: true,
embeddableId: '123',
valueInput: input,
valueInput: undefined,
},
});
});
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/embeddable/public/lib/actions/edit_panel_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
EmbeddableEditorState,
EmbeddableStateTransfer,
SavedObjectEmbeddableInput,
EmbeddableInput,
Container,
} from '../..';

export const ACTION_EDIT_PANEL = 'editPanel';
Expand Down Expand Up @@ -118,8 +120,7 @@ export class EditPanelAction implements Action<ActionContext> {
const byValueMode = !(embeddable.getInput() as SavedObjectEmbeddableInput).savedObjectId;
const state: EmbeddableEditorState = {
originatingApp: this.currentAppId,
byValueMode,
valueInput: byValueMode ? embeddable.getInput() : undefined,
valueInput: byValueMode ? this.getExplicitInput({ embeddable }) : undefined,
embeddableId: embeddable.id,
};
return { app, path, state };
Expand All @@ -132,4 +133,11 @@ export class EditPanelAction implements Action<ActionContext> {
const editUrl = embeddable ? embeddable.getOutput().editUrl : undefined;
return editUrl ? editUrl : '';
}

private getExplicitInput({ embeddable }: ActionContext): EmbeddableInput {
return (
(embeddable.getRoot() as Container)?.getInput()?.panels?.[embeddable.id]?.explicitInput ??
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
embeddable.getInput()
);
}
}
2 changes: 1 addition & 1 deletion src/plugins/embeddable/public/lib/containers/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ export abstract class Container<
return {
type: factory.type,
explicitInput: {
id: embeddableId,
...explicitInput,
id: embeddableId,
} as TEmbeddableInput,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,27 @@ describe('embeddable state transfer', () => {

it('can send an outgoing embeddable package state', async () => {
await stateTransfer.navigateToWithEmbeddablePackage(destinationApp, {
state: { type: 'coolestType', id: '150' },
state: { type: 'coolestType', input: { savedObjectId: '150' } },
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
state: { type: 'coolestType', id: '150' },
state: { type: 'coolestType', input: { savedObjectId: '150' } },
});
});

it('can send an outgoing embeddable package state in append mode', async () => {
const historyMock = mockHistoryState({ kibanaIsNowForSports: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
await stateTransfer.navigateToWithEmbeddablePackage(destinationApp, {
state: { type: 'coolestType', id: '150' },
state: { type: 'coolestType', input: { savedObjectId: '150' } },
appendToExistingState: true,
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
path: undefined,
state: { kibanaIsNowForSports: 'extremeSportsKibana', type: 'coolestType', id: '150' },
state: {
kibanaIsNowForSports: 'extremeSportsKibana',
type: 'coolestType',
input: { savedObjectId: '150' },
},
});
});

Expand All @@ -120,10 +124,13 @@ describe('embeddable state transfer', () => {
});

it('can fetch an incoming embeddable package state', async () => {
const historyMock = mockHistoryState({ type: 'skisEmbeddable', id: '123' });
const historyMock = mockHistoryState({
type: 'skisEmbeddable',
input: { savedObjectId: '123' },
});
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
const fetchedState = stateTransfer.getIncomingEmbeddablePackage();
expect(fetchedState).toEqual({ type: 'skisEmbeddable', id: '123' });
expect(fetchedState).toEqual({ type: 'skisEmbeddable', input: { savedObjectId: '123' } });
});

it('returns undefined when embeddable package is not in the right shape', async () => {
Expand All @@ -136,12 +143,12 @@ describe('embeddable state transfer', () => {
it('removes all keys in the keysToRemoveAfterFetch array', async () => {
const historyMock = mockHistoryState({
type: 'skisEmbeddable',
id: '123',
input: { savedObjectId: '123' },
test1: 'test1',
test2: 'test2',
});
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
stateTransfer.getIncomingEmbeddablePackage({ keysToRemoveAfterFetch: ['type', 'id'] });
stateTransfer.getIncomingEmbeddablePackage({ keysToRemoveAfterFetch: ['type', 'input'] });
expect(historyMock.replace).toHaveBeenCalledWith(
expect.objectContaining({ state: { test1: 'test1', test2: 'test2' } })
);
Expand All @@ -150,15 +157,15 @@ describe('embeddable state transfer', () => {
it('leaves state as is when no keysToRemove are supplied', async () => {
const historyMock = mockHistoryState({
type: 'skisEmbeddable',
id: '123',
input: { savedObjectId: '123' },
test1: 'test1',
test2: 'test2',
});
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
stateTransfer.getIncomingEmbeddablePackage();
expect(historyMock.location.state).toEqual({
type: 'skisEmbeddable',
id: '123',
input: { savedObjectId: '123' },
test1: 'test1',
test2: 'test2',
});
Expand Down
Loading