Skip to content

Commit

Permalink
revert embeddable changes and create stateful wrapper on the boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 9, 2019
1 parent f1dea23 commit db4ae45
Show file tree
Hide file tree
Showing 35 changed files with 183 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ import { DashboardAppScope } from './dashboard_app';
import { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize/embeddable';
import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters';
import { RenderDeps } from './application';
import {
SavedObjectFinderProps,
SavedObjectFinderUi,
} from '../../../../../plugins/kibana_react/public';

export interface DashboardAppControllerDependencies extends RenderDeps {
$scope: DashboardAppScope;
Expand Down Expand Up @@ -717,14 +721,17 @@ export class DashboardAppController {
};
navActions[TopNavIds.ADD] = () => {
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
const SavedObjectFinder = (props: SavedObjectFinderProps) => (
<SavedObjectFinderUi {...props} savedObjects={savedObjects} uiSettings={uiSettings} />
);

openAddPanelFlyout({
embeddable: dashboardContainer,
getAllFactories: embeddables.getEmbeddableFactories,
getFactory: embeddables.getEmbeddableFactory,
notifications,
overlays,
uiSettings,
savedObjects,
SavedObjectFinder,
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let embeddable: ContactCardEmbeddable;
beforeEach(async () => {
const options: DashboardOptions = {
ExitFullScreenButton: () => null,
SavedObjectFinder: () => null,
application: {} as any,
embeddable: {
getEmbeddableFactory: (id: string) => embeddableFactories.get(id)!,
Expand All @@ -51,8 +52,6 @@ beforeEach(async () => {
overlays: {} as any,
savedObjectMetaData: {} as any,
uiActions: {} as any,
uiSettings: {} as any,
savedObjects: {} as any,
};
const input = getSampleDashboardInput({
panels: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ import {
export async function openReplacePanelFlyout(options: {
embeddable: IContainer;
core: CoreStart;
savedObjectFinder: React.ComponentType<any>;
notifications: CoreStart['notifications'];
panelToRemove: IEmbeddable<EmbeddableInput, EmbeddableOutput>;
getEmbeddableFactories: IEmbeddableStart['getEmbeddableFactories'];
}) {
const { embeddable, core, panelToRemove, getEmbeddableFactories } = options;
const {
embeddable,
core,
panelToRemove,
savedObjectFinder,
notifications,
getEmbeddableFactories,
} = options;
const flyoutSession = core.overlays.openFlyout(
toMountPoint(
<ReplacePanelFlyout
Expand All @@ -45,9 +54,8 @@ export async function openReplacePanelFlyout(options: {
}
}}
panelToRemove={panelToRemove}
notifications={core.notifications}
uiSettings={core.uiSettings}
savedObjects={core.savedObjects}
savedObjectsFinder={savedObjectFinder}
notifications={notifications}
getEmbeddableFactories={getEmbeddableFactories}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ beforeEach(async () => {
coreStart = coreMock.createStart();
const options: DashboardOptions = {
ExitFullScreenButton: () => null,
SavedObjectFinder: () => null,
application: {} as any,
embeddable: {
getEmbeddableFactory: (id: string) => embeddableFactories.get(id)!,
} as any,
inspector: {} as any,
notifications: {} as any,
uiSettings: coreStart.uiSettings,
savedObjects: coreStart.savedObjects,
overlays: coreStart.overlays,
savedObjectMetaData: {} as any,
uiActions: {} as any,
Expand Down Expand Up @@ -83,12 +82,26 @@ beforeEach(async () => {
});

test('Executes the replace panel action', async () => {
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
let SavedObjectFinder: any;
let notifications: any;
const action = new ReplacePanelAction(
coreStart,
SavedObjectFinder,
notifications,
getEmbeddableFactories
);
action.execute({ embeddable });
});

test('Is not compatible when embeddable is not in a dashboard container', async () => {
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
let SavedObjectFinder: any;
let notifications: any;
const action = new ReplacePanelAction(
coreStart,
SavedObjectFinder,
notifications,
getEmbeddableFactories
);
expect(
await action.isCompatible({
embeddable: new ContactCardEmbeddable(
Expand All @@ -100,19 +113,40 @@ test('Is not compatible when embeddable is not in a dashboard container', async
});

test('Execute throws an error when called with an embeddable not in a parent', async () => {
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
let SavedObjectFinder: any;
let notifications: any;
const action = new ReplacePanelAction(
coreStart,
SavedObjectFinder,
notifications,
getEmbeddableFactories
);
async function check() {
await action.execute({ embeddable: container });
}
await expect(check()).rejects.toThrow(Error);
});

test('Returns title', async () => {
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
let SavedObjectFinder: any;
let notifications: any;
const action = new ReplacePanelAction(
coreStart,
SavedObjectFinder,
notifications,
getEmbeddableFactories
);
expect(action.getDisplayName({ embeddable })).toBeDefined();
});

test('Returns an icon', async () => {
const action = new ReplacePanelAction(coreStart, getEmbeddableFactories);
let SavedObjectFinder: any;
let notifications: any;
const action = new ReplacePanelAction(
coreStart,
SavedObjectFinder,
notifications,
getEmbeddableFactories
);
expect(action.getIconType({ embeddable })).toBeDefined();
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class ReplacePanelAction implements IAction<ActionContext> {

constructor(
private core: CoreStart,
private savedobjectfinder: React.ComponentType<any>,
private notifications: CoreStart['notifications'],
private getEmbeddableFactories: IEmbeddableStart['getEmbeddableFactories']
) {}

Expand Down Expand Up @@ -80,6 +82,8 @@ export class ReplacePanelAction implements IAction<ActionContext> {
openReplacePanelFlyout({
embeddable: dash,
core: this.core,
savedObjectFinder: this.savedobjectfinder,
notifications: this.notifications,
panelToRemove: view,
getEmbeddableFactories: this.getEmbeddableFactories,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import React from 'react';
import { EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, EuiTitle } from '@elastic/eui';
import { GetEmbeddableFactories } from 'src/plugins/embeddable/public';
import { DashboardPanelState } from '../embeddable';
import { CoreStart, NotificationsStart, Toast } from '../../../../core/public';
import { NotificationsStart, Toast } from '../../../../core/public';
import { IContainer, IEmbeddable, EmbeddableInput, EmbeddableOutput } from '../embeddable_plugin';
import { SavedObjectFinderUi } from '../../../kibana_react/public';

interface Props {
container: IContainer;
savedObjectsFinder: React.ComponentType<any>;
onClose: () => void;
notifications: NotificationsStart;
uiSettings: CoreStart['uiSettings'];
savedObjects: CoreStart['savedObjects'];
panelToRemove: IEmbeddable<EmbeddableInput, EmbeddableOutput>;
getEmbeddableFactories: GetEmbeddableFactories;
}
Expand Down Expand Up @@ -96,8 +94,9 @@ export class ReplacePanelFlyout extends React.Component<Props> {
};

public render() {
const SavedObjectFinder = this.props.savedObjectsFinder;
const savedObjectsFinder = (
<SavedObjectFinderUi
<SavedObjectFinder
noItemsMessage={i18n.translate(
'dashboardEmbeddableContainer.addPanel.noMatchingObjectsMessage',
{
Expand All @@ -112,8 +111,6 @@ export class ReplacePanelFlyout extends React.Component<Props> {
.map(({ savedObjectMetaData }) => savedObjectMetaData as any)}
showFilter={true}
onChoose={this.onReplacePanel}
uiSettings={this.props.uiSettings}
savedObjects={this.props.savedObjects}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ const options: DashboardContainerOptions = {
notifications: {} as any,
overlays: {} as any,
inspector: {} as any,
SavedObjectFinder: () => null,
ExitFullScreenButton: () => null,
uiActions: {} as any,
uiSettings: {} as any,
savedObjects: {} as any,
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ export interface DashboardContainerOptions {
application: CoreStart['application'];
overlays: CoreStart['overlays'];
notifications: CoreStart['notifications'];
savedObjects: CoreStart['savedObjects'];
uiSettings: CoreStart['uiSettings'];
embeddable: IEmbeddableStart;
inspector: InspectorStartContract;
SavedObjectFinder: React.ComponentType<any>;
ExitFullScreenButton: React.ComponentType<any>;
uiActions: IUiActionsStart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ function prepare(props?: Partial<DashboardGridProps>) {
inspector: {
isAvailable: jest.fn(),
} as any,
SavedObjectFinder: () => null,
ExitFullScreenButton: () => null,
uiActions: {
getTriggerCompatibleActions: (() => []) as any,
} as any,
uiSettings: {} as any,
savedObjects: {} as any,
};
dashboardContainer = new DashboardContainer(initialInput, options);
const defaultTestProps: DashboardGridProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ class DashboardGridUi extends React.Component<DashboardGridProps, State> {
overlays={this.props.kibana.services.overlays}
notifications={this.props.kibana.services.notifications}
inspector={this.props.kibana.services.inspector}
uiSettings={this.props.kibana.services.uiSettings}
savedObjects={this.props.kibana.services.savedObjects}
SavedObjectFinder={this.props.kibana.services.SavedObjectFinder}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ function getProps(
inspector: {
isAvailable: jest.fn(),
} as any,
uiSettings: {} as any,
savedObjects: {} as any,
SavedObjectFinder: () => null,
ExitFullScreenButton,
uiActions: {
getTriggerCompatibleActions: (() => []) as any,
Expand Down
20 changes: 17 additions & 3 deletions src/plugins/dashboard_embeddable_container/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { ExpandPanelAction, ReplacePanelAction } from '.';
import { DashboardContainerFactory } from './embeddable/dashboard_container_factory';
import { Start as InspectorStartContract } from '../../../plugins/inspector/public';
import {
SavedObjectFinderUi,
SavedObjectFinderProps,
ExitFullScreenButton as ExitFullScreenButtonUi,
ExitFullScreenButtonProps,
} from '../../../plugins/kibana_react/public';
Expand Down Expand Up @@ -56,9 +58,20 @@ export class DashboardEmbeddableContainerPublicPlugin
}

public start(core: CoreStart, plugins: StartDependencies): Start {
const { application, notifications, overlays, uiSettings, savedObjects } = core;
const { application, notifications, overlays } = core;
const { embeddable, inspector, uiActions } = plugins;

const SavedObjectFinder: React.FC<Exclude<
SavedObjectFinderProps,
'savedObjects' | 'uiSettings'
>> = props => (
<SavedObjectFinderUi
{...props}
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
/>
);

const useHideChrome = () => {
React.useEffect(() => {
core.chrome.setIsVisible(false);
Expand All @@ -73,6 +86,8 @@ export class DashboardEmbeddableContainerPublicPlugin

const changeViewAction = new ReplacePanelAction(
core,
SavedObjectFinder,
notifications,
plugins.embeddable.getEmbeddableFactories
);
uiActions.registerAction(changeViewAction);
Expand All @@ -84,10 +99,9 @@ export class DashboardEmbeddableContainerPublicPlugin
overlays,
embeddable,
inspector,
SavedObjectFinder,
ExitFullScreenButton,
uiActions,
uiSettings,
savedObjects,
});

embeddable.registerEmbeddableFactory(factory.type, factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ test('DashboardContainer in edit mode shows edit mode actions', async () => {
notifications: {} as any,
overlays: {} as any,
inspector: {} as any,
uiSettings: {} as any,
savedObjects: {} as any,
SavedObjectFinder: () => null,
ExitFullScreenButton: () => null,
uiActions: {} as any,
};
Expand All @@ -90,8 +89,7 @@ test('DashboardContainer in edit mode shows edit mode actions', async () => {
notifications={{} as any}
overlays={{} as any}
inspector={inspector}
uiSettings={{} as any}
savedObjects={{} as any}
SavedObjectFinder={() => null}
/>
</KibanaContextProvider>
</I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ test('EmbeddableChildPanel renders an embeddable when it is done loading', async
getEmbeddableFactory={(() => undefined) as any}
notifications={{} as any}
overlays={{} as any}
uiSettings={{} as any}
savedObjects={{} as any}
inspector={inspector}
SavedObjectFinder={() => null}
/>
);

Expand Down Expand Up @@ -107,9 +106,8 @@ test(`EmbeddableChildPanel renders an error message if the factory doesn't exist
getEmbeddableFactory={(() => undefined) as any}
notifications={{} as any}
overlays={{} as any}
uiSettings={{} as any}
savedObjects={{} as any}
inspector={inspector}
SavedObjectFinder={() => null}
/>
);

Expand Down
Loading

0 comments on commit db4ae45

Please sign in to comment.