[Refactor] Move AttributeService from Dashboard to Embeddable plugin (#79830) (#80177)

* [Refactor] Move AttributeService from Dashboard to Embeddable plugin

* Fix wrong import

* Fixing typescript errors

* Make Dashboard a required dependency

* Fixing circular dependency

* Fix label namespace

* Updating docs

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	docs/development/plugins/embeddable/public/kibana-plugin-plugins-embeddable-public.embeddablestart.md
#	docs/development/plugins/embeddable/public/kibana-plugin-plugins-embeddable-public.md
#	docs/development/plugins/embeddable/server/kibana-plugin-plugins-embeddable-server.embeddablesetup.md
#	src/plugins/embeddable/public/public.api.md
#	src/plugins/embeddable/server/server.api.md
This commit is contained in:
Maja Grubic 2020-10-13 15:24:03 +01:00 committed by GitHub
parent 168c3178e0
commit cc3b7b2bae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 335 additions and 71 deletions

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [ATTRIBUTE\_SERVICE\_KEY](./kibana-plugin-plugins-embeddable-public.attribute_service_key.md)
## ATTRIBUTE\_SERVICE\_KEY variable
The attribute service is a shared, generic service that embeddables can use to provide the functionality required to fulfill the requirements of the ReferenceOrValueEmbeddable interface. The attribute\_service can also be used as a higher level wrapper to transform an embeddable input shape that references a saved object into an embeddable input shape that contains that saved object's attributes by value.
<b>Signature:</b>
```typescript
ATTRIBUTE_SERVICE_KEY = "attributes"
```

View file

@ -0,0 +1,25 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [(constructor)](./kibana-plugin-plugins-embeddable-public.attributeservice._constructor_.md)
## AttributeService.(constructor)
Constructs a new instance of the `AttributeService` class
<b>Signature:</b>
```typescript
constructor(type: string, showSaveModal: (saveModal: React.ReactElement, I18nContext: I18nStart['Context']) => void, i18nContext: I18nStart['Context'], toasts: NotificationsStart['toasts'], options: AttributeServiceOptions<SavedObjectAttributes>, getEmbeddableFactory?: (embeddableFactoryId: string) => EmbeddableFactory);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | |
| showSaveModal | <code>(saveModal: React.ReactElement, I18nContext: I18nStart['Context']) =&gt; void</code> | |
| i18nContext | <code>I18nStart['Context']</code> | |
| toasts | <code>NotificationsStart['toasts']</code> | |
| options | <code>AttributeServiceOptions&lt;SavedObjectAttributes&gt;</code> | |
| getEmbeddableFactory | <code>(embeddableFactoryId: string) =&gt; EmbeddableFactory</code> | |

View file

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [getExplicitInputFromEmbeddable](./kibana-plugin-plugins-embeddable-public.attributeservice.getexplicitinputfromembeddable.md)
## AttributeService.getExplicitInputFromEmbeddable() method
<b>Signature:</b>
```typescript
getExplicitInputFromEmbeddable(embeddable: IEmbeddable): ValType | RefType;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| embeddable | <code>IEmbeddable</code> | |
<b>Returns:</b>
`ValType | RefType`

View file

@ -0,0 +1,16 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [getInputAsRefType](./kibana-plugin-plugins-embeddable-public.attributeservice.getinputasreftype.md)
## AttributeService.getInputAsRefType property
<b>Signature:</b>
```typescript
getInputAsRefType: (input: ValType | RefType, saveOptions?: {
showSaveModal: boolean;
saveModalTitle?: string | undefined;
} | {
title: string;
} | undefined) => Promise<RefType>;
```

View file

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [getInputAsValueType](./kibana-plugin-plugins-embeddable-public.attributeservice.getinputasvaluetype.md)
## AttributeService.getInputAsValueType property
<b>Signature:</b>
```typescript
getInputAsValueType: (input: ValType | RefType) => Promise<ValType>;
```

View file

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [inputIsRefType](./kibana-plugin-plugins-embeddable-public.attributeservice.inputisreftype.md)
## AttributeService.inputIsRefType property
<b>Signature:</b>
```typescript
inputIsRefType: (input: ValType | RefType) => input is RefType;
```

View file

@ -0,0 +1,40 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md)
## AttributeService class
<b>Signature:</b>
```typescript
export declare class AttributeService<SavedObjectAttributes extends {
title: string;
}, ValType extends EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: SavedObjectAttributes;
} = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: SavedObjectAttributes;
}, RefType extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput>
```
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(type, showSaveModal, i18nContext, toasts, options, getEmbeddableFactory)](./kibana-plugin-plugins-embeddable-public.attributeservice._constructor_.md) | | Constructs a new instance of the <code>AttributeService</code> class |
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [getInputAsRefType](./kibana-plugin-plugins-embeddable-public.attributeservice.getinputasreftype.md) | | <code>(input: ValType &#124; RefType, saveOptions?: {</code><br/><code> showSaveModal: boolean;</code><br/><code> saveModalTitle?: string &#124; undefined;</code><br/><code> } &#124; {</code><br/><code> title: string;</code><br/><code> } &#124; undefined) =&gt; Promise&lt;RefType&gt;</code> | |
| [getInputAsValueType](./kibana-plugin-plugins-embeddable-public.attributeservice.getinputasvaluetype.md) | | <code>(input: ValType &#124; RefType) =&gt; Promise&lt;ValType&gt;</code> | |
| [inputIsRefType](./kibana-plugin-plugins-embeddable-public.attributeservice.inputisreftype.md) | | <code>(input: ValType &#124; RefType) =&gt; input is RefType</code> | |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [getExplicitInputFromEmbeddable(embeddable)](./kibana-plugin-plugins-embeddable-public.attributeservice.getexplicitinputfromembeddable.md) | | |
| [unwrapAttributes(input)](./kibana-plugin-plugins-embeddable-public.attributeservice.unwrapattributes.md) | | |
| [wrapAttributes(newAttributes, useRefType, input)](./kibana-plugin-plugins-embeddable-public.attributeservice.wrapattributes.md) | | |

View file

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [unwrapAttributes](./kibana-plugin-plugins-embeddable-public.attributeservice.unwrapattributes.md)
## AttributeService.unwrapAttributes() method
<b>Signature:</b>
```typescript
unwrapAttributes(input: RefType | ValType): Promise<SavedObjectAttributes>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| input | <code>RefType &#124; ValType</code> | |
<b>Returns:</b>
`Promise<SavedObjectAttributes>`

View file

@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) &gt; [wrapAttributes](./kibana-plugin-plugins-embeddable-public.attributeservice.wrapattributes.md)
## AttributeService.wrapAttributes() method
<b>Signature:</b>
```typescript
wrapAttributes(newAttributes: SavedObjectAttributes, useRefType: boolean, input?: ValType | RefType): Promise<Omit<ValType | RefType, 'id'>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| newAttributes | <code>SavedObjectAttributes</code> | |
| useRefType | <code>boolean</code> | |
| input | <code>ValType &#124; RefType</code> | |
<b>Returns:</b>
`Promise<Omit<ValType | RefType, 'id'>>`

View file

@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [EmbeddableStart](./kibana-plugin-plugins-embeddable-public.embeddablestart.md) &gt; [getAttributeService](./kibana-plugin-plugins-embeddable-public.embeddablestart.getattributeservice.md)
## EmbeddableStart.getAttributeService property
<b>Signature:</b>
```typescript
getAttributeService: <A extends {
title: string;
}, V extends EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
} = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
}, R extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput>(type: string, options: AttributeServiceOptions<A>) => AttributeService<A, V, R>;
```

View file

@ -15,6 +15,7 @@ export interface EmbeddableStart extends PersistableState<EmbeddableInput>
| Property | Type | Description |
| --- | --- | --- |
| [EmbeddablePanel](./kibana-plugin-plugins-embeddable-public.embeddablestart.embeddablepanel.md) | <code>EmbeddablePanelHOC</code> | |
| [getAttributeService](./kibana-plugin-plugins-embeddable-public.embeddablestart.getattributeservice.md) | <code>&lt;A extends {</code><br/><code> title: string;</code><br/><code> }, V extends EmbeddableInput &amp; {</code><br/><code> [ATTRIBUTE_SERVICE_KEY]: A;</code><br/><code> } = EmbeddableInput &amp; {</code><br/><code> [ATTRIBUTE_SERVICE_KEY]: A;</code><br/><code> }, R extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput&gt;(type: string, options: AttributeServiceOptions&lt;A&gt;) =&gt; AttributeService&lt;A, V, R&gt;</code> | |
| [getEmbeddableFactories](./kibana-plugin-plugins-embeddable-public.embeddablestart.getembeddablefactories.md) | <code>() =&gt; IterableIterator&lt;EmbeddableFactory&gt;</code> | |
| [getEmbeddableFactory](./kibana-plugin-plugins-embeddable-public.embeddablestart.getembeddablefactory.md) | <code>&lt;I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, E extends IEmbeddable&lt;I, O&gt; = IEmbeddable&lt;I, O&gt;&gt;(embeddableFactoryId: string) =&gt; EmbeddableFactory&lt;I, O, E&gt; &#124; undefined</code> | |
| [getEmbeddablePanel](./kibana-plugin-plugins-embeddable-public.embeddablestart.getembeddablepanel.md) | <code>(stateTransfer?: EmbeddableStateTransfer) =&gt; EmbeddablePanelHOC</code> | |

View file

@ -9,6 +9,7 @@
| Class | Description |
| --- | --- |
| [AddPanelAction](./kibana-plugin-plugins-embeddable-public.addpanelaction.md) | |
| [AttributeService](./kibana-plugin-plugins-embeddable-public.attributeservice.md) | |
| [Container](./kibana-plugin-plugins-embeddable-public.container.md) | |
| [EditPanelAction](./kibana-plugin-plugins-embeddable-public.editpanelaction.md) | |
| [Embeddable](./kibana-plugin-plugins-embeddable-public.embeddable.md) | |
@ -71,6 +72,7 @@
| --- | --- |
| [ACTION\_ADD\_PANEL](./kibana-plugin-plugins-embeddable-public.action_add_panel.md) | |
| [ACTION\_EDIT\_PANEL](./kibana-plugin-plugins-embeddable-public.action_edit_panel.md) | |
| [ATTRIBUTE\_SERVICE\_KEY](./kibana-plugin-plugins-embeddable-public.attribute_service_key.md) | The attribute service is a shared, generic service that embeddables can use to provide the functionality required to fulfill the requirements of the ReferenceOrValueEmbeddable interface. The attribute\_service can also be used as a higher level wrapper to transform an embeddable input shape that references a saved object into an embeddable input shape that contains that saved object's attributes by value. |
| [CONTEXT\_MENU\_TRIGGER](./kibana-plugin-plugins-embeddable-public.context_menu_trigger.md) | |
| [contextMenuTrigger](./kibana-plugin-plugins-embeddable-public.contextmenutrigger.md) | |
| [defaultEmbeddableFactoryProvider](./kibana-plugin-plugins-embeddable-public.defaultembeddablefactoryprovider.md) | |

View file

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-server](./kibana-plugin-plugins-embeddable-server.md) &gt; [EmbeddableSetup](./kibana-plugin-plugins-embeddable-server.embeddablesetup.md) &gt; [getAttributeService](./kibana-plugin-plugins-embeddable-server.embeddablesetup.getattributeservice.md)
## EmbeddableSetup.getAttributeService property
<b>Signature:</b>
```typescript
getAttributeService: any;
```

View file

@ -14,6 +14,7 @@ export interface EmbeddableSetup
| Property | Type | Description |
| --- | --- | --- |
| [getAttributeService](./kibana-plugin-plugins-embeddable-server.embeddablesetup.getattributeservice.md) | <code>any</code> | |
| [registerEmbeddableFactory](./kibana-plugin-plugins-embeddable-server.embeddablesetup.registerembeddablefactory.md) | <code>(factory: EmbeddableRegistryDefinition) =&gt; void</code> | |
| [registerEnhancement](./kibana-plugin-plugins-embeddable-server.embeddablesetup.registerenhancement.md) | <code>(enhancement: EnhancementRegistryDefinition) =&gt; void</code> | |

View file

@ -4,7 +4,7 @@
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["embeddable", "uiActions", "dashboard", "savedObjects"],
"requiredPlugins": ["embeddable", "uiActions", "savedObjects", "dashboard"],
"optionalPlugins": [],
"extraPublicDirs": ["public/todo", "public/hello_world", "public/todo/todo_ref_embeddable"],
"requiredBundles": ["kibanaReact"]

View file

@ -26,10 +26,10 @@ import {
EmbeddableOutput,
SavedObjectEmbeddableInput,
ReferenceOrValueEmbeddable,
AttributeService,
} from '../../../../src/plugins/embeddable/public';
import { BookSavedObjectAttributes } from '../../common';
import { BookEmbeddableComponent } from './book_component';
import { AttributeService } from '../../../../src/plugins/dashboard/public';
export const BOOK_EMBEDDABLE = 'book';
export type BookEmbeddableInput = BookByValueInput | BookByReferenceInput;

View file

@ -25,6 +25,8 @@ import {
EmbeddableFactoryDefinition,
IContainer,
EmbeddableFactory,
EmbeddableStart,
AttributeService,
} from '../../../../src/plugins/embeddable/public';
import {
BookEmbeddable,
@ -38,11 +40,10 @@ import {
SavedObjectsClientContract,
SimpleSavedObject,
} from '../../../../src/core/public';
import { DashboardStart, AttributeService } from '../../../../src/plugins/dashboard/public';
import { checkForDuplicateTitle, OnSaveProps } from '../../../../src/plugins/saved_objects/public';
interface StartServices {
getAttributeService: DashboardStart['getAttributeService'];
getAttributeService: EmbeddableStart['getAttributeService'];
openModal: OverlayStart['openModal'];
savedObjectsClient: SavedObjectsClientContract;
overlays: OverlayStart;

View file

@ -22,7 +22,11 @@ import { i18n } from '@kbn/i18n';
import { BookSavedObjectAttributes, BOOK_SAVED_OBJECT } from '../../common';
import { createAction } from '../../../../src/plugins/ui_actions/public';
import { toMountPoint } from '../../../../src/plugins/kibana_react/public';
import { ViewMode, SavedObjectEmbeddableInput } from '../../../../src/plugins/embeddable/public';
import {
ViewMode,
SavedObjectEmbeddableInput,
EmbeddableStart,
} from '../../../../src/plugins/embeddable/public';
import {
BookEmbeddable,
BOOK_EMBEDDABLE,
@ -30,13 +34,12 @@ import {
BookByValueInput,
} from './book_embeddable';
import { CreateEditBookComponent } from './create_edit_book_component';
import { DashboardStart } from '../../../../src/plugins/dashboard/public';
import { OnSaveProps } from '../../../../src/plugins/saved_objects/public';
import { SavedObjectsClientContract } from '../../../../src/core/target/types/public/saved_objects';
interface StartServices {
openModal: OverlayStart['openModal'];
getAttributeService: DashboardStart['getAttributeService'];
getAttributeService: EmbeddableStart['getAttributeService'];
savedObjectsClient: SavedObjectsClientContract;
}

View file

@ -62,7 +62,6 @@ import {
ACTION_ADD_BOOK_TO_LIBRARY,
createAddBookToLibraryAction,
} from './book/add_book_to_library_action';
import { DashboardStart } from '../../../src/plugins/dashboard/public';
import {
ACTION_UNLINK_BOOK_FROM_LIBRARY,
createUnlinkBookFromLibraryAction,
@ -75,7 +74,6 @@ export interface EmbeddableExamplesSetupDependencies {
export interface EmbeddableExamplesStartDependencies {
embeddable: EmbeddableStart;
dashboard: DashboardStart;
savedObjectsClient: SavedObjectsClient;
}
@ -157,7 +155,7 @@ export class EmbeddableExamplesPlugin
this.exampleEmbeddableFactories.getBookEmbeddableFactory = deps.embeddable.registerEmbeddableFactory(
BOOK_EMBEDDABLE,
new BookEmbeddableFactoryDefinition(async () => ({
getAttributeService: (await core.getStartServices())[1].dashboard.getAttributeService,
getAttributeService: (await core.getStartServices())[1].embeddable.getAttributeService,
openModal: (await core.getStartServices())[0].overlays.openModal,
savedObjectsClient: (await core.getStartServices())[0].savedObjects.client,
overlays: (await core.getStartServices())[0].overlays,
@ -165,7 +163,7 @@ export class EmbeddableExamplesPlugin
);
const editBookAction = createEditBookAction(async () => ({
getAttributeService: (await core.getStartServices())[1].dashboard.getAttributeService,
getAttributeService: (await core.getStartServices())[1].embeddable.getAttributeService,
openModal: (await core.getStartServices())[0].overlays.openModal,
savedObjectsClient: (await core.getStartServices())[0].savedObjects.client,
}));

View file

@ -45,7 +45,6 @@ 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';
export function plugin(initializerContext: PluginInitializerContext) {
return new DashboardPlugin(initializerContext);

View file

@ -20,13 +20,10 @@
import { DashboardStart } from './plugin';
export type Start = jest.Mocked<DashboardStart>;
export { mockAttributeService } from './attribute_service/attribute_service.mock';
const createStartContract = (): DashboardStart => {
// @ts-ignore
const startContract: DashboardStart = {
getAttributeService: jest.fn(),
};
const startContract: DashboardStart = {};
return startContract;
};

View file

@ -39,8 +39,6 @@ import {
CONTEXT_MENU_TRIGGER,
EmbeddableSetup,
EmbeddableStart,
SavedObjectEmbeddableInput,
EmbeddableInput,
PANEL_NOTIFICATION_TRIGGER,
} from '../../embeddable/public';
import { DataPublicPluginSetup, DataPublicPluginStart, esFilters } from '../../data/public';
@ -53,7 +51,6 @@ import {
getSavedObjectFinder,
SavedObjectLoader,
SavedObjectsStart,
showSaveModal,
} from '../../saved_objects/public';
import {
ExitFullScreenButton as ExitFullScreenButtonUi,
@ -103,11 +100,6 @@ import { DashboardConstants } from './dashboard_constants';
import { addEmbeddableToDashboardUrl } from './url_utils/url_helper';
import { PlaceholderEmbeddableFactory } from './application/embeddable/placeholder';
import { UrlGeneratorState } from '../../share/public';
import { AttributeService } from '.';
import {
AttributeServiceOptions,
ATTRIBUTE_SERVICE_KEY,
} from './attribute_service/attribute_service';
declare module '../../share/public' {
export interface UrlGeneratorStateMapping {
@ -156,16 +148,6 @@ export interface DashboardStart {
dashboardUrlGenerator?: DashboardUrlGenerator;
dashboardFeatureFlagConfig: DashboardFeatureFlagConfig;
DashboardContainerByValueRenderer: ReturnType<typeof createDashboardContainerByValueRenderer>;
getAttributeService: <
A extends { title: string },
V extends EmbeddableInput & { [ATTRIBUTE_SERVICE_KEY]: A } = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
},
R extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput
>(
type: string,
options: AttributeServiceOptions<A>
) => AttributeService<A, V, R>;
}
declare module '../../../plugins/ui_actions/public' {
@ -433,7 +415,6 @@ export class DashboardPlugin
const {
uiActions,
data: { indexPatterns, search },
embeddable,
} = plugins;
const SavedObjectFinder = getSavedObjectFinder(core.savedObjects, core.uiSettings);
@ -483,15 +464,6 @@ export class DashboardPlugin
DashboardContainerByValueRenderer: createDashboardContainerByValueRenderer({
factory: dashboardContainerFactory,
}),
getAttributeService: (type: string, options) =>
new AttributeService(
type,
showSaveModal,
core.i18n.Context,
core.notifications.toasts,
options,
embeddable.getEmbeddableFactory
),
};
}

View file

@ -77,6 +77,8 @@ export {
EmbeddableRendererProps,
} from './lib';
export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './lib/attribute_service';
export { EnhancementRegistryDefinition } from './types';
export function plugin(initializerContext: PluginInitializerContext) {

View file

@ -17,11 +17,11 @@
* under the License.
*/
import { EmbeddableInput, SavedObjectEmbeddableInput } from '../embeddable_plugin';
import { coreMock } from '../../../../core/public/mocks';
import { EmbeddableInput, SavedObjectEmbeddableInput } from '../index';
import { coreMock } from '../../../../../core/public/mocks';
import { AttributeServiceOptions } from './attribute_service';
import { CoreStart } from '../../../../core/public';
import { AttributeService, ATTRIBUTE_SERVICE_KEY } from '..';
import { CoreStart } from 'src/core/public';
import { AttributeService, ATTRIBUTE_SERVICE_KEY } from './index';
export const mockAttributeService = <
A extends { title: string },

View file

@ -19,8 +19,8 @@
import { ATTRIBUTE_SERVICE_KEY } from './attribute_service';
import { mockAttributeService } from './attribute_service.mock';
import { coreMock } from '../../../../core/public/mocks';
import { OnSaveProps } from '../../../saved_objects/public/save_modal';
import { coreMock } from '../../../../../core/public/mocks';
import { OnSaveProps } from 'src/plugins/saved_objects/public/save_modal';
interface TestAttributes {
title: string;

View file

@ -20,17 +20,17 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
import { I18nStart, NotificationsStart } from 'src/core/public';
import { SavedObjectSaveModal, OnSaveProps, SaveResult } from '../../../../saved_objects/public';
import {
EmbeddableInput,
SavedObjectEmbeddableInput,
isSavedObjectEmbeddableInput,
IEmbeddable,
Container,
EmbeddableStart,
EmbeddableFactoryNotFoundError,
} from '../embeddable_plugin';
import { I18nStart, NotificationsStart } from '../../../../core/public';
import { SavedObjectSaveModal, OnSaveProps, SaveResult } from '../../../saved_objects/public';
EmbeddableFactory,
} from '../index';
/**
* The attribute service is a shared, generic service that embeddables can use to provide the functionality
@ -66,7 +66,7 @@ export class AttributeService<
private i18nContext: I18nStart['Context'],
private toasts: NotificationsStart['toasts'],
private options: AttributeServiceOptions<SavedObjectAttributes>,
getEmbeddableFactory?: EmbeddableStart['getEmbeddableFactory']
getEmbeddableFactory?: (embeddableFactoryId: string) => EmbeddableFactory
) {
if (getEmbeddableFactory) {
const factory = getEmbeddableFactory(this.type);
@ -113,7 +113,7 @@ export class AttributeService<
return { ...originalInput } as RefType;
} catch (error) {
this.toasts.addDanger({
title: i18n.translate('dashboard.attributeService.saveToLibraryError', {
title: i18n.translate('embeddableApi.attributeService.saveToLibraryError', {
defaultMessage: `Panel was not saved to the library. Error: {errorMessage}`,
values: {
errorMessage: error.message,

View file

@ -39,6 +39,7 @@ import { dataPluginMock } from '../../data/public/mocks';
import { inspectorPluginMock } from '../../inspector/public/mocks';
import { uiActionsPluginMock } from '../../ui_actions/public/mocks';
export { mockAttributeService } from './lib/attribute_service/attribute_service.mock';
export type Setup = jest.Mocked<EmbeddableSetup>;
export type Start = jest.Mocked<EmbeddableStart>;
@ -125,6 +126,7 @@ const createStartContract = (): Start => {
EmbeddablePanel: jest.fn(),
getEmbeddablePanel: jest.fn(),
getStateTransfer: jest.fn(() => createEmbeddableStateTransferMock() as EmbeddableStateTransfer),
getAttributeService: jest.fn(),
};
return startContract;
};

View file

@ -20,7 +20,7 @@ import React from 'react';
import { Subscription } from 'rxjs';
import { identity } from 'lodash';
import { DataPublicPluginSetup, DataPublicPluginStart } from '../../data/public';
import { getSavedObjectFinder } from '../../saved_objects/public';
import { getSavedObjectFinder, showSaveModal } from '../../saved_objects/public';
import { UiActionsSetup, UiActionsStart } from '../../ui_actions/public';
import { Start as InspectorStart } from '../../inspector/public';
import {
@ -47,6 +47,7 @@ import {
defaultEmbeddableFactoryProvider,
IEmbeddable,
EmbeddablePanel,
SavedObjectEmbeddableInput,
} from './lib';
import { EmbeddableFactoryDefinition } from './lib/embeddables/embeddable_factory_definition';
import { EmbeddableStateTransfer } from './lib/state_transfer';
@ -56,6 +57,8 @@ import {
telemetryBaseEmbeddableInput,
} from '../common/lib/migrate_base_input';
import { PersistableState, SerializableState } from '../../kibana_utils/common';
import { ATTRIBUTE_SERVICE_KEY, AttributeService } from './lib/attribute_service';
import { AttributeServiceOptions } from './lib/attribute_service/attribute_service';
export interface EmbeddableSetupDependencies {
data: DataPublicPluginSetup;
@ -93,6 +96,16 @@ export interface EmbeddableStart extends PersistableState<EmbeddableInput> {
EmbeddablePanel: EmbeddablePanelHOC;
getEmbeddablePanel: (stateTransfer?: EmbeddableStateTransfer) => EmbeddablePanelHOC;
getStateTransfer: (history?: ScopedHistory) => EmbeddableStateTransfer;
getAttributeService: <
A extends { title: string },
V extends EmbeddableInput & { [ATTRIBUTE_SERVICE_KEY]: A } = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
},
R extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput
>(
type: string,
options: AttributeServiceOptions<A>
) => AttributeService<A, V, R>;
}
export type EmbeddablePanelHOC = React.FC<{ embeddable: IEmbeddable; hideHeader?: boolean }>;
@ -178,6 +191,15 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
return {
getEmbeddableFactory: this.getEmbeddableFactory,
getEmbeddableFactories: this.getEmbeddableFactories,
getAttributeService: (type: string, options) =>
new AttributeService(
type,
showSaveModal,
core.i18n.Context,
core.notifications.toasts,
options,
this.getEmbeddableFactory
),
getStateTransfer: (history?: ScopedHistory) => {
return history
? new EmbeddableStateTransfer(core.application.navigateToApp, history, this.appList)

View file

@ -31,6 +31,7 @@ import { ExclusiveUnion } from '@elastic/eui';
import { ExpressionAstFunction } from 'src/plugins/expressions/common';
import { History } from 'history';
import { Href } from 'history';
import { I18nStart as I18nStart_2 } from 'src/core/public';
import { IconType } from '@elastic/eui';
import { ISearchOptions } from 'src/plugins/data/public';
import { ISearchSource } from 'src/plugins/data/public';
@ -119,6 +120,42 @@ export class AddPanelAction implements Action_3<ActionContext_2> {
readonly type = "ACTION_ADD_PANEL";
}
// Warning: (ae-missing-release-tag) "ATTRIBUTE_SERVICE_KEY" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const ATTRIBUTE_SERVICE_KEY = "attributes";
// Warning: (ae-missing-release-tag) "AttributeService" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class AttributeService<SavedObjectAttributes extends {
title: string;
}, ValType extends EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: SavedObjectAttributes;
} = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: SavedObjectAttributes;
}, RefType extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput> {
// Warning: (ae-forgotten-export) The symbol "AttributeServiceOptions" needs to be exported by the entry point index.d.ts
constructor(type: string, showSaveModal: (saveModal: React.ReactElement, I18nContext: I18nStart_2['Context']) => void, i18nContext: I18nStart_2['Context'], toasts: NotificationsStart_2['toasts'], options: AttributeServiceOptions<SavedObjectAttributes>, getEmbeddableFactory?: (embeddableFactoryId: string) => EmbeddableFactory);
// (undocumented)
getExplicitInputFromEmbeddable(embeddable: IEmbeddable): ValType | RefType;
// (undocumented)
getInputAsRefType: (input: ValType | RefType, saveOptions?: {
showSaveModal: boolean;
saveModalTitle?: string | undefined;
} | {
title: string;
} | undefined) => Promise<RefType>;
// (undocumented)
getInputAsValueType: (input: ValType | RefType) => Promise<ValType>;
// (undocumented)
inputIsRefType: (input: ValType | RefType) => input is RefType;
// (undocumented)
unwrapAttributes(input: RefType | ValType): Promise<SavedObjectAttributes>;
// (undocumented)
wrapAttributes(newAttributes: SavedObjectAttributes, useRefType: boolean, input?: ValType | RefType): Promise<Omit<ValType | RefType, 'id'>>;
}
// Warning: (ae-missing-release-tag) "ChartActionContext" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
@ -527,6 +564,14 @@ export interface EmbeddableStart extends PersistableState<EmbeddableInput> {
// (undocumented)
EmbeddablePanel: EmbeddablePanelHOC;
// (undocumented)
getAttributeService: <A extends {
title: string;
}, V extends EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
} = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
}, R extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput>(type: string, options: AttributeServiceOptions<A>) => AttributeService<A, V, R>;
// (undocumented)
getEmbeddableFactories: () => IterableIterator<EmbeddableFactory>;
// (undocumented)
getEmbeddableFactory: <I extends EmbeddableInput = EmbeddableInput, O extends EmbeddableOutput = EmbeddableOutput, E extends IEmbeddable<I, O> = IEmbeddable<I, O>>(embeddableFactoryId: string) => EmbeddableFactory<I, O, E> | undefined;

View file

@ -35,6 +35,7 @@ import { SerializableState } from '../../kibana_utils/common';
import { EmbeddableInput } from '../common/types';
export interface EmbeddableSetup {
getAttributeService: any;
registerEmbeddableFactory: (factory: EmbeddableRegistryDefinition) => void;
registerEnhancement: (enhancement: EnhancementRegistryDefinition) => void;
}

View file

@ -23,6 +23,8 @@ export interface EmbeddableRegistryDefinition<P extends EmbeddableInput = Embedd
//
// @public (undocumented)
export interface EmbeddableSetup {
// (undocumented)
getAttributeService: any;
// (undocumented)
registerEmbeddableFactory: (factory: EmbeddableRegistryDefinition) => void;
// (undocumented)

View file

@ -3,7 +3,7 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["data", "expressions", "uiActions", "embeddable", "inspector", "dashboard"],
"requiredPlugins": ["data", "expressions", "uiActions", "embeddable", "inspector" ],
"optionalPlugins": ["usageCollection"],
"requiredBundles": ["kibanaUtils", "discover", "savedObjects"]
}

View file

@ -25,7 +25,11 @@ import {
VisualizeByReferenceInput,
VisualizeSavedObjectAttributes,
} from './visualize_embeddable';
import { IContainer, ErrorEmbeddable } from '../../../../plugins/embeddable/public';
import {
IContainer,
ErrorEmbeddable,
AttributeService,
} from '../../../../plugins/embeddable/public';
import { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import {
getSavedVisualizationsLoader,
@ -37,7 +41,6 @@ import {
import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants';
import { SavedVisualizationsLoader } from '../saved_visualizations';
import { AttributeService } from '../../../dashboard/public';
export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDeps) => async (
vis: Vis,

View file

@ -38,6 +38,7 @@ import {
Adapters,
SavedObjectEmbeddableInput,
ReferenceOrValueEmbeddable,
AttributeService,
} from '../../../../plugins/embeddable/public';
import {
IExpressionLoaderParams,
@ -51,7 +52,6 @@ import { VIS_EVENT_TO_TRIGGER } from './events';
import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { TriggerId } from '../../../ui_actions/public';
import { SavedObjectAttributes } from '../../../../core/types';
import { AttributeService } from '../../../dashboard/public';
import { SavedVisualizationsLoader } from '../saved_visualizations';
import { VisSavedObject } from '../types';

View file

@ -26,6 +26,7 @@ import {
EmbeddableOutput,
ErrorEmbeddable,
IContainer,
AttributeService,
} from '../../../embeddable/public';
import { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import {
@ -50,7 +51,6 @@ import { createVisEmbeddableFromObject } from './create_vis_embeddable_from_obje
import { StartServicesGetter } from '../../../kibana_utils/public';
import { VisualizationsStartDeps } from '../plugin';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants';
import { AttributeService } from '../../../dashboard/public';
import { checkForDuplicateTitle } from '../../../saved_objects/public';
interface VisualizationAttributes extends SavedObjectAttributes {
@ -126,7 +126,7 @@ export class VisualizeEmbeddableFactory
if (!this.attributeService) {
this.attributeService = await this.deps
.start()
.plugins.dashboard.getAttributeService<
.plugins.embeddable.getAttributeService<
VisualizeSavedObjectAttributes,
VisualizeByValueInput,
VisualizeByReferenceInput

View file

@ -112,7 +112,7 @@ export interface VisualizationsStartDeps {
uiActions: UiActionsStart;
application: ApplicationStart;
dashboard: DashboardStart;
getAttributeService: DashboardStart['getAttributeService'];
getAttributeService: EmbeddableStart['getAttributeService'];
savedObjectsClient: SavedObjectsClientContract;
}

View file

@ -12,9 +12,10 @@
"visualizations",
"dashboard",
"charts",
"uiActions"
"uiActions",
"embeddable"
],
"optionalPlugins": ["embeddable", "usageCollection", "taskManager", "globalSearch"],
"optionalPlugins": ["usageCollection", "taskManager", "globalSearch"],
"configPath": ["xpack", "lens"],
"extraPublicDirs": ["common/constants"],
"requiredBundles": ["savedObjects", "kibanaUtils", "kibanaReact", "embeddable"]

View file

@ -36,7 +36,7 @@ import {
LensByReferenceInput,
} from '../editor_frame_service/embeddable/embeddable';
import { SavedObjectReference } from '../../../../../src/core/types';
import { mockAttributeService } from '../../../../../src/plugins/dashboard/public/mocks';
import { mockAttributeService } from '../../../../../src/plugins/embeddable/public/mocks';
import { LensAttributeService } from '../lens_attribute_service';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';

View file

@ -25,7 +25,7 @@ import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'
import { VIS_EVENT_TO_TRIGGER } from '../../../../../../src/plugins/visualizations/public/embeddable';
import { coreMock, httpServiceMock } from '../../../../../../src/core/public/mocks';
import { IBasePath } from '../../../../../../src/core/public';
import { AttributeService } from '../../../../../../src/plugins/dashboard/public';
import { AttributeService } from '../../../../../../src/plugins/embeddable/public';
import { LensAttributeService } from '../../lens_attribute_service';
import { OnSaveProps } from '../../../../../../src/plugins/saved_objects/public/save_modal';

View file

@ -6,7 +6,7 @@
import { CoreStart } from '../../../../src/core/public';
import { LensPluginStartDependencies } from './plugin';
import { AttributeService } from '../../../../src/plugins/dashboard/public';
import { AttributeService } from '../../../../src/plugins/embeddable/public';
import {
LensSavedObjectAttributes,
LensByValueInput,
@ -26,7 +26,7 @@ export function getLensAttributeService(
startDependencies: LensPluginStartDependencies
): LensAttributeService {
const savedObjectStore = new SavedObjectIndexStore(core.savedObjects.client);
return startDependencies.dashboard.getAttributeService<
return startDependencies.embeddable.getAttributeService<
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput

View file

@ -58,7 +58,7 @@ export interface LensPluginStartDependencies {
navigation: NavigationPublicPluginStart;
uiActions: UiActionsStart;
dashboard: DashboardStart;
embeddable?: EmbeddableStart;
embeddable: EmbeddableStart;
}
export class LensPlugin {
private datatableVisualization: DatatableVisualization;