Skip to content

Commit 481bddd

Browse files
committed
Add editApp and editPath to embeddable (#64297)
1 parent 2849095 commit 481bddd

18 files changed

Lines changed: 66 additions & 10 deletions

File tree

src/plugins/dashboard/public/application/embeddable/grid/dashboard_grid.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class DashboardGridUi extends React.Component<DashboardGridProps, State> {
275275
getEmbeddableFactory={this.props.kibana.services.embeddable.getEmbeddableFactory}
276276
getAllEmbeddableFactories={this.props.kibana.services.embeddable.getEmbeddableFactories}
277277
overlays={this.props.kibana.services.overlays}
278+
application={this.props.kibana.services.application}
278279
notifications={this.props.kibana.services.notifications}
279280
inspector={this.props.kibana.services.inspector}
280281
SavedObjectFinder={this.props.kibana.services.SavedObjectFinder}

src/plugins/dashboard/public/application/tests/dashboard_container.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ test('DashboardContainer in edit mode shows edit mode actions', async () => {
8484
getAllEmbeddableFactories={(() => []) as any}
8585
getEmbeddableFactory={(() => null) as any}
8686
notifications={{} as any}
87+
application={{} as any}
8788
overlays={{} as any}
8889
inspector={inspector}
8990
SavedObjectFinder={() => null}

src/plugins/embeddable/public/lib/actions/edit_panel_action.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class EditableEmbeddable extends Embeddable {
4141
}
4242

4343
test('is compatible when edit url is available, in edit mode and editable', async () => {
44-
const action = new EditPanelAction(getFactory);
44+
const action = new EditPanelAction(getFactory, {} as any);
4545
expect(
4646
await action.isCompatible({
4747
embeddable: new EditableEmbeddable({ id: '123', viewMode: ViewMode.EDIT }, true),
@@ -50,7 +50,7 @@ test('is compatible when edit url is available, in edit mode and editable', asyn
5050
});
5151

5252
test('getHref returns the edit urls', async () => {
53-
const action = new EditPanelAction(getFactory);
53+
const action = new EditPanelAction(getFactory, {} as any);
5454
expect(action.getHref).toBeDefined();
5555

5656
if (action.getHref) {
@@ -64,7 +64,7 @@ test('getHref returns the edit urls', async () => {
6464
});
6565

6666
test('is not compatible when edit url is not available', async () => {
67-
const action = new EditPanelAction(getFactory);
67+
const action = new EditPanelAction(getFactory, {} as any);
6868
const embeddable = new ContactCardEmbeddable(
6969
{
7070
id: '123',
@@ -83,7 +83,7 @@ test('is not compatible when edit url is not available', async () => {
8383
});
8484

8585
test('is not visible when edit url is available but in view mode', async () => {
86-
const action = new EditPanelAction(getFactory);
86+
const action = new EditPanelAction(getFactory, {} as any);
8787
expect(
8888
await action.isCompatible({
8989
embeddable: new EditableEmbeddable(
@@ -98,7 +98,7 @@ test('is not visible when edit url is available but in view mode', async () => {
9898
});
9999

100100
test('is not compatible when edit url is available, in edit mode, but not editable', async () => {
101-
const action = new EditPanelAction(getFactory);
101+
const action = new EditPanelAction(getFactory, {} as any);
102102
expect(
103103
await action.isCompatible({
104104
embeddable: new EditableEmbeddable(

src/plugins/embeddable/public/lib/actions/edit_panel_action.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import { i18n } from '@kbn/i18n';
21+
import { ApplicationStart } from 'kibana/public';
2122
import { Action } from 'src/plugins/ui_actions/public';
2223
import { ViewMode } from '../types';
2324
import { EmbeddableFactoryNotFoundError } from '../errors';
@@ -35,7 +36,10 @@ export class EditPanelAction implements Action<ActionContext> {
3536
public readonly id = ACTION_EDIT_PANEL;
3637
public order = 15;
3738

38-
constructor(private readonly getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory']) {}
39+
constructor(
40+
private readonly getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory'],
41+
private readonly application: ApplicationStart
42+
) {}
3943

4044
public getDisplayName({ embeddable }: ActionContext) {
4145
const factory = this.getEmbeddableFactory(embeddable.type);
@@ -56,18 +60,35 @@ export class EditPanelAction implements Action<ActionContext> {
5660

5761
public async isCompatible({ embeddable }: ActionContext) {
5862
const canEditEmbeddable = Boolean(
59-
embeddable && embeddable.getOutput().editable && embeddable.getOutput().editUrl
63+
embeddable &&
64+
embeddable.getOutput().editable &&
65+
(embeddable.getOutput().editUrl ||
66+
(embeddable.getOutput().editApp && embeddable.getOutput().editPath))
6067
);
6168
const inDashboardEditMode = embeddable.getInput().viewMode === ViewMode.EDIT;
6269
return Boolean(canEditEmbeddable && inDashboardEditMode);
6370
}
6471

6572
public async execute(context: ActionContext) {
73+
const appTarget = this.getAppTarget(context);
74+
75+
if (appTarget) {
76+
await this.application.navigateToApp(appTarget.app, { path: appTarget.path });
77+
return;
78+
}
79+
6680
const href = await this.getHref(context);
6781
if (href) {
68-
// TODO: when apps start using browser router instead of hash router this has to be fixed
69-
// https://github.com/elastic/kibana/issues/58217
7082
window.location.href = href;
83+
return;
84+
}
85+
}
86+
87+
public getAppTarget({ embeddable }: ActionContext): { app: string; path: string } | undefined {
88+
const app = embeddable ? embeddable.getOutput().editApp : undefined;
89+
const path = embeddable ? embeddable.getOutput().editPath : undefined;
90+
if (app && path) {
91+
return { app, path };
7192
}
7293
}
7394

src/plugins/embeddable/public/lib/containers/embeddable_child_panel.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ test('EmbeddableChildPanel renders an embeddable when it is done loading', async
6666
getAllEmbeddableFactories={start.getEmbeddableFactories}
6767
getEmbeddableFactory={getEmbeddableFactory}
6868
notifications={{} as any}
69+
application={{} as any}
6970
overlays={{} as any}
7071
inspector={inspector}
7172
SavedObjectFinder={() => null}
@@ -105,6 +106,7 @@ test(`EmbeddableChildPanel renders an error message if the factory doesn't exist
105106
getEmbeddableFactory={(() => undefined) as any}
106107
notifications={{} as any}
107108
overlays={{} as any}
109+
application={{} as any}
108110
inspector={inspector}
109111
SavedObjectFinder={() => null}
110112
/>

src/plugins/embeddable/public/lib/containers/embeddable_child_panel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface EmbeddableChildPanelProps {
4040
getAllEmbeddableFactories: EmbeddableStart['getEmbeddableFactories'];
4141
overlays: CoreStart['overlays'];
4242
notifications: CoreStart['notifications'];
43+
application: CoreStart['application'];
4344
inspector: InspectorStartContract;
4445
SavedObjectFinder: React.ComponentType<any>;
4546
}
@@ -101,6 +102,7 @@ export class EmbeddableChildPanel extends React.Component<EmbeddableChildPanelPr
101102
getEmbeddableFactory={this.props.getEmbeddableFactory}
102103
getAllEmbeddableFactories={this.props.getAllEmbeddableFactories}
103104
overlays={this.props.overlays}
105+
application={this.props.application}
104106
notifications={this.props.notifications}
105107
inspector={this.props.inspector}
106108
SavedObjectFinder={this.props.SavedObjectFinder}

src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface EmbeddableInput {
5555

5656
export interface EmbeddableOutput {
5757
editUrl?: string;
58+
editApp?: string;
59+
editPath?: string;
5860
defaultTitle?: string;
5961
title?: string;
6062
editable?: boolean;

src/plugins/embeddable/public/lib/panel/embeddable_panel.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ test('HelloWorldContainer in view mode hides edit mode actions', async () => {
159159
getAllEmbeddableFactories={start.getEmbeddableFactories}
160160
getEmbeddableFactory={start.getEmbeddableFactory}
161161
notifications={{} as any}
162+
application={{} as any}
162163
overlays={{} as any}
163164
inspector={inspector}
164165
SavedObjectFinder={() => null}
@@ -198,6 +199,7 @@ const renderInEditModeAndOpenContextMenu = async (
198199
getEmbeddableFactory={start.getEmbeddableFactory}
199200
notifications={{} as any}
200201
overlays={{} as any}
202+
application={{} as any}
201203
inspector={inspector}
202204
SavedObjectFinder={() => null}
203205
/>
@@ -296,6 +298,7 @@ test('HelloWorldContainer in edit mode shows edit mode actions', async () => {
296298
getEmbeddableFactory={start.getEmbeddableFactory}
297299
notifications={{} as any}
298300
overlays={{} as any}
301+
application={{} as any}
299302
inspector={inspector}
300303
SavedObjectFinder={() => null}
301304
/>
@@ -358,6 +361,7 @@ test('Updates when hidePanelTitles is toggled', async () => {
358361
getEmbeddableFactory={start.getEmbeddableFactory}
359362
notifications={{} as any}
360363
overlays={{} as any}
364+
application={{} as any}
361365
inspector={inspector}
362366
SavedObjectFinder={() => null}
363367
/>
@@ -410,6 +414,7 @@ test('Check when hide header option is false', async () => {
410414
getEmbeddableFactory={start.getEmbeddableFactory}
411415
notifications={{} as any}
412416
overlays={{} as any}
417+
application={{} as any}
413418
inspector={inspector}
414419
SavedObjectFinder={() => null}
415420
hideHeader={false}
@@ -447,6 +452,7 @@ test('Check when hide header option is true', async () => {
447452
getEmbeddableFactory={start.getEmbeddableFactory}
448453
notifications={{} as any}
449454
overlays={{} as any}
455+
application={{} as any}
450456
inspector={inspector}
451457
SavedObjectFinder={() => null}
452458
hideHeader={true}

src/plugins/embeddable/public/lib/panel/embeddable_panel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface Props {
4545
getAllEmbeddableFactories: EmbeddableStart['getEmbeddableFactories'];
4646
overlays: CoreStart['overlays'];
4747
notifications: CoreStart['notifications'];
48+
application: CoreStart['application'];
4849
inspector: InspectorStartContract;
4950
SavedObjectFinder: React.ComponentType<any>;
5051
hideHeader?: boolean;
@@ -243,7 +244,7 @@ export class EmbeddablePanel extends React.Component<Props, State> {
243244
),
244245
new InspectPanelAction(this.props.inspector),
245246
new RemovePanelAction(),
246-
new EditPanelAction(this.props.getEmbeddableFactory),
247+
new EditPanelAction(this.props.getEmbeddableFactory, this.props.application),
247248
];
248249

249250
const sorted = actions

src/plugins/embeddable/public/lib/test_samples/embeddables/hello_world_container.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ interface HelloWorldContainerOptions {
4949
getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory'];
5050
getAllEmbeddableFactories: EmbeddableStart['getEmbeddableFactories'];
5151
overlays: CoreStart['overlays'];
52+
application: CoreStart['application'];
5253
notifications: CoreStart['notifications'];
5354
inspector: InspectorStartContract;
5455
SavedObjectFinder: React.ComponentType<any>;
@@ -81,6 +82,7 @@ export class HelloWorldContainer extends Container<InheritedInput, HelloWorldCon
8182
getAllEmbeddableFactories={this.options.getAllEmbeddableFactories}
8283
getEmbeddableFactory={this.options.getEmbeddableFactory}
8384
overlays={this.options.overlays}
85+
application={this.options.application}
8486
notifications={this.options.notifications}
8587
inspector={this.options.inspector}
8688
SavedObjectFinder={this.options.SavedObjectFinder}

0 commit comments

Comments
 (0)