Skip to content

Commit

Permalink
[embeddable] remove getAttributeService from start API (elastic#203660)
Browse files Browse the repository at this point in the history
Part of embeddable refactor cleanup

AttributeService is moved from embeddable plugin to visualizations
plugin.

PR reduces visualizations bundle size by avoiding importing
`legacy/embeddable/index.ts` in plugin page load

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent d9f8f17 commit 9ce5239
Show file tree
Hide file tree
Showing 23 changed files with 31 additions and 316 deletions.
2 changes: 1 addition & 1 deletion src/plugins/embeddable/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"contentManagement"
],
"optionalPlugins": ["savedObjectsTaggingOss", "usageCollection"],
"requiredBundles": ["savedObjects", "kibanaUtils", "presentationPanel"],
"requiredBundles": ["kibanaUtils", "presentationPanel"],
"extraPublicDirs": ["common"]
}
}
1 change: 0 additions & 1 deletion src/plugins/embeddable/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export type {
SelfStyledEmbeddable,
ValueClickContext,
} from './lib';
export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './lib/attribute_service';
export type {
EmbeddableSetup,
EmbeddableSetupDependencies,
Expand Down

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/plugins/embeddable/public/lib/attribute_service/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/plugins/embeddable/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { EmbeddablePublicPlugin } from './plugin';
import { registerReactEmbeddableFactory } from './react_embeddable_system';
import { registerAddFromLibraryType } from './add_from_library/registry';

export { mockAttributeService } from './lib/attribute_service/attribute_service.mock';
export type Setup = jest.Mocked<EmbeddableSetup>;
export type Start = jest.Mocked<EmbeddableStart>;

Expand Down Expand Up @@ -114,7 +113,6 @@ const createStartContract = (): Start => {
inject: jest.fn(),
getAllMigrations: jest.fn(),
getStateTransfer: jest.fn(() => createEmbeddableStateTransferMock() as EmbeddableStateTransfer),
getAttributeService: jest.fn(),
};
return startContract;
};
Expand Down
18 changes: 0 additions & 18 deletions src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ import {
EmbeddableOutput,
defaultEmbeddableFactoryProvider,
IEmbeddable,
SavedObjectEmbeddableInput,
} from './lib';
import { EmbeddableFactoryDefinition } from './lib/embeddables/embeddable_factory_definition';
import { EmbeddableStateTransfer } from './lib/state_transfer';
import { ATTRIBUTE_SERVICE_KEY, AttributeService } from './lib/attribute_service';
import { AttributeServiceOptions } from './lib/attribute_service/attribute_service';
import { EmbeddableStateWithType, CommonEmbeddableStartContract } from '../common/types';
import {
getExtractFunction,
Expand Down Expand Up @@ -134,19 +131,6 @@ export interface EmbeddableStart extends PersistableStateService<EmbeddableState
*/
getEmbeddableFactories: () => IterableIterator<EmbeddableFactory>;
getStateTransfer: (storage?: Storage) => EmbeddableStateTransfer;
getAttributeService: <
A extends { title: string },
V extends EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
} = EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: A;
},
R extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput,
M extends unknown = unknown
>(
type: string,
options: AttributeServiceOptions<A, M>
) => AttributeService<A, V, R, M>;
}
export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, EmbeddableStart> {
private readonly embeddableFactoryDefinitions: Map<string, EmbeddableFactoryDefinition> =
Expand Down Expand Up @@ -218,8 +202,6 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
const embeddableStart: EmbeddableStart = {
getEmbeddableFactory: this.getEmbeddableFactory,
getEmbeddableFactories: this.getEmbeddableFactories,
getAttributeService: (type: string, options) =>
new AttributeService(type, core.notifications.toasts, options, this.getEmbeddableFactory),
getStateTransfer: (storage?: Storage) =>
storage
? new EmbeddableStateTransfer(
Expand Down
1 change: 0 additions & 1 deletion src/plugins/embeddable/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"kbn_references": [
"@kbn/core",
"@kbn/inspector-plugin",
"@kbn/saved-objects-plugin",
"@kbn/kibana-utils-plugin",
"@kbn/ui-actions-plugin",
"@kbn/utility-types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@
*/

import { contentManagementMock } from '@kbn/content-management-plugin/public/mocks';
import { coreMock } from '@kbn/core/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { AttributeService, type EmbeddableStart } from '@kbn/embeddable-plugin/public';
import { spacesPluginMock } from '@kbn/spaces-plugin/public/mocks';
import { SavedSearchByValueAttributes, byValueToSavedSearch } from '.';

const mockServices = {
contentManagement: contentManagementMock.createStartContract().client,
search: dataPluginMock.createStartContract().search,
spaces: spacesPluginMock.createStartContract(),
embeddable: {
getAttributeService: jest.fn(
(_, opts) => new AttributeService('search', coreMock.createStart().notifications.toasts, opts)
),
} as unknown as EmbeddableStart,
};

describe('toSavedSearch', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
import { Action } from '@kbn/ui-actions-plugin/public';
import React from 'react';
import { take } from 'rxjs';
import { apiHasVisualizeConfig, HasVisualizeConfig } from '../legacy/embeddable';
import {
apiHasVisualizeConfig,
type HasVisualizeConfig,
} from '../embeddable/interfaces/has_visualize_config';
import {
apiHasExpressionVariables,
HasExpressionVariables,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
SerializedTitles,
} from '@kbn/presentation-publishing';
import { DeepPartial } from '@kbn/utility-types';
import { HasVisualizeConfig } from '../legacy/embeddable';
import type { HasVisualizeConfig } from './interfaces/has_visualize_config';
import type { Vis, VisParams, VisSavedObject } from '../types';
import type { SerializedVis } from '../vis';

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function plugin(initializerContext: PluginInitializerContext) {
/** @public static code */
export { TypesService } from './vis_types/types_service';
export { VIS_EVENT_TO_TRIGGER } from './embeddable';
export { apiHasVisualizeConfig, COMMON_VISUALIZATION_GROUPING } from './legacy/embeddable';
export { apiHasVisualizeConfig } from './embeddable/interfaces/has_visualize_config';
export { COMMON_VISUALIZATION_GROUPING } from './legacy/embeddable/constants';
export { VisualizationContainer } from './components';
export { getVisSchemas } from './vis_schemas';

Expand All @@ -41,7 +42,8 @@ export type VisualizeEmbeddableFactoryContract = PublicContract<VisualizeEmbedda
export type VisualizeEmbeddableContract = PublicContract<VisualizeEmbeddable>;
export type { SchemaConfig } from '../common/types';
export { updateOldState } from './legacy/vis_update_state';
export type { VisualizeInput, VisualizeEmbeddable, HasVisualizeConfig } from './legacy/embeddable';
export type { VisualizeInput, VisualizeEmbeddable } from './legacy/embeddable';
export type { HasVisualizeConfig } from './embeddable/interfaces/has_visualize_config';
export type { PersistedState } from './persisted_state';
export type {
ISavedVis,
Expand Down
Loading

0 comments on commit 9ce5239

Please sign in to comment.