From 9ce523939279bdeba399b447849db47fa0877a23 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 12 Dec 2024 08:38:11 -0700 Subject: [PATCH] [embeddable] remove getAttributeService from start API (#203660) 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 <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine --- src/plugins/embeddable/kibana.jsonc | 2 +- src/plugins/embeddable/public/index.ts | 1 - .../attribute_service.mock.tsx | 35 ---- .../attribute_service.test.ts | 196 ------------------ .../public/lib/attribute_service/index.ts | 10 - src/plugins/embeddable/public/mocks.tsx | 2 - src/plugins/embeddable/public/plugin.tsx | 18 -- src/plugins/embeddable/tsconfig.json | 1 - .../saved_searches/to_saved_search.test.ts | 7 - .../public/actions/edit_in_lens_action.tsx | 5 +- .../visualizations/public/embeddable/types.ts | 2 +- src/plugins/visualizations/public/index.ts | 6 +- .../legacy/embeddable}/attribute_service.tsx | 27 +-- .../create_vis_embeddable_from_object.ts | 3 +- .../public/legacy/embeddable/index.ts | 4 - .../embeddable/visualize_embeddable.tsx | 2 +- .../visualize_embeddable_factory.tsx | 16 +- src/plugins/visualizations/public/plugin.ts | 2 + src/plugins/visualizations/public/services.ts | 3 + .../utils/get_visualization_instance.ts | 2 +- .../translations/translations/fr-FR.json | 1 - .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - 23 files changed, 31 insertions(+), 316 deletions(-) delete mode 100644 src/plugins/embeddable/public/lib/attribute_service/attribute_service.mock.tsx delete mode 100644 src/plugins/embeddable/public/lib/attribute_service/attribute_service.test.ts delete mode 100644 src/plugins/embeddable/public/lib/attribute_service/index.ts rename src/plugins/{embeddable/public/lib/attribute_service => visualizations/public/legacy/embeddable}/attribute_service.tsx (90%) diff --git a/src/plugins/embeddable/kibana.jsonc b/src/plugins/embeddable/kibana.jsonc index ea198de6386a3..8a012aefbc30b 100644 --- a/src/plugins/embeddable/kibana.jsonc +++ b/src/plugins/embeddable/kibana.jsonc @@ -18,7 +18,7 @@ "contentManagement" ], "optionalPlugins": ["savedObjectsTaggingOss", "usageCollection"], - "requiredBundles": ["savedObjects", "kibanaUtils", "presentationPanel"], + "requiredBundles": ["kibanaUtils", "presentationPanel"], "extraPublicDirs": ["common"] } } diff --git a/src/plugins/embeddable/public/index.ts b/src/plugins/embeddable/public/index.ts index 19d3bd76c1a77..22d845be9c933 100644 --- a/src/plugins/embeddable/public/index.ts +++ b/src/plugins/embeddable/public/index.ts @@ -82,7 +82,6 @@ export type { SelfStyledEmbeddable, ValueClickContext, } from './lib'; -export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './lib/attribute_service'; export type { EmbeddableSetup, EmbeddableSetupDependencies, diff --git a/src/plugins/embeddable/public/lib/attribute_service/attribute_service.mock.tsx b/src/plugins/embeddable/public/lib/attribute_service/attribute_service.mock.tsx deleted file mode 100644 index 0500ca563593f..0000000000000 --- a/src/plugins/embeddable/public/lib/attribute_service/attribute_service.mock.tsx +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import { EmbeddableInput, SavedObjectEmbeddableInput } from '..'; -import { coreMock } from '@kbn/core/public/mocks'; -import { AttributeServiceOptions } from './attribute_service'; -import { CoreStart } from '@kbn/core/public'; -import { AttributeService, ATTRIBUTE_SERVICE_KEY } from '.'; - -export const mockAttributeService = < - 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, - customCore?: jest.Mocked -): AttributeService => { - const core = customCore ? customCore : coreMock.createStart(); - return new AttributeService( - type, - core.notifications.toasts, - options, - jest.fn().mockReturnValue(() => ({ getDisplayName: () => type })) - ); -}; diff --git a/src/plugins/embeddable/public/lib/attribute_service/attribute_service.test.ts b/src/plugins/embeddable/public/lib/attribute_service/attribute_service.test.ts deleted file mode 100644 index 3b86bdfb7d664..0000000000000 --- a/src/plugins/embeddable/public/lib/attribute_service/attribute_service.test.ts +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import { ATTRIBUTE_SERVICE_KEY, AttributeServiceUnwrapResult } from './attribute_service'; -import { mockAttributeService } from './attribute_service.mock'; -import { coreMock } from '@kbn/core/public/mocks'; -import { OnSaveProps } from '@kbn/saved-objects-plugin/public/save_modal'; - -interface TestAttributes { - title: string; - testAttr1?: string; - testAttr2?: { array: unknown[]; testAttr3: string }; -} - -interface TestByValueInput { - id: string; - [ATTRIBUTE_SERVICE_KEY]: TestAttributes; -} - -describe('attributeService', () => { - const defaultTestType = 'defaultTestType'; - let attributes: TestAttributes; - let byValueInput: TestByValueInput; - let byReferenceInput: { id: string; savedObjectId: string }; - const defaultSaveMethod = ( - testAttributes: TestAttributes, - savedObjectId?: string - ): Promise<{ id: string }> => { - return new Promise(() => { - return { id: '123' }; - }); - }; - - const defaultUnwrapMethod = ( - savedObjectId: string - ): Promise> => { - return new Promise(() => { - return { ...attributes }; - }); - }; - const defaultCheckForDuplicateTitle = (props: OnSaveProps): Promise => { - return new Promise(() => { - return true; - }); - }; - const options = { - saveMethod: defaultSaveMethod, - unwrapMethod: defaultUnwrapMethod, - checkForDuplicateTitle: defaultCheckForDuplicateTitle, - }; - - beforeEach(() => { - attributes = { - title: 'ultra title', - testAttr1: 'neat first attribute', - testAttr2: { array: [1, 2, 3], testAttr3: 'super attribute' }, - }; - byValueInput = { - id: '456', - attributes, - }; - byReferenceInput = { - id: '456', - savedObjectId: '123', - }; - }); - - describe('determining input type', () => { - const defaultAttributeService = mockAttributeService(defaultTestType, options); - const customAttributeService = mockAttributeService( - defaultTestType, - options - ); - - it('can determine input type given default types', () => { - expect( - defaultAttributeService.inputIsRefType({ id: '456', savedObjectId: '123' }) - ).toBeTruthy(); - expect( - defaultAttributeService.inputIsRefType({ - id: '456', - attributes: { title: 'wow I am by value' }, - }) - ).toBeFalsy(); - }); - it('can determine input type given custom types', () => { - expect( - customAttributeService.inputIsRefType({ id: '456', savedObjectId: '123' }) - ).toBeTruthy(); - expect( - customAttributeService.inputIsRefType({ - id: '456', - [ATTRIBUTE_SERVICE_KEY]: { title: 'wow I am by value' }, - }) - ).toBeFalsy(); - }); - }); - - describe('unwrapping attributes', () => { - it('does not throw error when given reference type input with no unwrap method', async () => { - const attributeService = mockAttributeService(defaultTestType, { - saveMethod: defaultSaveMethod, - checkForDuplicateTitle: jest.fn(), - }); - expect(await attributeService.unwrapAttributes(byReferenceInput)).toEqual({ - attributes: byReferenceInput, - }); - }); - - it('returns attributes when when given value type input', async () => { - const attributeService = mockAttributeService(defaultTestType, options); - expect(await attributeService.unwrapAttributes(byValueInput)).toEqual({ attributes }); - }); - - it('runs attributes through a custom unwrap method', async () => { - const attributeService = mockAttributeService(defaultTestType, { - saveMethod: defaultSaveMethod, - unwrapMethod: (savedObjectId) => { - return new Promise((resolve) => { - return resolve({ - attributes: { - ...attributes, - testAttr2: { array: [1, 2, 3, 4, 5], testAttr3: 'kibanana' }, - }, - }); - }); - }, - checkForDuplicateTitle: jest.fn(), - }); - expect(await attributeService.unwrapAttributes(byReferenceInput)).toEqual({ - attributes: { - ...attributes, - testAttr2: { array: [1, 2, 3, 4, 5], testAttr3: 'kibanana' }, - }, - }); - }); - }); - - describe('wrapping attributes', () => { - it('returns given attributes when use ref type is false', async () => { - const attributeService = mockAttributeService(defaultTestType, options); - expect(await attributeService.wrapAttributes(attributes, false)).toEqual({ attributes }); - }); - - it('calls saveMethod with appropriate parameters', async () => { - const core = coreMock.createStart(); - const saveMethod = jest.fn(); - saveMethod.mockReturnValueOnce({}); - const attributeService = mockAttributeService( - defaultTestType, - { - saveMethod, - unwrapMethod: defaultUnwrapMethod, - checkForDuplicateTitle: defaultCheckForDuplicateTitle, - }, - core - ); - expect(await attributeService.wrapAttributes(attributes, true, byReferenceInput)).toEqual( - byReferenceInput - ); - expect(saveMethod).toHaveBeenCalledWith(attributes, '123'); - }); - - it('uses custom save method when given an id', async () => { - const saveMethod = jest.fn().mockReturnValue({ id: '123' }); - const attributeService = mockAttributeService(defaultTestType, { - saveMethod, - unwrapMethod: defaultUnwrapMethod, - checkForDuplicateTitle: defaultCheckForDuplicateTitle, - }); - expect(await attributeService.wrapAttributes(attributes, true, byReferenceInput)).toEqual( - byReferenceInput - ); - expect(saveMethod).toHaveBeenCalledWith(attributes, byReferenceInput.savedObjectId); - }); - - it('uses custom save method given no id', async () => { - const saveMethod = jest.fn().mockReturnValue({ id: '678' }); - const attributeService = mockAttributeService(defaultTestType, { - saveMethod, - unwrapMethod: defaultUnwrapMethod, - checkForDuplicateTitle: defaultCheckForDuplicateTitle, - }); - expect(await attributeService.wrapAttributes(attributes, true)).toEqual({ - savedObjectId: '678', - }); - expect(saveMethod).toHaveBeenCalledWith(attributes, undefined); - }); - }); -}); diff --git a/src/plugins/embeddable/public/lib/attribute_service/index.ts b/src/plugins/embeddable/public/lib/attribute_service/index.ts deleted file mode 100644 index 7e41bfc6ceec6..0000000000000 --- a/src/plugins/embeddable/public/lib/attribute_service/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -export { AttributeService, ATTRIBUTE_SERVICE_KEY } from './attribute_service'; diff --git a/src/plugins/embeddable/public/mocks.tsx b/src/plugins/embeddable/public/mocks.tsx index cdfaa8e0ce01b..ec1a272bbe574 100644 --- a/src/plugins/embeddable/public/mocks.tsx +++ b/src/plugins/embeddable/public/mocks.tsx @@ -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; export type Start = jest.Mocked; @@ -114,7 +113,6 @@ const createStartContract = (): Start => { inject: jest.fn(), getAllMigrations: jest.fn(), getStateTransfer: jest.fn(() => createEmbeddableStateTransferMock() as EmbeddableStateTransfer), - getAttributeService: jest.fn(), }; return startContract; }; diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index 18af7eda372ec..b3b363edd949d 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -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, @@ -134,19 +131,6 @@ export interface EmbeddableStart extends PersistableStateService IterableIterator; 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 - ) => AttributeService; } export class EmbeddablePublicPlugin implements Plugin { private readonly embeddableFactoryDefinitions: Map = @@ -218,8 +202,6 @@ export class EmbeddablePublicPlugin implements Plugin - new AttributeService(type, core.notifications.toasts, options, this.getEmbeddableFactory), getStateTransfer: (storage?: Storage) => storage ? new EmbeddableStateTransfer( diff --git a/src/plugins/embeddable/tsconfig.json b/src/plugins/embeddable/tsconfig.json index 58bd02e0493a8..bf97096d1484b 100644 --- a/src/plugins/embeddable/tsconfig.json +++ b/src/plugins/embeddable/tsconfig.json @@ -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", diff --git a/src/plugins/saved_search/public/services/saved_searches/to_saved_search.test.ts b/src/plugins/saved_search/public/services/saved_searches/to_saved_search.test.ts index defb0e1a79986..b17eadf7e9571 100644 --- a/src/plugins/saved_search/public/services/saved_searches/to_saved_search.test.ts +++ b/src/plugins/saved_search/public/services/saved_searches/to_saved_search.test.ts @@ -8,9 +8,7 @@ */ 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 '.'; @@ -18,11 +16,6 @@ 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', () => { diff --git a/src/plugins/visualizations/public/actions/edit_in_lens_action.tsx b/src/plugins/visualizations/public/actions/edit_in_lens_action.tsx index 8995b2abf7385..f8ed7a6294dbf 100644 --- a/src/plugins/visualizations/public/actions/edit_in_lens_action.tsx +++ b/src/plugins/visualizations/public/actions/edit_in_lens_action.tsx @@ -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, diff --git a/src/plugins/visualizations/public/embeddable/types.ts b/src/plugins/visualizations/public/embeddable/types.ts index 80e7e2d9179e8..767f911d5bd52 100644 --- a/src/plugins/visualizations/public/embeddable/types.ts +++ b/src/plugins/visualizations/public/embeddable/types.ts @@ -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'; diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index 3de1bfc01f2ef..54b37b0a237e1 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -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'; @@ -41,7 +42,8 @@ export type VisualizeEmbeddableFactoryContract = PublicContract; 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, diff --git a/src/plugins/embeddable/public/lib/attribute_service/attribute_service.tsx b/src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx similarity index 90% rename from src/plugins/embeddable/public/lib/attribute_service/attribute_service.tsx rename to src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx index 05aa8a3d0059a..49703371ac783 100644 --- a/src/plugins/embeddable/public/lib/attribute_service/attribute_service.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx @@ -10,7 +10,6 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { get, omit } from 'lodash'; -import { NotificationsStart } from '@kbn/core/public'; import { SavedObjectSaveModal, OnSaveProps, @@ -21,8 +20,8 @@ import { EmbeddableInput, SavedObjectEmbeddableInput, isSavedObjectEmbeddableInput, - EmbeddableFactory, -} from '..'; +} from '@kbn/embeddable-plugin/public'; +import { getNotifications } from '../../services'; /** * The attribute service is a shared, generic service that embeddables can use to provide the functionality @@ -64,20 +63,10 @@ export class AttributeService< RefType extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput, MetaInfo extends unknown = unknown > { - private embeddableFactory; - constructor( private type: string, - private toasts: NotificationsStart['toasts'], - private options: AttributeServiceOptions, - getEmbeddableFactory?: (embeddableFactoryId: string) => EmbeddableFactory - ) { - if (getEmbeddableFactory) { - const factory = getEmbeddableFactory(this.type); - - this.embeddableFactory = factory; - } - } + private options: AttributeServiceOptions + ) {} private async defaultUnwrapMethod( input: RefType @@ -116,8 +105,8 @@ export class AttributeService< } return { ...originalInput } as RefType; } catch (error) { - this.toasts.addDanger({ - title: i18n.translate('embeddableApi.attributeService.saveToLibraryError', { + getNotifications().toasts.addDanger({ + title: i18n.translate('visualizations.attributeService.saveToLibraryError', { defaultMessage: `An error occurred while saving. Error: {errorMessage}`, values: { errorMessage: error.message, @@ -187,9 +176,7 @@ export class AttributeService< (input as ValType)[ATTRIBUTE_SERVICE_KEY].title )} showCopyOnSave={false} - objectType={ - this.embeddableFactory ? this.embeddableFactory.getDisplayName() : this.type - } + objectType={this.type} showDescription={false} /> ); diff --git a/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts b/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts index 69ed12302f4ec..b684bd83402c5 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts +++ b/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { IContainer, ErrorEmbeddable, AttributeService } from '@kbn/embeddable-plugin/public'; +import { IContainer, ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; import type { DataView } from '@kbn/data-views-plugin/public'; import { Vis } from '../../types'; import type { @@ -21,6 +21,7 @@ import { getHttp, getTimeFilter, getCapabilities } from '../../services'; import { urlFor } from '../../utils/saved_visualize_utils'; import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory'; import { createVisualizeEmbeddableAsync } from './visualize_embeddable_async'; +import { AttributeService } from './attribute_service'; /** @deprecated * VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only diff --git a/src/plugins/visualizations/public/legacy/embeddable/index.ts b/src/plugins/visualizations/public/legacy/embeddable/index.ts index 6afee494e6f4f..979a631f8c665 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/index.ts +++ b/src/plugins/visualizations/public/legacy/embeddable/index.ts @@ -12,7 +12,3 @@ export { VISUALIZE_EMBEDDABLE_TYPE, COMMON_VISUALIZATION_GROUPING } from './cons export { createVisEmbeddableFromObject } from './create_vis_embeddable_from_object'; export type { VisualizeEmbeddable, VisualizeInput } from './visualize_embeddable'; -export { - type HasVisualizeConfig, - apiHasVisualizeConfig, -} from '../../embeddable/interfaces/has_visualize_config'; diff --git a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx index 196753d73b28c..bfd87435345e5 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx @@ -23,7 +23,6 @@ import { Warnings } from '@kbn/charts-plugin/public'; import { hasUnsupportedDownsampledAggregationFailure } from '@kbn/search-response-warnings'; import { Adapters, - AttributeService, Embeddable, EmbeddableInput, EmbeddableOutput, @@ -53,6 +52,7 @@ import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory'; import { getSavedVisualization } from '../../utils/saved_visualize_utils'; import { VisSavedObject } from '../../types'; import { toExpressionAst } from '../../embeddable/to_ast'; +import { AttributeService } from './attribute_service'; export interface VisualizeEmbeddableConfiguration { vis: Vis; diff --git a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable_factory.tsx b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable_factory.tsx index 7594c8d42f2ea..112a8d3b7fd8c 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable_factory.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable_factory.tsx @@ -25,9 +25,9 @@ import { EmbeddableOutput, ErrorEmbeddable, IContainer, - AttributeService, } from '@kbn/embeddable-plugin/public'; import type { StartServicesGetter } from '@kbn/kibana-utils-plugin/public'; +import { AttributeService } from './attribute_service'; import { checkForDuplicateTitle } from '../../utils/saved_objects_utils/check_for_duplicate_title'; import type { VisualizeByReferenceInput, @@ -138,16 +138,10 @@ export class VisualizeEmbeddableFactory private async getAttributeService() { if (!this.attributeService) { - this.attributeService = this.deps - .start() - .plugins.embeddable.getAttributeService< - VisualizeSavedObjectAttributes, - VisualizeByValueInput, - VisualizeByReferenceInput - >(this.type, { - saveMethod: this.saveMethod.bind(this), - checkForDuplicateTitle: this.checkTitle.bind(this), - }); + this.attributeService = new AttributeService(this.type, { + saveMethod: this.saveMethod.bind(this), + checkForDuplicateTitle: this.checkTitle.bind(this), + }); } return this.attributeService!; } diff --git a/src/plugins/visualizations/public/plugin.ts b/src/plugins/visualizations/public/plugin.ts index 856c16104b6ca..6f82934b162d4 100644 --- a/src/plugins/visualizations/public/plugin.ts +++ b/src/plugins/visualizations/public/plugin.ts @@ -115,6 +115,7 @@ import { setDataViews, setInspector, getTypes, + setNotifications, } from './services'; import { VisualizeConstants, VISUALIZE_EMBEDDABLE_TYPE } from '../common/constants'; import { EditInLensAction } from './actions/edit_in_lens_action'; @@ -485,6 +486,7 @@ export class VisualizationsPlugin setSavedSearch(savedSearch); setDataViews(dataViews); setInspector(inspector); + setNotifications(core.notifications); if (spaces) { setSpaces(spaces); diff --git a/src/plugins/visualizations/public/services.ts b/src/plugins/visualizations/public/services.ts index 3b383abe52a35..09ab2e2e59272 100644 --- a/src/plugins/visualizations/public/services.ts +++ b/src/plugins/visualizations/public/services.ts @@ -21,6 +21,7 @@ import type { ExecutionContextSetup, AnalyticsServiceStart, I18nStart, + NotificationsStart, } from '@kbn/core/public'; import type { DataPublicPluginStart, TimefilterContract } from '@kbn/data-plugin/public'; import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; @@ -42,6 +43,8 @@ export const [getUISettings, setUISettings] = createGetterSetter('Analytics'); export const [getI18n, setI18n] = createGetterSetter('I18n'); export const [getTheme, setTheme] = createGetterSetter('Theme'); +export const [getNotifications, setNotifications] = + createGetterSetter('Notifications'); export const [getCapabilities, setCapabilities] = createGetterSetter('Capabilities'); diff --git a/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts b/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts index 3a3898093a8eb..df7c7b5dda52d 100644 --- a/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts +++ b/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts @@ -16,7 +16,7 @@ import { createVisAsync } from '../../vis_async'; import { convertToSerializedVis, getSavedVisualization } from '../../utils/saved_visualize_utils'; import { SerializedVis, Vis, VisSavedObject, VisualizeEmbeddableContract } from '../..'; import type { VisInstance, VisualizeServices } from '../types'; -import { VisualizeInput } from '../../legacy/embeddable'; +import type { VisualizeInput } from '../../legacy/embeddable'; function isErrorRelatedToRuntimeFields(error: ExpressionValueError['error']) { const originalError = error.original || error; diff --git a/x-pack/platform/plugins/private/translations/translations/fr-FR.json b/x-pack/platform/plugins/private/translations/translations/fr-FR.json index bd3d7a568d929..7103837a38947 100644 --- a/x-pack/platform/plugins/private/translations/translations/fr-FR.json +++ b/x-pack/platform/plugins/private/translations/translations/fr-FR.json @@ -2794,7 +2794,6 @@ "embeddableApi.addPanel.managedPanelTooltip": "Elastic gère ce panneau. Le fait de l'ajouter à un tableau de bord le dissocie de la bibliothèque.", "embeddableApi.addPanel.noMatchingObjectsMessage": "Aucun objet correspondant trouvé.", "embeddableApi.addPanel.Title": "Ajouter depuis la bibliothèque", - "embeddableApi.attributeService.saveToLibraryError": "Une erreur s'est produite lors de l'enregistrement. Erreur : {errorMessage}.", "embeddableApi.cellValueTrigger.description": "Les actions apparaissent dans les options de valeur de cellule dans la visualisation", "embeddableApi.cellValueTrigger.title": "Valeur de cellule", "embeddableApi.common.constants.grouping.annotations": "Annotations et Navigation", diff --git a/x-pack/platform/plugins/private/translations/translations/ja-JP.json b/x-pack/platform/plugins/private/translations/translations/ja-JP.json index be926d0485004..ecd025ad2ca29 100644 --- a/x-pack/platform/plugins/private/translations/translations/ja-JP.json +++ b/x-pack/platform/plugins/private/translations/translations/ja-JP.json @@ -2789,7 +2789,6 @@ "embeddableApi.addPanel.managedPanelTooltip": "Elasticはこのパネルを管理します。ダッシュボードに追加すると、ライブラリからリンクが解除されます。", "embeddableApi.addPanel.noMatchingObjectsMessage": "一致するオブジェクトが見つかりませんでした。", "embeddableApi.addPanel.Title": "ライブラリから追加", - "embeddableApi.attributeService.saveToLibraryError": "保存中にエラーが発生しました。エラー:{errorMessage}", "embeddableApi.cellValueTrigger.description": "アクションはビジュアライゼーションのセル値オプションに表示されます", "embeddableApi.cellValueTrigger.title": "セル値", "embeddableApi.common.constants.grouping.annotations": "注釈とナビゲーション", diff --git a/x-pack/platform/plugins/private/translations/translations/zh-CN.json b/x-pack/platform/plugins/private/translations/translations/zh-CN.json index f9638a6fe5028..1b4159dcbc4f2 100644 --- a/x-pack/platform/plugins/private/translations/translations/zh-CN.json +++ b/x-pack/platform/plugins/private/translations/translations/zh-CN.json @@ -2779,7 +2779,6 @@ "embeddableApi.addPanel.managedPanelTooltip": "Elastic 将管理此面板。将其添加到仪表板会取消其与库的链接。", "embeddableApi.addPanel.noMatchingObjectsMessage": "未找到任何匹配对象。", "embeddableApi.addPanel.Title": "从库中添加", - "embeddableApi.attributeService.saveToLibraryError": "保存时出错。错误:{errorMessage}", "embeddableApi.cellValueTrigger.description": "操作在可视化上的单元格值选项中显示", "embeddableApi.cellValueTrigger.title": "单元格值", "embeddableApi.common.constants.grouping.annotations": "标注和导航",