Skip to content

Commit

Permalink
[embeddable] remove EmbeddableInput type (elastic#211949)
Browse files Browse the repository at this point in the history
EmbeddableInput type is part of the legacy embeddable system. The legacy
embeddable system is being removed and as such, the EmbeddableInput type
is being removed.

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 04ee5fc)
  • Loading branch information
nreese committed Mar 6, 2025
1 parent edc74ba commit 47f0295
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { SavedObjectEmbeddableInput } from '@kbn/embeddable-plugin/common';
import type { Reference } from '@kbn/content-management-utils';

import type { GridData } from '../../server/content_management';
Expand All @@ -33,5 +32,3 @@ export interface DashboardPanelState<PanelState = object> {
*/
references?: Reference[];
}

export type DashboardContainerByReferenceInput = SavedObjectEmbeddableInput;
6 changes: 1 addition & 5 deletions src/platform/plugins/shared/dashboard/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

export type { DashboardCapabilities } from './types';

export type {
DashboardPanelMap,
DashboardPanelState,
DashboardContainerByReferenceInput,
} from './dashboard_container/types';
export type { DashboardPanelMap, DashboardPanelState } from './dashboard_container/types';

export {
type InjectExtractDeps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import type { SavedObjectMigrationFn } from '@kbn/core/server';
import type { EmbeddableInput } from '@kbn/embeddable-plugin/common';
import type { SavedDashboardPanel } from '../schema';

import {
Expand Down Expand Up @@ -36,14 +35,14 @@ export const migrateExplicitlyHiddenTitles: SavedObjectMigrationFn<any, any> = (
const newPanels: SavedDashboardPanel[] = [];
panels.forEach((panel) => {
// Convert each panel into the dashboard panel state
const originalPanelState = convertSavedDashboardPanelToPanelState<EmbeddableInput>(panel);
const originalPanelState = convertSavedDashboardPanelToPanelState(panel);
newPanels.push(
convertPanelStateToSavedDashboardPanel(panel.panelIndex, {
...originalPanelState,
explicitInput: {
...originalPanelState.explicitInput,
...(originalPanelState.explicitInput.title === '' &&
!originalPanelState.explicitInput.hidePanelTitles
...((originalPanelState.explicitInput as { title?: string }).title === '' &&
!(originalPanelState.explicitInput as { hidePanelTitles?: boolean }).hidePanelTitles
? { hidePanelTitles: true }
: {}),
},
Expand Down
3 changes: 0 additions & 3 deletions src/platform/plugins/shared/embeddable/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
*/

export type {
EmbeddableInput,
CommonEmbeddableStartContract,
EmbeddableStateWithType,
EmbeddablePersistableStateService,
EmbeddableRegistryDefinition,
} from './types';
export type { SavedObjectEmbeddableInput } from './lib';
export { isSavedObjectEmbeddableInput } from './lib';
2 changes: 0 additions & 2 deletions src/platform/plugins/shared/embeddable/common/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ export { getInjectFunction } from './inject';
export type { MigrateFunction } from './migrate';
export { getMigrateFunction } from './migrate';
export { getTelemetryFunction } from './telemetry';
export type { SavedObjectEmbeddableInput } from './saved_object_embeddable';
export { isSavedObjectEmbeddableInput } from './saved_object_embeddable';

This file was deleted.

53 changes: 0 additions & 53 deletions src/platform/plugins/shared/embeddable/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,12 @@
*/

import type { SerializableRecord } from '@kbn/utility-types';
import type { KibanaExecutionContext } from '@kbn/core/public';
import type {
PersistableStateService,
PersistableState,
PersistableStateDefinition,
} from '@kbn/kibana-utils-plugin/common';

export type EmbeddableInput = {
version?: string;
viewMode?: 'view' | 'edit' | 'print' | 'preview';
title?: string;
description?: string;
/**
* Note this is not a saved object id. It is used to uniquely identify this
* Embeddable instance from others (e.g. inside a container). It's possible to
* have two Embeddables where everything else is the same but the id.
*/
id: string;
lastReloadRequestTime?: number;
hidePanelTitles?: boolean;

/**
* Reserved key for enhancements added by other plugins.
*/
enhancements?: SerializableRecord;

/**
* List of action IDs that this embeddable should not render.
*/
disabledActions?: string[];

/**
* Whether this embeddable should not execute triggers.
*/
disableTriggers?: boolean;

/**
* Search session id to group searches
*/
searchSessionId?: string;

/**
* Flag whether colors should be synced with other panels
*/
syncColors?: boolean;

/**
* Flag whether cursor should be synced with other panels on hover
*/
syncCursor?: boolean;

/**
* Flag whether tooltips should be synced with other panels on hover
*/
syncTooltips?: boolean;

executionContext?: KibanaExecutionContext;
};

export type EmbeddableStateWithType = {
enhancements?: SerializableRecord;
type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
SaveResult,
showSaveModal,
} from '@kbn/saved-objects-plugin/public';
import {
EmbeddableInput,
SavedObjectEmbeddableInput,
isSavedObjectEmbeddableInput,
} from '@kbn/embeddable-plugin/common';
import { getNotifications } from '../../services';
import {
VisualizeByReferenceInput,
VisualizeByValueInput,
VisualizeSavedObjectAttributes,
} from './visualize_embeddable';

/**
* The attribute service is a shared, generic service that embeddables can use to provide the functionality
Expand All @@ -34,76 +34,57 @@ export const ATTRIBUTE_SERVICE_KEY = 'attributes';
export interface GenericAttributes {
title: string;
}
export interface AttributeServiceUnwrapResult<
SavedObjectAttributes extends GenericAttributes,
MetaInfo extends unknown = unknown
> {
attributes: SavedObjectAttributes;
metaInfo?: MetaInfo;
export interface AttributeServiceUnwrapResult {
attributes: VisualizeSavedObjectAttributes;
metaInfo?: unknown;
}
export interface AttributeServiceOptions<
SavedObjectAttributes extends GenericAttributes,
MetaInfo extends unknown = unknown
> {
export interface AttributeServiceOptions {
saveMethod: (
attributes: SavedObjectAttributes,
attributes: VisualizeSavedObjectAttributes,
savedObjectId?: string
) => Promise<{ id?: string } | { error: Error }>;
checkForDuplicateTitle: (props: OnSaveProps) => Promise<boolean>;
unwrapMethod?: (
savedObjectId: string
) => Promise<AttributeServiceUnwrapResult<SavedObjectAttributes, MetaInfo>>;
unwrapMethod?: (savedObjectId: string) => Promise<AttributeServiceUnwrapResult>;
}

export class AttributeService<
SavedObjectAttributes extends { title: string },
ValType extends EmbeddableInput & {
[ATTRIBUTE_SERVICE_KEY]: SavedObjectAttributes;
} = EmbeddableInput & { [ATTRIBUTE_SERVICE_KEY]: SavedObjectAttributes },
RefType extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput,
MetaInfo extends unknown = unknown
> {
constructor(
private type: string,
private options: AttributeServiceOptions<SavedObjectAttributes, MetaInfo>
) {}
export class AttributeService {
constructor(private type: string, private options: AttributeServiceOptions) {}

private async defaultUnwrapMethod(
input: RefType
): Promise<AttributeServiceUnwrapResult<SavedObjectAttributes, MetaInfo>> {
return Promise.resolve({ attributes: { ...(input as unknown as SavedObjectAttributes) } });
input: VisualizeByReferenceInput
): Promise<AttributeServiceUnwrapResult> {
return Promise.resolve({
attributes: { ...(input as unknown as VisualizeSavedObjectAttributes) },
});
}

public async unwrapAttributes(
input: RefType | ValType
): Promise<AttributeServiceUnwrapResult<SavedObjectAttributes, MetaInfo>> {
input: VisualizeByReferenceInput | VisualizeByValueInput
): Promise<AttributeServiceUnwrapResult> {
if (this.inputIsRefType(input)) {
return this.options.unwrapMethod
? await this.options.unwrapMethod(input.savedObjectId)
: await this.defaultUnwrapMethod(input);
}
return { attributes: (input as ValType)[ATTRIBUTE_SERVICE_KEY] };
return { attributes: (input as VisualizeByValueInput)[ATTRIBUTE_SERVICE_KEY] };
}

public async wrapAttributes(
newAttributes: SavedObjectAttributes,
newAttributes: VisualizeSavedObjectAttributes,
useRefType: boolean,
input?: ValType | RefType
): Promise<Omit<ValType | RefType, 'id'>> {
input?: VisualizeByValueInput | VisualizeByReferenceInput
): Promise<Omit<VisualizeByValueInput | VisualizeByReferenceInput, 'id'>> {
const originalInput = input ? input : {};
const savedObjectId =
input && this.inputIsRefType(input)
? (input as SavedObjectEmbeddableInput).savedObjectId
: undefined;
const savedObjectId = input && this.inputIsRefType(input) ? input.savedObjectId : undefined;
if (!useRefType) {
return { [ATTRIBUTE_SERVICE_KEY]: newAttributes } as ValType;
return { [ATTRIBUTE_SERVICE_KEY]: newAttributes } as VisualizeByValueInput;
}
try {
const savedItem = await this.options.saveMethod(newAttributes, savedObjectId);
if ('id' in savedItem) {
return { ...originalInput, savedObjectId: savedItem.id } as RefType;
return { ...originalInput, savedObjectId: savedItem.id } as VisualizeByReferenceInput;
}
return { ...originalInput } as RefType;
return { ...originalInput } as VisualizeByReferenceInput;
} catch (error) {
getNotifications().toasts.addDanger({
title: i18n.translate('visualizations.attributeService.saveToLibraryError', {
Expand All @@ -118,13 +99,17 @@ export class AttributeService<
}
}

inputIsRefType = (input: ValType | RefType): input is RefType => {
return isSavedObjectEmbeddableInput(input);
inputIsRefType = (
input: VisualizeByValueInput | VisualizeByReferenceInput
): input is VisualizeByReferenceInput => {
return Boolean((input as VisualizeByReferenceInput).savedObjectId);
};

getInputAsValueType = async (input: ValType | RefType): Promise<ValType> => {
getInputAsValueType = async (
input: VisualizeByValueInput | VisualizeByReferenceInput
): Promise<VisualizeByValueInput> => {
if (!this.inputIsRefType(input)) {
return input as ValType;
return input as VisualizeByValueInput;
}
const { attributes } = await this.unwrapAttributes(input);
const { savedObjectId, ...originalInputToPropagate } = input;
Expand All @@ -133,26 +118,26 @@ export class AttributeService<
...originalInputToPropagate,
// by value visualizations should not have default titles and/or descriptions
...{ attributes: omit(attributes, ['title', 'description']) },
} as unknown as ValType;
} as unknown as VisualizeByValueInput;
};

getInputAsRefType = async (
input: ValType | RefType,
input: VisualizeByValueInput | VisualizeByReferenceInput,
saveOptions?: { showSaveModal: boolean; saveModalTitle?: string } | { title: string }
): Promise<RefType> => {
): Promise<VisualizeByReferenceInput> => {
if (this.inputIsRefType(input)) {
return input;
}
return new Promise<RefType>((resolve, reject) => {
return new Promise<VisualizeByReferenceInput>((resolve, reject) => {
const onSave = async (props: OnSaveProps): Promise<SaveResult> => {
await this.options.checkForDuplicateTitle(props);
try {
const newAttributes = { ...(input as ValType)[ATTRIBUTE_SERVICE_KEY] };
const newAttributes = { ...(input as VisualizeByValueInput)[ATTRIBUTE_SERVICE_KEY] };
newAttributes.title = props.newTitle;
const wrappedInput = (await this.wrapAttributes(
newAttributes,
true
)) as unknown as RefType;
)) as unknown as VisualizeByReferenceInput;
// Remove unneeded attributes from the original input. Note that the original panel title
// is removed in favour of the new attributes title
const newInput = omit(input, [ATTRIBUTE_SERVICE_KEY, 'title']);
Expand All @@ -173,7 +158,7 @@ export class AttributeService<
title={get(
saveOptions,
'saveModalTitle',
(input as ValType)[ATTRIBUTE_SERVICE_KEY].title
(input as VisualizeByValueInput)[ATTRIBUTE_SERVICE_KEY].title
)}
showCopyOnSave={false}
objectType={this.type}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { Vis } from '../../types';
import type {
VisualizeInput,
VisualizeEmbeddable,
VisualizeByValueInput,
VisualizeByReferenceInput,
VisualizeSavedObjectAttributes,
VisualizeEmbeddableDeps,
} from './visualize_embeddable';
import { getHttp, getTimeFilter, getCapabilities } from '../../services';
Expand All @@ -32,11 +29,7 @@ export const createVisEmbeddableFromObject =
async (
vis: Vis,
input: Partial<VisualizeInput> & { id: string },
attributeService?: AttributeService<
VisualizeSavedObjectAttributes,
VisualizeByValueInput,
VisualizeByReferenceInput
>
attributeService?: AttributeService
): Promise<VisualizeEmbeddable | ErrorEmbeddable> => {
try {
const visId = vis.id as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import { KibanaExecutionContext } from '@kbn/core/types';
import { EmbeddableInput } from '@kbn/embeddable-plugin/common';
import { omitGenericEmbeddableInput, genericEmbeddableInputIsEqual } from './diff_embeddable_input';
import { EmbeddableInput } from './i_embeddable';

const getGenericEmbeddableState = (state?: Partial<EmbeddableInput>): EmbeddableInput => {
const defaultState: EmbeddableInput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import fastIsEqual from 'fast-deep-equal';
import { pick, omit } from 'lodash';
import type { EmbeddableInput } from '@kbn/embeddable-plugin/common';
import { EmbeddableInput } from './i_embeddable';

// list out the keys from the EmbeddableInput type to allow lodash to pick them later
const allGenericInputKeys: Readonly<Array<keyof EmbeddableInput>> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { merge } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, skip } from 'rxjs';
import { RenderCompleteDispatcher } from '@kbn/kibana-utils-plugin/public';
import { Adapters } from '@kbn/inspector-plugin/public';
import { EmbeddableInput } from '@kbn/embeddable-plugin/common';
import { EmbeddableError, EmbeddableOutput, IEmbeddable } from './i_embeddable';
import { EmbeddableError, EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable';
import { genericEmbeddableInputIsEqual, omitGenericEmbeddableInput } from './diff_embeddable_input';

function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) {
Expand Down
Loading

0 comments on commit 47f0295

Please sign in to comment.