Skip to content

Commit

Permalink
[Refactor] Move AttributeService from Dashboard to Embeddable plugin (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
# 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
  • Loading branch information
Maja Grubic authored Oct 13, 2020
1 parent 168c317 commit cc3b7b2
Show file tree
Hide file tree
Showing 42 changed files with 335 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -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"
```
Original file line number Diff line number Diff line change
@@ -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> | |

Original file line number Diff line number Diff line change
@@ -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`

Original file line number Diff line number Diff line change
@@ -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>;
```
Original file line number Diff line number Diff line change
@@ -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>;
```
Original file line number Diff line number Diff line change
@@ -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;
```
Original file line number Diff line number Diff line change
@@ -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) | | |

Original file line number Diff line number Diff line change
@@ -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>`

Original file line number Diff line number Diff line change
@@ -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'>>`

Original file line number Diff line number Diff line change
@@ -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>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -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> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) | |
Expand Down Expand Up @@ -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) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
```
Original file line number Diff line number Diff line change
Expand Up @@ -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> | |

2 changes: 1 addition & 1 deletion examples/embeddable_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
EmbeddableFactoryDefinition,
IContainer,
EmbeddableFactory,
EmbeddableStart,
AttributeService,
} from '../../../../src/plugins/embeddable/public';
import {
BookEmbeddable,
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions examples/embeddable_examples/public/book/edit_book_action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ 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,
BookByReferenceInput,
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;
}

Expand Down
6 changes: 2 additions & 4 deletions examples/embeddable_examples/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,7 +74,6 @@ export interface EmbeddableExamplesSetupDependencies {

export interface EmbeddableExamplesStartDependencies {
embeddable: EmbeddableStart;
dashboard: DashboardStart;
savedObjectsClient: SavedObjectsClient;
}

Expand Down Expand Up @@ -157,15 +155,15 @@ 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,
}))
);

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,
}));
Expand Down
1 change: 0 additions & 1 deletion src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/dashboard/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading

0 comments on commit cc3b7b2

Please sign in to comment.