[embeddable] folder cleanup (#205219)

Clean up embeddable folder structure.

PR also splits `COMMON_EMBEDDABLE_GROUPING` into
`ADD_PANEL_ANNOTATION_GROUP`, `ADD_PANEL_LEGACY_GROUP`, and
`ADD_PANEL_OTHER_GROUP` to provide a more contextually relevant name.

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2025-01-07 10:27:50 -07:00 committed by GitHub
parent 0ed641ef4f
commit fd702efdd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 85 additions and 175 deletions

View file

@ -10,7 +10,7 @@
import { i18n } from '@kbn/i18n';
import { CanAddNewPanel } from '@kbn/presentation-containers';
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { ADD_PANEL_ANNOTATION_GROUP } from '@kbn/embeddable-plugin/public';
import { IncompatibleActionError, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
import {
ADD_IMAGE_EMBEDDABLE_ACTION_ID,
@ -48,7 +48,7 @@ export const registerCreateImageAction = () => {
// swallow the rejection, since this just means the user closed without saving
}
},
grouping: [COMMON_EMBEDDABLE_GROUPING.annotation],
grouping: [ADD_PANEL_ANNOTATION_GROUP],
getDisplayName: () =>
i18n.translate('imageEmbeddable.imageEmbeddableFactory.displayName', {
defaultMessage: 'Image',

View file

@ -9,7 +9,7 @@
import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { ADD_PANEL_TRIGGER, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { ADD_PANEL_ANNOTATION_GROUP } from '@kbn/embeddable-plugin/public';
import { APP_ICON, APP_NAME, CONTENT_ID } from '../../common';
import { uiActions } from '../services/kibana_services';
@ -38,7 +38,7 @@ export const registerCreateLinksPanelAction = () => {
initialState: runtimeState,
});
},
grouping: [COMMON_EMBEDDABLE_GROUPING.annotation],
grouping: [ADD_PANEL_ANNOTATION_GROUP],
getDisplayName: () => APP_NAME,
});
uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_LINKS_PANEL_ACTION_ID);

View file

@ -13,7 +13,7 @@ import {
addPanelMenuTrigger,
} from '@kbn/ui-actions-plugin/public';
import { PresentationContainer } from '@kbn/presentation-containers';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { ADD_PANEL_OTHER_GROUP } from '@kbn/embeddable-plugin/public';
import type { IconType, CommonProps } from '@elastic/eui';
import React, { type MouseEventHandler } from 'react';
@ -98,12 +98,12 @@ export const getAddPanelActionMenuItemsGroup = (
});
} else {
// use other group as the default for definitions that don't have a group
const fallbackGroup = COMMON_EMBEDDABLE_GROUPING.other;
const fallbackGroup = ADD_PANEL_OTHER_GROUP;
if (!grouped[fallbackGroup.id]) {
grouped[fallbackGroup.id] = {
id: fallbackGroup.id,
title: fallbackGroup.getDisplayName?.({ embeddable: api }) || '',
title: fallbackGroup.getDisplayName?.() || '',
'data-test-subj': `dashboardEditorMenu-${fallbackGroup.id}Group`,
order: fallbackGroup.order || 0,
items: [],

View file

@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { ADD_PANEL_ANNOTATION_GROUP, ADD_PANEL_LEGACY_GROUP } from '@kbn/embeddable-plugin/public';
import type { PresentationContainer } from '@kbn/presentation-containers';
import type { Action, UiActionsService } from '@kbn/ui-actions-plugin/public';
import { ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
@ -92,8 +92,8 @@ describe('Get dashboard panels hook', () => {
describe('augmenting ui action group items with dashboard visualization types', () => {
it.each([
['visualizations', VisGroups.PROMOTED],
[COMMON_EMBEDDABLE_GROUPING.legacy.id, VisGroups.LEGACY],
[COMMON_EMBEDDABLE_GROUPING.annotation.id, VisGroups.TOOLS],
[ADD_PANEL_LEGACY_GROUP.id, VisGroups.LEGACY],
[ADD_PANEL_ANNOTATION_GROUP.id, VisGroups.TOOLS],
])(
'includes in the ui action %s group, %s dashboard visualization group types',
async (uiActionGroupId, dashboardVisualizationGroupId) => {

View file

@ -10,7 +10,7 @@
import { useCallback, useMemo, useRef } from 'react';
import { AsyncSubject, defer, from, lastValueFrom, map, type Subscription } from 'rxjs';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { ADD_PANEL_ANNOTATION_GROUP, ADD_PANEL_LEGACY_GROUP } from '@kbn/embeddable-plugin/public';
import { PresentationContainer } from '@kbn/presentation-containers';
import { ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
import { VisGroups, type BaseVisType, type VisTypeAlias } from '@kbn/visualizations-plugin/public';
@ -155,7 +155,7 @@ export const useGetDashboardPanels = ({ api, createNewVisType }: UseGetDashboard
),
};
}
case COMMON_EMBEDDABLE_GROUPING.legacy.id: {
case ADD_PANEL_LEGACY_GROUP.id: {
return {
...panelGroup,
items: sortGroupPanelsByOrder<PanelSelectionMenuItem>(
@ -165,7 +165,7 @@ export const useGetDashboardPanels = ({ api, createNewVisType }: UseGetDashboard
),
};
}
case COMMON_EMBEDDABLE_GROUPING.annotation.id: {
case ADD_PANEL_ANNOTATION_GROUP.id: {
return {
...panelGroup,
items: sortGroupPanelsByOrder<PanelSelectionMenuItem>(

View file

@ -12,12 +12,13 @@ import { EmbeddablePublicPlugin } from './plugin';
export { useAddFromLibraryTypes } from './add_from_library/registry';
export { openAddFromLibraryFlyout } from './add_from_library/open_add_from_library_flyout';
export { PanelNotFoundError, PanelIncompatibleError } from './react_embeddable_system';
export { EmbeddableStateTransfer } from './state_transfer';
export {
cellValueTrigger,
CELL_VALUE_TRIGGER,
contextMenuTrigger,
CONTEXT_MENU_TRIGGER,
EmbeddableStateTransfer,
isMultiValueClickTriggerContext,
isRangeSelectTriggerContext,
isRowClickTriggerContext,
@ -25,26 +26,22 @@ export {
MULTI_VALUE_CLICK_TRIGGER,
panelBadgeTrigger,
panelHoverTrigger,
PanelNotFoundError,
PanelIncompatibleError,
panelNotificationTrigger,
PANEL_BADGE_TRIGGER,
PANEL_HOVER_TRIGGER,
PANEL_NOTIFICATION_TRIGGER,
SELECT_RANGE_TRIGGER,
VALUE_CLICK_TRIGGER,
ViewMode,
} from './lib';
} from './ui_actions/triggers';
export { ViewMode } from '../common/types';
export type {
CellValueContext,
ChartActionContext,
EmbeddableEditorState,
EmbeddablePackageState,
MultiValueClickContext,
PropertySpec,
RangeSelectContext,
ValueClickContext,
} from './lib';
} from './ui_actions/triggers';
export type { EmbeddableEditorState, EmbeddablePackageState } from './state_transfer';
export type { EmbeddableSetup, EmbeddableStart } from './types';
export type { EnhancementRegistryDefinition } from './enhancements/types';
@ -58,4 +55,8 @@ export function plugin(initializerContext: PluginInitializerContext) {
return new EmbeddablePublicPlugin(initializerContext);
}
export { COMMON_EMBEDDABLE_GROUPING } from './lib/embeddables/common/constants';
export {
ADD_PANEL_ANNOTATION_GROUP,
ADD_PANEL_OTHER_GROUP,
ADD_PANEL_LEGACY_GROUP,
} from './ui_actions/add_panel_groups';

View file

@ -1,39 +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 { i18n } from '@kbn/i18n';
import { UiActionsPresentableGroup } from '@kbn/ui-actions-plugin/public';
export const COMMON_EMBEDDABLE_GROUPING: { [key: string]: UiActionsPresentableGroup<unknown> } = {
annotation: {
id: 'annotation-and-navigation',
getDisplayName: () =>
i18n.translate('embeddableApi.common.constants.grouping.annotations', {
defaultMessage: 'Annotations and Navigation',
}),
order: 900, // This is the order of the group in the context menu
},
other: {
id: 'other',
getDisplayName: () =>
i18n.translate('embeddableApi.common.constants.grouping.other', {
defaultMessage: 'Other',
}),
getIconType: () => 'empty',
order: -1, // Given an item that doesn't specify a group is assigned zero, this forces other to come after all intentionally grouped section
},
legacy: {
id: 'legacy',
getDisplayName: () =>
i18n.translate('embeddableApi.common.constants.grouping.legacy', {
defaultMessage: 'Legacy',
}),
order: -2, // Given an item that doesn't specify a group is assigned zero, this forces it to the bottom of the list
},
};

View file

@ -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 { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { PanelNotFoundError } from './errors';
describe('IncompatibleActionError', () => {
test('is instance of error', () => {
const error = new IncompatibleActionError();
expect(error).toBeInstanceOf(Error);
});
test('has INCOMPATIBLE_ACTION code', () => {
const error = new IncompatibleActionError();
expect(error.code).toBe('INCOMPATIBLE_ACTION');
});
});
describe('PanelNotFoundError', () => {
test('is instance of error', () => {
const error = new PanelNotFoundError();
expect(error).toBeInstanceOf(Error);
});
test('has PANEL_NOT_FOUND code', () => {
const error = new PanelNotFoundError();
expect(error.code).toBe('PANEL_NOT_FOUND');
});
});

View file

@ -1,13 +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 * from './errors';
export * from './types';
export * from './triggers';
export * from './state_transfer';

View file

@ -1,29 +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 Trigger {
id: string;
title?: string;
description?: string;
}
export interface PropertySpec {
displayName: string;
accessPath: string;
id: string;
description: string;
value?: string;
}
export { ViewMode } from '../../common/types';
export interface CommonlyUsedRange {
from: string;
to: string;
display: string;
}

View file

@ -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 * from '@kbn/ui-actions-plugin/public';

View file

@ -17,8 +17,8 @@ import {
} from '@kbn/core/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { migrateToLatest } from '@kbn/kibana-utils-plugin/common';
import { bootstrap } from './bootstrap';
import { EmbeddableStateTransfer } from './lib/state_transfer';
import { registerTriggers } from './ui_actions/register_triggers';
import { EmbeddableStateTransfer } from './state_transfer';
import { EmbeddableStateWithType, CommonEmbeddableStartContract } from '../common/types';
import {
getExtractFunction,
@ -47,7 +47,7 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
constructor(initializerContext: PluginInitializerContext) {}
public setup(core: CoreSetup, { uiActions }: EmbeddableSetupDependencies) {
bootstrap(uiActions);
registerTriggers(uiActions);
return {
registerReactEmbeddableFactory,

View file

@ -7,6 +7,8 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
export { PanelIncompatibleError } from './panel_incompatible_error';
export { PanelNotFoundError } from './panel_not_found_error';
export { registerReactEmbeddableFactory } from './react_embeddable_registry';
export { ReactEmbeddableRenderer } from './react_embeddable_renderer';
export type { DefaultEmbeddableApi, ReactEmbeddableFactory } from './types';

View file

@ -7,21 +7,8 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
/* eslint-disable max-classes-per-file */
import { i18n } from '@kbn/i18n';
export class PanelNotFoundError extends Error {
code = 'PANEL_NOT_FOUND';
constructor() {
super(
i18n.translate('embeddableApi.errors.paneldoesNotExist', {
defaultMessage: 'Panel not found',
})
);
}
}
export class PanelIncompatibleError extends Error {
code = 'PANEL_INCOMPATIBLE';

View file

@ -7,4 +7,16 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
export * from './triggers';
import { i18n } from '@kbn/i18n';
export class PanelNotFoundError extends Error {
code = 'PANEL_NOT_FOUND';
constructor() {
super(
i18n.translate('embeddableApi.errors.paneldoesNotExist', {
defaultMessage: 'Panel not found',
})
);
}
}

View file

@ -17,7 +17,7 @@ import type { Storage } from '@kbn/kibana-utils-plugin/public';
import type { PersistableStateService } from '@kbn/kibana-utils-plugin/common';
import type { registerAddFromLibraryType } from './add_from_library/registry';
import type { registerReactEmbeddableFactory } from './react_embeddable_system';
import type { EmbeddableStateTransfer } from './lib';
import type { EmbeddableStateTransfer } from './state_transfer';
import type { EmbeddableStateWithType } from '../common';
import { EnhancementRegistryDefinition } from './enhancements/types';

View file

@ -0,0 +1,38 @@
/*
* 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 { i18n } from '@kbn/i18n';
export const ADD_PANEL_ANNOTATION_GROUP = {
id: 'annotation-and-navigation',
getDisplayName: () =>
i18n.translate('embeddableApi.common.constants.grouping.annotations', {
defaultMessage: 'Annotations and Navigation',
}),
order: 900, // This is the order of the group in the context menu
};
export const ADD_PANEL_OTHER_GROUP = {
id: 'other',
getDisplayName: () =>
i18n.translate('embeddableApi.common.constants.grouping.other', {
defaultMessage: 'Other',
}),
getIconType: () => 'empty',
order: -1, // Given an item that doesn't specify a group is assigned zero, this forces other to come after all intentionally grouped section
};
export const ADD_PANEL_LEGACY_GROUP = {
id: 'legacy',
getDisplayName: () =>
i18n.translate('embeddableApi.common.constants.grouping.legacy', {
defaultMessage: 'Legacy',
}),
order: -2, // Given an item that doesn't specify a group is assigned zero, this forces it to the bottom of the list
};

View file

@ -17,13 +17,9 @@ import {
valueClickTrigger,
cellValueTrigger,
panelHoverTrigger,
} from './lib';
} from './triggers';
/**
* This method initializes Embeddable plugin with initial set of
* triggers and actions.
*/
export const bootstrap = (uiActions: UiActionsSetup) => {
export const registerTriggers = (uiActions: UiActionsSetup) => {
uiActions.registerTrigger(contextMenuTrigger);
uiActions.registerTrigger(panelHoverTrigger);
uiActions.registerTrigger(panelBadgeTrigger);

View file

@ -14,7 +14,7 @@ import {
HasType,
HasAppContext,
} from '@kbn/presentation-publishing';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { ADD_PANEL_LEGACY_GROUP } from '@kbn/embeddable-plugin/public';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { apiHasType } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel, CanAddNewPanel } from '@kbn/presentation-containers';
@ -33,7 +33,7 @@ const isApiCompatible = (api: unknown | null): api is AddAggVisualizationPanelAc
export class AddAggVisualizationPanelAction implements Action<EmbeddableApiContext> {
public readonly type = ADD_AGG_VIS_ACTION_ID;
public readonly id = ADD_AGG_VIS_ACTION_ID;
public readonly grouping = [COMMON_EMBEDDABLE_GROUPING.legacy];
public readonly grouping = [ADD_PANEL_LEGACY_GROUP];
private readonly aggVisualizationCreationEnabled: boolean;
public readonly order = 20;