Skip to content

Commit db4ae45

Browse files
committed
revert embeddable changes and create stateful wrapper on the boundaries
1 parent f1dea23 commit db4ae45

35 files changed

+183
-152
lines changed

src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ import { DashboardAppScope } from './dashboard_app';
7070
import { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize/embeddable';
7171
import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters';
7272
import { RenderDeps } from './application';
73+
import {
74+
SavedObjectFinderProps,
75+
SavedObjectFinderUi,
76+
} from '../../../../../plugins/kibana_react/public';
7377

7478
export interface DashboardAppControllerDependencies extends RenderDeps {
7579
$scope: DashboardAppScope;
@@ -717,14 +721,17 @@ export class DashboardAppController {
717721
};
718722
navActions[TopNavIds.ADD] = () => {
719723
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
724+
const SavedObjectFinder = (props: SavedObjectFinderProps) => (
725+
<SavedObjectFinderUi {...props} savedObjects={savedObjects} uiSettings={uiSettings} />
726+
);
727+
720728
openAddPanelFlyout({
721729
embeddable: dashboardContainer,
722730
getAllFactories: embeddables.getEmbeddableFactories,
723731
getFactory: embeddables.getEmbeddableFactory,
724732
notifications,
725733
overlays,
726-
uiSettings,
727-
savedObjects,
734+
SavedObjectFinder,
728735
});
729736
}
730737
};

src/plugins/dashboard_embeddable_container/public/actions/expand_panel_action.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ let embeddable: ContactCardEmbeddable;
4242
beforeEach(async () => {
4343
const options: DashboardOptions = {
4444
ExitFullScreenButton: () => null,
45+
SavedObjectFinder: () => null,
4546
application: {} as any,
4647
embeddable: {
4748
getEmbeddableFactory: (id: string) => embeddableFactories.get(id)!,
@@ -51,8 +52,6 @@ beforeEach(async () => {
5152
overlays: {} as any,
5253
savedObjectMetaData: {} as any,
5354
uiActions: {} as any,
54-
uiSettings: {} as any,
55-
savedObjects: {} as any,
5655
};
5756
const input = getSampleDashboardInput({
5857
panels: {

src/plugins/dashboard_embeddable_container/public/actions/open_replace_panel_flyout.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,19 @@ import {
3131
export async function openReplacePanelFlyout(options: {
3232
embeddable: IContainer;
3333
core: CoreStart;
34+
savedObjectFinder: React.ComponentType<any>;
35+
notifications: CoreStart['notifications'];
3436
panelToRemove: IEmbeddable<EmbeddableInput, EmbeddableOutput>;
3537
getEmbeddableFactories: IEmbeddableStart['getEmbeddableFactories'];
3638
}) {
37-
const { embeddable, core, panelToRemove, getEmbeddableFactories } = options;
39+
const {
40+
embeddable,
41+
core,
42+
panelToRemove,
43+
savedObjectFinder,
44+
notifications,
45+
getEmbeddableFactories,
46+
} = options;
3847
const flyoutSession = core.overlays.openFlyout(
3948
toMountPoint(
4049
<ReplacePanelFlyout
@@ -45,9 +54,8 @@ export async function openReplacePanelFlyout(options: {
4554
}
4655
}}
4756
panelToRemove={panelToRemove}
48-
notifications={core.notifications}
49-
uiSettings={core.uiSettings}
50-
savedObjects={core.savedObjects}
57+
savedObjectsFinder={savedObjectFinder}
58+
notifications={notifications}
5159
getEmbeddableFactories={getEmbeddableFactories}
5260
/>
5361
),

src/plugins/dashboard_embeddable_container/public/actions/replace_panel_action.test.tsx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ beforeEach(async () => {
4545
coreStart = coreMock.createStart();
4646
const options: DashboardOptions = {
4747
ExitFullScreenButton: () => null,
48+
SavedObjectFinder: () => null,
4849
application: {} as any,
4950
embeddable: {
5051
getEmbeddableFactory: (id: string) => embeddableFactories.get(id)!,
5152
} as any,
5253
inspector: {} as any,
5354
notifications: {} as any,
54-
uiSettings: coreStart.uiSettings,
55-
savedObjects: coreStart.savedObjects,
5655
overlays: coreStart.overlays,
5756
savedObjectMetaData: {} as any,
5857
uiActions: {} as any,
@@ -83,12 +82,26 @@ beforeEach(async () => {
8382
});
8483

8584
test('Executes the replace panel action', async () => {
86-
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
85+
let SavedObjectFinder: any;
86+
let notifications: any;
87+
const action = new ReplacePanelAction(
88+
coreStart,
89+
SavedObjectFinder,
90+
notifications,
91+
getEmbeddableFactories
92+
);
8793
action.execute({ embeddable });
8894
});
8995

9096
test('Is not compatible when embeddable is not in a dashboard container', async () => {
91-
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
97+
let SavedObjectFinder: any;
98+
let notifications: any;
99+
const action = new ReplacePanelAction(
100+
coreStart,
101+
SavedObjectFinder,
102+
notifications,
103+
getEmbeddableFactories
104+
);
92105
expect(
93106
await action.isCompatible({
94107
embeddable: new ContactCardEmbeddable(
@@ -100,19 +113,40 @@ test('Is not compatible when embeddable is not in a dashboard container', async
100113
});
101114

102115
test('Execute throws an error when called with an embeddable not in a parent', async () => {
103-
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
116+
let SavedObjectFinder: any;
117+
let notifications: any;
118+
const action = new ReplacePanelAction(
119+
coreStart,
120+
SavedObjectFinder,
121+
notifications,
122+
getEmbeddableFactories
123+
);
104124
async function check() {
105125
await action.execute({ embeddable: container });
106126
}
107127
await expect(check()).rejects.toThrow(Error);
108128
});
109129

110130
test('Returns title', async () => {
111-
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
131+
let SavedObjectFinder: any;
132+
let notifications: any;
133+
const action = new ReplacePanelAction(
134+
coreStart,
135+
SavedObjectFinder,
136+
notifications,
137+
getEmbeddableFactories
138+
);
112139
expect(action.getDisplayName({ embeddable })).toBeDefined();
113140
});
114141

115142
test('Returns an icon', async () => {
116-
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
143+
let SavedObjectFinder: any;
144+
let notifications: any;
145+
const action = new ReplacePanelAction(
146+
coreStart,
147+
SavedObjectFinder,
148+
notifications,
149+
getEmbeddableFactories
150+
);
117151
expect(action.getIconType({ embeddable })).toBeDefined();
118152
});

src/plugins/dashboard_embeddable_container/public/actions/replace_panel_action.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export class ReplacePanelAction implements IAction<ActionContext> {
4141

4242
constructor(
4343
private core: CoreStart,
44+
private savedobjectfinder: React.ComponentType<any>,
45+
private notifications: CoreStart['notifications'],
4446
private getEmbeddableFactories: IEmbeddableStart['getEmbeddableFactories']
4547
) {}
4648

@@ -80,6 +82,8 @@ export class ReplacePanelAction implements IAction<ActionContext> {
8082
openReplacePanelFlyout({
8183
embeddable: dash,
8284
core: this.core,
85+
savedObjectFinder: this.savedobjectfinder,
86+
notifications: this.notifications,
8387
panelToRemove: view,
8488
getEmbeddableFactories: this.getEmbeddableFactories,
8589
});

src/plugins/dashboard_embeddable_container/public/actions/replace_panel_flyout.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ import React from 'react';
2222
import { EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, EuiTitle } from '@elastic/eui';
2323
import { GetEmbeddableFactories } from 'src/plugins/embeddable/public';
2424
import { DashboardPanelState } from '../embeddable';
25-
import { CoreStart, NotificationsStart, Toast } from '../../../../core/public';
25+
import { NotificationsStart, Toast } from '../../../../core/public';
2626
import { IContainer, IEmbeddable, EmbeddableInput, EmbeddableOutput } from '../embeddable_plugin';
27-
import { SavedObjectFinderUi } from '../../../kibana_react/public';
2827

2928
interface Props {
3029
container: IContainer;
30+
savedObjectsFinder: React.ComponentType<any>;
3131
onClose: () => void;
3232
notifications: NotificationsStart;
33-
uiSettings: CoreStart['uiSettings'];
34-
savedObjects: CoreStart['savedObjects'];
3533
panelToRemove: IEmbeddable<EmbeddableInput, EmbeddableOutput>;
3634
getEmbeddableFactories: GetEmbeddableFactories;
3735
}
@@ -96,8 +94,9 @@ export class ReplacePanelFlyout extends React.Component<Props> {
9694
};
9795

9896
public render() {
97+
const SavedObjectFinder = this.props.savedObjectsFinder;
9998
const savedObjectsFinder = (
100-
<SavedObjectFinderUi
99+
<SavedObjectFinder
101100
noItemsMessage={i18n.translate(
102101
'dashboardEmbeddableContainer.addPanel.noMatchingObjectsMessage',
103102
{
@@ -112,8 +111,6 @@ export class ReplacePanelFlyout extends React.Component<Props> {
112111
.map(({ savedObjectMetaData }) => savedObjectMetaData as any)}
113112
showFilter={true}
114113
onChoose={this.onReplacePanel}
115-
uiSettings={this.props.uiSettings}
116-
savedObjects={this.props.savedObjects}
117114
/>
118115
);
119116

src/plugins/dashboard_embeddable_container/public/embeddable/dashboard_container.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ const options: DashboardContainerOptions = {
4141
notifications: {} as any,
4242
overlays: {} as any,
4343
inspector: {} as any,
44+
SavedObjectFinder: () => null,
4445
ExitFullScreenButton: () => null,
4546
uiActions: {} as any,
46-
uiSettings: {} as any,
47-
savedObjects: {} as any,
4847
};
4948

5049
beforeEach(() => {

src/plugins/dashboard_embeddable_container/public/embeddable/dashboard_container.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ export interface DashboardContainerOptions {
7777
application: CoreStart['application'];
7878
overlays: CoreStart['overlays'];
7979
notifications: CoreStart['notifications'];
80-
savedObjects: CoreStart['savedObjects'];
81-
uiSettings: CoreStart['uiSettings'];
8280
embeddable: IEmbeddableStart;
8381
inspector: InspectorStartContract;
82+
SavedObjectFinder: React.ComponentType<any>;
8483
ExitFullScreenButton: React.ComponentType<any>;
8584
uiActions: IUiActionsStart;
8685
}

src/plugins/dashboard_embeddable_container/public/embeddable/grid/dashboard_grid.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ function prepare(props?: Partial<DashboardGridProps>) {
6868
inspector: {
6969
isAvailable: jest.fn(),
7070
} as any,
71+
SavedObjectFinder: () => null,
7172
ExitFullScreenButton: () => null,
7273
uiActions: {
7374
getTriggerCompatibleActions: (() => []) as any,
7475
} as any,
75-
uiSettings: {} as any,
76-
savedObjects: {} as any,
7776
};
7877
dashboardContainer = new DashboardContainer(initialInput, options);
7978
const defaultTestProps: DashboardGridProps = {

src/plugins/dashboard_embeddable_container/public/embeddable/grid/dashboard_grid.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ class DashboardGridUi extends React.Component<DashboardGridProps, State> {
276276
overlays={this.props.kibana.services.overlays}
277277
notifications={this.props.kibana.services.notifications}
278278
inspector={this.props.kibana.services.inspector}
279-
uiSettings={this.props.kibana.services.uiSettings}
280-
savedObjects={this.props.kibana.services.savedObjects}
279+
SavedObjectFinder={this.props.kibana.services.SavedObjectFinder}
281280
/>
282281
</div>
283282
);

0 commit comments

Comments
 (0)