Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions examples/embeddable_examples/common/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 { TodoSavedObjectAttributes, SearchableListSavedObjectAttributes } from './types';
32 changes: 32 additions & 0 deletions examples/embeddable_examples/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*/

import { SavedObjectAttributes } from 'kibana/public';

export interface TodoSavedObjectAttributes extends SavedObjectAttributes {
task: string;
icon?: string;
title?: string;
}

export interface SearchableListSavedObjectAttributes extends SavedObjectAttributes {
panelsJSON: string;
title?: string;
search?: string;
}
4 changes: 2 additions & 2 deletions examples/embeddable_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["embeddable_examples"],
"server": false,
"server": true,
"ui": true,
"requiredPlugins": ["embeddable"],
"requiredPlugins": ["embeddable", "uiActions", "inspector"],
"optionalPlugins": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.
*/
import React from 'react';
import { CoreStart } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { IEmbeddable } from 'src/plugins/embeddable/public';
import { EuiCallOut } from '@elastic/eui';
import { createAction } from '../../../../src/plugins/ui_actions/public';
import { toMountPoint } from '../../../../src/plugins/kibana_react/public';

interface StartServices {
openModal: CoreStart['overlays']['openModal'];
}

export interface CheckRefsActionContext {
embeddable: IEmbeddable;
}

export const ACTION_CHECK_SO_REFERENCES = 'ACTION_CHECK_SO_REFERENCES';

export const createCheckReferencesAction = (getStartServices: () => Promise<StartServices>) =>
createAction({
getDisplayName: () =>
i18n.translate('embeddableExamples.actions.checkReferences', {
defaultMessage: 'View saved object references',
}),
type: ACTION_CHECK_SO_REFERENCES,
isCompatible: async ({ embeddable }) => {
return Boolean(
embeddable.getOutput().savedObjectReferences &&
embeddable.getOutput().savedObjectReferences!.length > 0
);
},
execute: async ({ embeddable }) => {
const { openModal } = await getStartServices();
const refs = embeddable.getOutput().savedObjectReferences;
if (refs) {
openModal(
toMountPoint(
<EuiCallOut data-test-subj="refs">
<h1>Saved object references:</h1>
{refs.map(ref => (
<ul>
<li>{`id: ${ref.id}`}</li>
<li>{`type: ${ref.type}`}</li>
<li>{`name: ${ref.name}`}</li>
</ul>
))}
</EuiCallOut>
)
);
}
},
});
20 changes: 20 additions & 0 deletions examples/embeddable_examples/public/actions/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 * from './check_references_action';
94 changes: 94 additions & 0 deletions examples/embeddable_examples/public/create_sample_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.
*/

import { SavedObjectsClientContract } from 'kibana/public';
import { PanelState } from 'src/plugins/embeddable/public';
import { TodoSavedObjectAttributes, SearchableListSavedObjectAttributes } from '../common';
import { TODO_SO_EMBEDDABLE } from './todo_saved_object';

export async function createSampleData(client: SavedObjectsClientContract, overwrite = true) {
await client.create<TodoSavedObjectAttributes>(
'todo',
{
task: 'Take the garbage out',
title: 'Garbage',
icon: 'trash',
},
{
id: 'sample-todo-saved-object',
overwrite,
}
);

await client.create<TodoSavedObjectAttributes>(
'todo',
{
task: 'Disinfect the house. Spare no bugs!',
title: 'Disinfect',
icon: 'bug',
},
{
id: 'sample-todo-saved-object-2',
overwrite,
}
);

const panels: { [key: string]: PanelState } = {
'1': {
type: TODO_SO_EMBEDDABLE,
explicitInput: {
id: '1',
savedObjectId: 'sample-todo-saved-object',
},
},
'2': {
type: TODO_SO_EMBEDDABLE,
explicitInput: {
id: '2',
task: 'Sweep & mop the floors',
title: 'Floors',
icon: 'broom',
},
},
'3': {
type: TODO_SO_EMBEDDABLE,
explicitInput: {
id: '3',
savedObjectId: 'sample-todo-saved-object-2',
},
},
};

await client.create<SearchableListSavedObjectAttributes>(
'list',
{
panelsJSON: JSON.stringify(panels),
title: 'My todo list',
search: 'foo',
},
{
id: 'sample-list-saved-object',
overwrite,
references: [
{ name: 'sample-todo-saved-object-2', id: 'sample-todo-saved-object-2', type: 'todo' },
{ name: 'sample-todo-saved-object', id: 'sample-todo-saved-object', type: 'todo' },
],
}
);
}
22 changes: 9 additions & 13 deletions examples/embeddable_examples/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

import { PluginInitializer } from 'kibana/public';
export {
HELLO_WORLD_EMBEDDABLE,
HelloWorldEmbeddable,
Expand All @@ -26,18 +25,15 @@ export {
export { ListContainer, LIST_CONTAINER } from './list_container';
export { TODO_EMBEDDABLE } from './todo';

import {
EmbeddableExamplesPlugin,
EmbeddableExamplesSetupDependencies,
EmbeddableExamplesStartDependencies,
} from './plugin';
import { EmbeddableExamplesPlugin } from './plugin';

export { SearchableListContainer, SEARCHABLE_LIST_CONTAINER } from './searchable_list_container';
export { MULTI_TASK_TODO_EMBEDDABLE } from './multi_task_todo';
export {
TODO_SO_EMBEDDABLE,
TodoSoEmbeddable,
TodoSoEmbeddableInput,
TodoSoEmbeddableOutput,
} from './todo_saved_object';

export const plugin: PluginInitializer<
void,
void,
EmbeddableExamplesSetupDependencies,
EmbeddableExamplesStartDependencies
> = () => new EmbeddableExamplesPlugin();
export { MULTI_TASK_TODO_EMBEDDABLE } from './multi_task_todo';
export const plugin = () => new EmbeddableExamplesPlugin();
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,27 @@
*/

import React from 'react';
import { EuiPanel, EuiLoadingSpinner, EuiFlexItem } from '@elastic/eui';
import { IEmbeddable } from '../../../../src/plugins/embeddable/public';
import { EuiLoadingSpinner, EuiFlexItem } from '@elastic/eui';
import { CoreStart, IUiSettingsClient, SavedObjectsStart } from 'kibana/public';
import { UiActionsStart } from '../../../../src/plugins/ui_actions/public';
import { Start as InspectorStart } from '../../../../src/plugins/inspector/public';
import { getSavedObjectFinder } from '../../../../src/plugins/saved_objects/public';
import {
IEmbeddable,
EmbeddableStart,
EmbeddablePanel,
} from '../../../../src/plugins/embeddable/public';

interface Props {
embeddable: IEmbeddable;
uiActionsApi: UiActionsStart;
getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory'];
getAllEmbeddableFactories: EmbeddableStart['getEmbeddableFactories'];
overlays: CoreStart['overlays'];
notifications: CoreStart['notifications'];
inspector: InspectorStart;
savedObject: SavedObjectsStart;
uiSettingsClient: IUiSettingsClient;
}

export class EmbeddableListItem extends React.Component<Props> {
Expand All @@ -49,15 +65,33 @@ export class EmbeddableListItem extends React.Component<Props> {
}

public render() {
const {
embeddable,
uiActionsApi,
getAllEmbeddableFactories,
getEmbeddableFactory,
savedObject,
uiSettingsClient,
notifications,
inspector,
overlays,
} = this.props;
return (
<EuiFlexItem>
<EuiPanel>
{this.props.embeddable ? (
<div ref={this.embeddableRoot} />
) : (
<EuiLoadingSpinner size="s" />
)}
</EuiPanel>
{embeddable ? (
<EmbeddablePanel
embeddable={embeddable}
getActions={uiActionsApi.getTriggerCompatibleActions}
getEmbeddableFactory={getEmbeddableFactory}
getAllEmbeddableFactories={getAllEmbeddableFactories}
overlays={overlays}
notifications={notifications}
inspector={inspector}
SavedObjectFinder={getSavedObjectFinder(savedObject, uiSettingsClient)}
/>
) : (
<EuiLoadingSpinner size="s" />
)}
</EuiFlexItem>
);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/embeddable_examples/public/list_container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export { ListContainer, LIST_CONTAINER } from './list_container';
export { ListContainerFactory } from './list_container_factory';
export * from './list_container';
export * from './list_container_factory';
Loading