From 8a46374650902fbdda08b9cd020186c712bff1bd Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 19 Dec 2024 09:37:18 -0700 Subject: [PATCH] [8.x] [embeddable] remove legacy embeddable types (#204832) (#204952) # Backport This will backport the following commits from `main` to `8.x`: - [[embeddable] remove legacy embeddable types (#204832)](https://github.com/elastic/kibana/pull/204832) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../dashboard_container_references.test.ts | 2 +- .../create/search_sessions/new_session.ts | 9 ++- src/plugins/embeddable/public/index.ts | 14 ---- .../embeddables/diff_embeddable_input.test.ts | 3 +- .../public/lib/embeddables/index.ts | 4 -- .../public/lib/embeddables/is_embeddable.ts | 19 ------ .../lib/embeddables/is_error_embeddable.ts | 16 ----- .../lib/embeddables/with_subscription.tsx | 65 ------------------ .../public/lib/filterable_embeddable/index.ts | 12 ---- .../should_fetch.test.tsx | 66 ------------------- .../filterable_embeddable/should_fetch.tsx | 51 -------------- .../public/lib/filterable_embeddable/types.ts | 51 -------------- src/plugins/embeddable/public/lib/index.ts | 3 - .../reference_or_value_embeddable/index.ts | 11 ---- .../reference_or_value_embeddable/types.ts | 46 ------------- .../lib/self_styled_embeddable/index.ts | 11 ---- .../lib/self_styled_embeddable/types.ts | 28 -------- src/plugins/embeddable/public/mocks.tsx | 54 +-------------- .../legacy/embeddable/attribute_service.tsx | 2 +- .../embeddable/visualize_embeddable.tsx | 17 +---- .../add_to_timeline/lens/add_to_timeline.ts | 7 +- .../lens/copy_to_clipboard.ts | 4 +- .../app/actions/filter/lens/create_action.ts | 4 +- 23 files changed, 22 insertions(+), 477 deletions(-) delete mode 100644 src/plugins/embeddable/public/lib/embeddables/is_embeddable.ts delete mode 100644 src/plugins/embeddable/public/lib/embeddables/is_error_embeddable.ts delete mode 100644 src/plugins/embeddable/public/lib/embeddables/with_subscription.tsx delete mode 100644 src/plugins/embeddable/public/lib/filterable_embeddable/index.ts delete mode 100644 src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.test.tsx delete mode 100644 src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.tsx delete mode 100644 src/plugins/embeddable/public/lib/filterable_embeddable/types.ts delete mode 100644 src/plugins/embeddable/public/lib/reference_or_value_embeddable/index.ts delete mode 100644 src/plugins/embeddable/public/lib/reference_or_value_embeddable/types.ts delete mode 100644 src/plugins/embeddable/public/lib/self_styled_embeddable/index.ts delete mode 100644 src/plugins/embeddable/public/lib/self_styled_embeddable/types.ts diff --git a/src/plugins/dashboard/common/dashboard_container/persistable_state/dashboard_container_references.test.ts b/src/plugins/dashboard/common/dashboard_container/persistable_state/dashboard_container_references.test.ts index 3f7592878e2e7..15ed03bb1d7d1 100644 --- a/src/plugins/dashboard/common/dashboard_container/persistable_state/dashboard_container_references.test.ts +++ b/src/plugins/dashboard/common/dashboard_container/persistable_state/dashboard_container_references.test.ts @@ -10,7 +10,7 @@ import { createExtract, createInject } from './dashboard_container_references'; import { createEmbeddablePersistableStateServiceMock } from '@kbn/embeddable-plugin/common/mocks'; import { ParsedDashboardAttributesWithType } from '../../types'; -import { SavedObjectEmbeddableInput } from '@kbn/embeddable-plugin/public'; +import { SavedObjectEmbeddableInput } from '@kbn/embeddable-plugin/common'; const persistableStateService = createEmbeddablePersistableStateServiceMock(); diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/create/search_sessions/new_session.ts b/src/plugins/dashboard/public/dashboard_container/embeddable/create/search_sessions/new_session.ts index 8c2b88d81b631..c21a6a6f615aa 100644 --- a/src/plugins/dashboard/public/dashboard_container/embeddable/create/search_sessions/new_session.ts +++ b/src/plugins/dashboard/public/dashboard_container/embeddable/create/search_sessions/new_session.ts @@ -7,13 +7,18 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { Filter, TimeRange, onlyDisabledFiltersChanged } from '@kbn/es-query'; +import { COMPARE_ALL_OPTIONS, Filter, TimeRange, onlyDisabledFiltersChanged } from '@kbn/es-query'; import { combineLatest, distinctUntilChanged, Observable, skip } from 'rxjs'; -import { shouldRefreshFilterCompareOptions } from '@kbn/embeddable-plugin/public'; import { apiPublishesSettings } from '@kbn/presentation-containers/interfaces/publishes_settings'; import { apiPublishesReload, apiPublishesUnifiedSearch } from '@kbn/presentation-publishing'; import { areTimesEqual } from '../../../../dashboard_api/unified_search_manager'; +const shouldRefreshFilterCompareOptions = { + ...COMPARE_ALL_OPTIONS, + // do not compare $state to avoid refreshing when filter is pinned/unpinned (which does not impact results) + state: false, +}; + export function newSession$(api: unknown) { const observables: Array> = []; diff --git a/src/plugins/embeddable/public/index.ts b/src/plugins/embeddable/public/index.ts index ad5857ac871a6..2cc322940a77b 100644 --- a/src/plugins/embeddable/public/index.ts +++ b/src/plugins/embeddable/public/index.ts @@ -22,20 +22,13 @@ export { EmbeddableFactoryNotFoundError, EmbeddableStateTransfer, ErrorEmbeddable, - genericEmbeddableInputIsEqual, isContextMenuTriggerContext, - isEmbeddable, - isErrorEmbeddable, isExplicitInputWithAttributes, - isFilterableEmbeddable, isMultiValueClickTriggerContext, isRangeSelectTriggerContext, - isReferenceOrValueEmbeddable, isRowClickTriggerContext, - isSavedObjectEmbeddableInput, isValueClickTriggerContext, MULTI_VALUE_CLICK_TRIGGER, - omitGenericEmbeddableInput, panelBadgeTrigger, panelHoverTrigger, PanelNotFoundError, @@ -46,11 +39,8 @@ export { PANEL_NOTIFICATION_TRIGGER, runEmbeddableFactoryMigrations, SELECT_RANGE_TRIGGER, - shouldFetch$, - shouldRefreshFilterCompareOptions, VALUE_CLICK_TRIGGER, ViewMode, - withEmbeddableSubscription, } from './lib'; export type { CellValueContext, @@ -63,15 +53,11 @@ export type { EmbeddableInstanceConfiguration, EmbeddableOutput, EmbeddablePackageState, - FilterableEmbeddable, IEmbeddable, MultiValueClickContext, OutputSpec, PropertySpec, RangeSelectContext, - ReferenceOrValueEmbeddable, - SavedObjectEmbeddableInput, - SelfStyledEmbeddable, ValueClickContext, } from './lib'; export type { diff --git a/src/plugins/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts b/src/plugins/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts index 49f097f500a46..b4b8a2a1da920 100644 --- a/src/plugins/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts +++ b/src/plugins/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts @@ -9,7 +9,8 @@ import { ViewMode } from '..'; import { KibanaExecutionContext } from '@kbn/core/types'; -import { EmbeddableInput, omitGenericEmbeddableInput, genericEmbeddableInputIsEqual } from '.'; +import { EmbeddableInput } from '.'; +import { omitGenericEmbeddableInput, genericEmbeddableInputIsEqual } from './diff_embeddable_input'; const getGenericEmbeddableState = (state?: Partial): EmbeddableInput => { const defaultState: EmbeddableInput = { diff --git a/src/plugins/embeddable/public/lib/embeddables/index.ts b/src/plugins/embeddable/public/lib/embeddables/index.ts index 92cd977d1f3d4..16b4fb7413769 100644 --- a/src/plugins/embeddable/public/lib/embeddables/index.ts +++ b/src/plugins/embeddable/public/lib/embeddables/index.ts @@ -9,13 +9,9 @@ export * from '../../../common/lib/saved_object_embeddable'; export * from './default_embeddable_factory_provider'; -export { genericEmbeddableInputIsEqual, omitGenericEmbeddableInput } from './diff_embeddable_input'; export { Embeddable } from './embeddable'; export { EmbeddableErrorHandler } from './embeddable_error_handler'; export * from './embeddable_factory'; export * from './embeddable_factory_definition'; export { ErrorEmbeddable } from './error_embeddable'; -export { isErrorEmbeddable } from './is_error_embeddable'; -export { isEmbeddable } from './is_embeddable'; export type { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; -export { withEmbeddableSubscription } from './with_subscription'; diff --git a/src/plugins/embeddable/public/lib/embeddables/is_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/is_embeddable.ts deleted file mode 100644 index 03d1c4b977013..0000000000000 --- a/src/plugins/embeddable/public/lib/embeddables/is_embeddable.ts +++ /dev/null @@ -1,19 +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 { IEmbeddable } from './i_embeddable'; - -export const isEmbeddable = (x: unknown): x is IEmbeddable => { - if (!x) return false; - if (typeof x !== 'object') return false; - if (typeof (x as IEmbeddable).id !== 'string') return false; - if (typeof (x as IEmbeddable).getInput !== 'function') return false; - if (typeof (x as IEmbeddable).supportedTriggers !== 'function') return false; - return true; -}; diff --git a/src/plugins/embeddable/public/lib/embeddables/is_error_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/is_error_embeddable.ts deleted file mode 100644 index 67240f30f8d79..0000000000000 --- a/src/plugins/embeddable/public/lib/embeddables/is_error_embeddable.ts +++ /dev/null @@ -1,16 +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 { ErrorEmbeddable, IEmbeddable } from '..'; - -export function isErrorEmbeddable( - embeddable: TEmbeddable | ErrorEmbeddable -): embeddable is ErrorEmbeddable { - return Boolean(embeddable.fatalError || (embeddable as ErrorEmbeddable).error !== undefined); -} diff --git a/src/plugins/embeddable/public/lib/embeddables/with_subscription.tsx b/src/plugins/embeddable/public/lib/embeddables/with_subscription.tsx deleted file mode 100644 index 2bd36d3dd12d9..0000000000000 --- a/src/plugins/embeddable/public/lib/embeddables/with_subscription.tsx +++ /dev/null @@ -1,65 +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 React from 'react'; -import * as Rx from 'rxjs'; -import { IEmbeddable, EmbeddableInput, EmbeddableOutput } from './i_embeddable'; - -export const withEmbeddableSubscription = < - I extends EmbeddableInput, - O extends EmbeddableOutput, - E extends IEmbeddable = IEmbeddable, - ExtraProps = {} ->( - WrappedComponent: React.ComponentType<{ input: I; output: O; embeddable: E } & ExtraProps> -): React.ComponentType<{ embeddable: E } & ExtraProps> => - class WithEmbeddableSubscription extends React.Component< - { embeddable: E } & ExtraProps, - { input: I; output: O } - > { - private subscription?: Rx.Subscription; - private mounted: boolean = false; - - constructor(props: { embeddable: E } & ExtraProps) { - super(props); - this.state = { - input: this.props.embeddable.getInput(), - output: this.props.embeddable.getOutput(), - }; - } - - componentDidMount() { - this.mounted = true; - - this.subscription = Rx.merge( - this.props.embeddable.getOutput$(), - this.props.embeddable.getInput$() - ).subscribe(() => { - if (this.mounted) { - this.setState({ - input: this.props.embeddable.getInput(), - output: this.props.embeddable.getOutput(), - }); - } - }); - } - - componentWillUnmount() { - this.mounted = false; - if (this.subscription) { - this.subscription.unsubscribe(); - } - } - - render() { - return ( - - ); - } - }; diff --git a/src/plugins/embeddable/public/lib/filterable_embeddable/index.ts b/src/plugins/embeddable/public/lib/filterable_embeddable/index.ts deleted file mode 100644 index 4224bb843c63a..0000000000000 --- a/src/plugins/embeddable/public/lib/filterable_embeddable/index.ts +++ /dev/null @@ -1,12 +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 type { FilterableEmbeddable } from './types'; -export { isFilterableEmbeddable } from './types'; -export { shouldFetch$, shouldRefreshFilterCompareOptions } from './should_fetch'; diff --git a/src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.test.tsx b/src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.test.tsx deleted file mode 100644 index 2e4b001224531..0000000000000 --- a/src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.test.tsx +++ /dev/null @@ -1,66 +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 { BehaviorSubject, Subscription } from 'rxjs'; -import type { FilterableEmbeddableInput } from './types'; -import { shouldFetch$ } from './should_fetch'; - -describe('shouldFetch$', () => { - let shouldFetchCount = 0; - let subscription: Subscription; - let updateInput: (inputFragment: Partial) => void; - beforeAll(() => { - let input: FilterableEmbeddableInput = { - id: '1', - timeRange: { - to: 'now', - from: 'now-15m', - }, - }; - const subject = new BehaviorSubject(input); - updateInput = (inputFragment: Partial) => { - input = { - ...input, - ...inputFragment, - }; - subject.next(input); - }; - - subscription = shouldFetch$(subject, () => { - return input; - }).subscribe(() => { - shouldFetchCount++; - }); - }); - - afterAll(() => { - subscription.unsubscribe(); - }); - - test('should not fire on initial subscription', () => { - expect(shouldFetchCount).toBe(0); - }); - - test('should not fire when there are no changes', () => { - const initialCount = shouldFetchCount; - updateInput({}); - expect(shouldFetchCount).toBe(initialCount); - }); - - test('should fire when timeRange changes', () => { - const initialCount = shouldFetchCount; - updateInput({ - timeRange: { - to: 'now', - from: 'now-25m', - }, - }); - expect(shouldFetchCount).toBe(initialCount + 1); - }); -}); diff --git a/src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.tsx b/src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.tsx deleted file mode 100644 index cd7c499f42cc9..0000000000000 --- a/src/plugins/embeddable/public/lib/filterable_embeddable/should_fetch.tsx +++ /dev/null @@ -1,51 +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 fastIsEqual from 'fast-deep-equal'; -import { Observable } from 'rxjs'; -import { map, distinctUntilChanged, skip, startWith } from 'rxjs'; -import { COMPARE_ALL_OPTIONS, onlyDisabledFiltersChanged } from '@kbn/es-query'; -import type { FilterableEmbeddableInput } from './types'; - -export const shouldRefreshFilterCompareOptions = { - ...COMPARE_ALL_OPTIONS, - // do not compare $state to avoid refreshing when filter is pinned/unpinned (which does not impact results) - state: false, -}; - -export function shouldFetch$< - TFilterableEmbeddableInput extends FilterableEmbeddableInput = FilterableEmbeddableInput ->( - updated$: Observable, - getInput: () => TFilterableEmbeddableInput -): Observable { - return updated$.pipe(map(() => getInput())).pipe( - // wrapping distinctUntilChanged with startWith and skip to prime distinctUntilChanged with an initial input value. - startWith(getInput()), - distinctUntilChanged( - (previous: TFilterableEmbeddableInput, current: TFilterableEmbeddableInput) => { - if ( - !fastIsEqual( - [previous.searchSessionId, previous.query, previous.timeRange, previous.timeslice], - [current.searchSessionId, current.query, current.timeRange, current.timeslice] - ) - ) { - return false; - } - - return onlyDisabledFiltersChanged( - previous.filters, - current.filters, - shouldRefreshFilterCompareOptions - ); - } - ), - skip(1) - ); -} diff --git a/src/plugins/embeddable/public/lib/filterable_embeddable/types.ts b/src/plugins/embeddable/public/lib/filterable_embeddable/types.ts deleted file mode 100644 index e2eb2564a962b..0000000000000 --- a/src/plugins/embeddable/public/lib/filterable_embeddable/types.ts +++ /dev/null @@ -1,51 +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 type { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query'; -import { PublishesWritableUnifiedSearch } from '@kbn/presentation-publishing'; -import { EmbeddableInput } from '../embeddables'; - -export type FilterableEmbeddableInput = EmbeddableInput & { - filters?: Filter[]; - query?: Query; - searchSessionId?: string; - timeRange?: TimeRange; - timeslice?: [number, number]; -}; - -export type EmbeddableHasTimeRange = Pick< - PublishesWritableUnifiedSearch, - 'timeRange$' | 'setTimeRange' | 'isCompatibleWithUnifiedSearch' ->; - -/** - * All embeddables that implement this interface should support being filtered - * and/or queried via the top navigation bar. - */ -export interface FilterableEmbeddable { - /** - * Gets the embeddable's local filters - **/ - getFilters: () => Filter[]; - /** - * Gets the embeddable's local query - **/ - getQuery: () => Query | AggregateQuery | undefined; -} - -/** - * Ensure that embeddable supports filtering/querying - * @param incoming Embeddable that is being tested to check if it is a FilterableEmbeddable - * @returns true if the incoming embeddable is a FilterableEmbeddable, false if it is not - */ -export function isFilterableEmbeddable(incoming: unknown): incoming is FilterableEmbeddable { - return ( - !!(incoming as FilterableEmbeddable).getFilters && !!(incoming as FilterableEmbeddable).getQuery - ); -} diff --git a/src/plugins/embeddable/public/lib/index.ts b/src/plugins/embeddable/public/lib/index.ts index 511cc619bd5af..642af73713dc4 100644 --- a/src/plugins/embeddable/public/lib/index.ts +++ b/src/plugins/embeddable/public/lib/index.ts @@ -12,7 +12,4 @@ export * from './embeddables'; export * from './types'; export * from './triggers'; export * from './state_transfer'; -export * from './reference_or_value_embeddable'; -export * from './self_styled_embeddable'; -export * from './filterable_embeddable'; export * from './factory_migrations/run_factory_migrations'; diff --git a/src/plugins/embeddable/public/lib/reference_or_value_embeddable/index.ts b/src/plugins/embeddable/public/lib/reference_or_value_embeddable/index.ts deleted file mode 100644 index 00df48a533537..0000000000000 --- a/src/plugins/embeddable/public/lib/reference_or_value_embeddable/index.ts +++ /dev/null @@ -1,11 +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 type { ReferenceOrValueEmbeddable } from './types'; -export { isReferenceOrValueEmbeddable } from './types'; diff --git a/src/plugins/embeddable/public/lib/reference_or_value_embeddable/types.ts b/src/plugins/embeddable/public/lib/reference_or_value_embeddable/types.ts deleted file mode 100644 index 2916986fa1352..0000000000000 --- a/src/plugins/embeddable/public/lib/reference_or_value_embeddable/types.ts +++ /dev/null @@ -1,46 +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 '..'; - -/** - * All embeddables that implement this interface will be able to use input that is - * either by reference (backed by a saved object) OR by value, (provided - * by the container). - * @public - */ -export interface ReferenceOrValueEmbeddable< - ValTypeInput extends EmbeddableInput = EmbeddableInput, - RefTypeInput extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput -> { - /** - * determines whether the input is by value or by reference. - */ - inputIsRefType: (input: ValTypeInput | RefTypeInput) => input is RefTypeInput; - - /** - * Gets the embeddable's current input as its Value type - */ - getInputAsValueType: () => Promise; - - /** - * Gets the embeddable's current input as its Reference type - */ - getInputAsRefType: () => Promise; -} - -export function isReferenceOrValueEmbeddable( - incoming: unknown -): incoming is ReferenceOrValueEmbeddable { - return ( - !!(incoming as ReferenceOrValueEmbeddable).inputIsRefType && - !!(incoming as ReferenceOrValueEmbeddable).getInputAsValueType && - !!(incoming as ReferenceOrValueEmbeddable).getInputAsRefType - ); -} diff --git a/src/plugins/embeddable/public/lib/self_styled_embeddable/index.ts b/src/plugins/embeddable/public/lib/self_styled_embeddable/index.ts deleted file mode 100644 index 52376906d983b..0000000000000 --- a/src/plugins/embeddable/public/lib/self_styled_embeddable/index.ts +++ /dev/null @@ -1,11 +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 type { SelfStyledEmbeddable } from './types'; -export { isSelfStyledEmbeddable } from './types'; diff --git a/src/plugins/embeddable/public/lib/self_styled_embeddable/types.ts b/src/plugins/embeddable/public/lib/self_styled_embeddable/types.ts deleted file mode 100644 index ec4b403e54448..0000000000000 --- a/src/plugins/embeddable/public/lib/self_styled_embeddable/types.ts +++ /dev/null @@ -1,28 +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 interface SelfStyledOptions { - hideTitle?: boolean; -} - -/** - * All embeddables that implement this interface will be able to configure - * the style of their containing panels - * @public - */ -export interface SelfStyledEmbeddable { - /** - * Gets the embeddable's style configuration - */ - getSelfStyledOptions: () => SelfStyledOptions; -} - -export function isSelfStyledEmbeddable(incoming: unknown): incoming is SelfStyledEmbeddable { - return !!(incoming as SelfStyledEmbeddable).getSelfStyledOptions; -} diff --git a/src/plugins/embeddable/public/mocks.tsx b/src/plugins/embeddable/public/mocks.tsx index 7db4efd34e48e..2208abd97e5d6 100644 --- a/src/plugins/embeddable/public/mocks.tsx +++ b/src/plugins/embeddable/public/mocks.tsx @@ -9,7 +9,7 @@ import { contentManagementMock } from '@kbn/content-management-plugin/public/mocks'; import { coreMock } from '@kbn/core/public/mocks'; -import { type AggregateQuery, type Filter, type Query } from '@kbn/es-query'; +import { type Query } from '@kbn/es-query'; import { inspectorPluginMock } from '@kbn/inspector-plugin/public/mocks'; import { SavedObjectManagementTypeInfo, @@ -20,20 +20,13 @@ import { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/pu import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks'; import { - EmbeddableInput, EmbeddableSetup, EmbeddableSetupDependencies, EmbeddableStart, EmbeddableStartDependencies, EmbeddableStateTransfer, - FilterableEmbeddable, - IEmbeddable, - ReferenceOrValueEmbeddable, - SavedObjectEmbeddableInput, - SelfStyledEmbeddable, } from '.'; import { setKibanaServices } from './kibana_services'; -import { SelfStyledOptions } from './lib/self_styled_embeddable/types'; import { EmbeddablePublicPlugin } from './plugin'; import { registerReactEmbeddableFactory } from './react_embeddable_system'; import { registerAddFromLibraryType } from './add_from_library/registry'; @@ -51,48 +44,6 @@ export const createEmbeddableStateTransferMock = (): Partial( - embeddable: IEmbeddable, - options: { - mockedByReferenceInput: RefTypeInput; - mockedByValueInput: ValTypeInput; - } -): OriginalEmbeddableType & ReferenceOrValueEmbeddable => { - const newEmbeddable: ReferenceOrValueEmbeddable = - embeddable as unknown as ReferenceOrValueEmbeddable; - newEmbeddable.inputIsRefType = (input: unknown): input is RefTypeInput => - !!(input as RefTypeInput).savedObjectId; - newEmbeddable.getInputAsRefType = () => Promise.resolve(options.mockedByReferenceInput); - newEmbeddable.getInputAsValueType = () => Promise.resolve(options.mockedByValueInput); - return newEmbeddable as OriginalEmbeddableType & ReferenceOrValueEmbeddable; -}; - -export function mockSelfStyledEmbeddable( - embeddable: OriginalEmbeddableType, - selfStyledOptions: SelfStyledOptions -): OriginalEmbeddableType & SelfStyledEmbeddable { - const newEmbeddable: SelfStyledEmbeddable = embeddable as unknown as SelfStyledEmbeddable; - newEmbeddable.getSelfStyledOptions = () => selfStyledOptions; - return newEmbeddable as OriginalEmbeddableType & SelfStyledEmbeddable; -} - -export function mockFilterableEmbeddable( - embeddable: OriginalEmbeddableType, - options: { - getFilters: () => Filter[]; - getQuery: () => Query | AggregateQuery | undefined; - } -): OriginalEmbeddableType & FilterableEmbeddable { - const newEmbeddable: FilterableEmbeddable = embeddable as unknown as FilterableEmbeddable; - newEmbeddable.getFilters = () => options.getFilters(); - newEmbeddable.getQuery = () => options.getQuery(); - return newEmbeddable as OriginalEmbeddableType & FilterableEmbeddable; -} - const createSetupContract = (): Setup => { const setupContract: Setup = { registerAddFromLibraryType: jest.fn().mockImplementation(registerAddFromLibraryType), @@ -158,9 +109,6 @@ export const embeddablePluginMock = { createSetupContract, createStartContract, createInstance, - mockRefOrValEmbeddable, - mockSelfStyledEmbeddable, - mockFilterableEmbeddable, }; export const setStubKibanaServices = () => { diff --git a/src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx b/src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx index 49703371ac783..48e8cd52e1e68 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/attribute_service.tsx @@ -20,7 +20,7 @@ import { EmbeddableInput, SavedObjectEmbeddableInput, isSavedObjectEmbeddableInput, -} from '@kbn/embeddable-plugin/public'; +} from '@kbn/embeddable-plugin/common'; import { getNotifications } from '../../services'; /** diff --git a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx index 02f816a5983ba..1f631f30f8eb5 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx @@ -22,14 +22,8 @@ import type { DataView } from '@kbn/data-views-plugin/public'; import { Warnings } from '@kbn/charts-plugin/public'; import { hasUnsupportedDownsampledAggregationFailure } from '@kbn/search-response-warnings'; import { Adapters } from '@kbn/inspector-plugin/public'; -import { - Embeddable, - EmbeddableInput, - EmbeddableOutput, - FilterableEmbeddable, - ReferenceOrValueEmbeddable, - SavedObjectEmbeddableInput, -} from '@kbn/embeddable-plugin/public'; +import { Embeddable, EmbeddableInput, EmbeddableOutput } from '@kbn/embeddable-plugin/public'; +import { SavedObjectEmbeddableInput } from '@kbn/embeddable-plugin/common'; import { ExpressionAstExpression, ExpressionLoader, @@ -105,12 +99,7 @@ export type VisualizeByReferenceInput = SavedObjectEmbeddableInput & VisualizeIn * VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only * used within the visualize editor. */ -export class VisualizeEmbeddable - extends Embeddable - implements - ReferenceOrValueEmbeddable, - FilterableEmbeddable -{ +export class VisualizeEmbeddable extends Embeddable { private handler?: ExpressionLoader; private timefilter: TimefilterContract; private timeRange?: TimeRange; diff --git a/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.ts b/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.ts index 3ccbd30efd614..5b6c1a00a49c5 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.ts @@ -5,10 +5,9 @@ * 2.0. */ -import type { CellValueContext, IEmbeddable } from '@kbn/embeddable-plugin/public'; -import { isErrorEmbeddable } from '@kbn/embeddable-plugin/public'; +import type { CellValueContext } from '@kbn/embeddable-plugin/public'; import { createAction } from '@kbn/ui-actions-plugin/public'; -import { apiPublishesUnifiedSearch } from '@kbn/presentation-publishing'; +import { apiPublishesUnifiedSearch, hasBlockingError } from '@kbn/presentation-publishing'; import { isLensApi } from '@kbn/lens-plugin/public'; import { KibanaServices } from '../../../../common/lib/kibana'; import type { SecurityAppStore } from '../../../../common/store/types'; @@ -84,7 +83,7 @@ export const createAddToTimelineLensAction = ({ getIconType: () => ADD_TO_TIMELINE_ICON, getDisplayName: () => ADD_TO_TIMELINE, isCompatible: async ({ embeddable, data }) => - !isErrorEmbeddable(embeddable as IEmbeddable) && + !hasBlockingError(embeddable) && isLensApi(embeddable) && apiPublishesUnifiedSearch(embeddable) && isDataColumnsFilterable(data) && diff --git a/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.ts b/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.ts index 8546f0c3260cc..1b86bd3d02cee 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.ts @@ -6,9 +6,9 @@ */ import type { CellValueContext, IEmbeddable } from '@kbn/embeddable-plugin/public'; -import { isErrorEmbeddable } from '@kbn/embeddable-plugin/public'; import { createAction } from '@kbn/ui-actions-plugin/public'; import copy from 'copy-to-clipboard'; +import { hasBlockingError } from '@kbn/presentation-publishing'; import { KibanaServices } from '../../../../common/lib/kibana'; import { fieldHasCellActions, isCountField, isInSecurityApp, isLensEmbeddable } from '../../utils'; import { COPY_TO_CLIPBOARD, COPY_TO_CLIPBOARD_ICON, COPY_TO_CLIPBOARD_SUCCESS } from '../constants'; @@ -37,7 +37,7 @@ export const createCopyToClipboardLensAction = ({ order }: { order?: number }) = getIconType: () => COPY_TO_CLIPBOARD_ICON, getDisplayName: () => COPY_TO_CLIPBOARD, isCompatible: async ({ embeddable, data }) => - !isErrorEmbeddable(embeddable as IEmbeddable) && + !hasBlockingError(embeddable) && isLensEmbeddable(embeddable as IEmbeddable) && isDataColumnsValid(data) && isInSecurityApp(currentAppId), diff --git a/x-pack/solutions/security/plugins/security_solution/public/app/actions/filter/lens/create_action.ts b/x-pack/solutions/security/plugins/security_solution/public/app/actions/filter/lens/create_action.ts index 966efe9590ecc..d4903e9d9378d 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/app/actions/filter/lens/create_action.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/app/actions/filter/lens/create_action.ts @@ -11,7 +11,7 @@ import { filterOutNullableValues, valueToArray, } from '@kbn/cell-actions/actions/utils'; -import { isErrorEmbeddable } from '@kbn/embeddable-plugin/public'; +import { hasBlockingError } from '@kbn/presentation-publishing'; import type { CellValueContext, IEmbeddable } from '@kbn/embeddable-plugin/public'; import { createAction } from '@kbn/ui-actions-plugin/public'; import { ACTION_INCOMPATIBLE_VALUE_WARNING } from '@kbn/cell-actions/src/actions/translations'; @@ -77,7 +77,7 @@ export const createFilterLensAction = ({ }), type: DefaultCellActionTypes.FILTER, isCompatible: async ({ embeddable, data }) => - !isErrorEmbeddable(embeddable as IEmbeddable) && + !!hasBlockingError(embeddable) && isLensEmbeddable(embeddable as IEmbeddable) && isDataColumnsValid(data) && isInSecurityApp(currentAppId),