diff --git a/packages/kbn-ui-actions-browser/index.ts b/packages/kbn-ui-actions-browser/index.ts index 9662013cf99e3..076b77680826b 100644 --- a/packages/kbn-ui-actions-browser/index.ts +++ b/packages/kbn-ui-actions-browser/index.ts @@ -15,7 +15,5 @@ export { visualizeGeoFieldTrigger, ROW_CLICK_TRIGGER, rowClickTrigger, - CATEGORIZE_FIELD_TRIGGER, - categorizeFieldTrigger, defaultTrigger, } from './src/triggers'; diff --git a/packages/kbn-ui-actions-browser/src/triggers/categorize_field_trigger.ts b/packages/kbn-ui-actions-browser/src/triggers/categorize_field_trigger.ts deleted file mode 100644 index a332a21acb431..0000000000000 --- a/packages/kbn-ui-actions-browser/src/triggers/categorize_field_trigger.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 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 or the Server - * Side Public License, v 1. - */ - -import { Trigger } from './trigger'; - -export const CATEGORIZE_FIELD_TRIGGER = 'CATEGORIZE_FIELD_TRIGGER'; -export const categorizeFieldTrigger: Trigger = { - id: CATEGORIZE_FIELD_TRIGGER, - title: 'Run pattern analysis', - description: 'Triggered when user wants to run pattern analysis on a field.', -}; diff --git a/packages/kbn-ui-actions-browser/src/triggers/index.ts b/packages/kbn-ui-actions-browser/src/triggers/index.ts index 433a9cd6dff40..091305791d858 100644 --- a/packages/kbn-ui-actions-browser/src/triggers/index.ts +++ b/packages/kbn-ui-actions-browser/src/triggers/index.ts @@ -11,4 +11,3 @@ export * from './row_click_trigger'; export * from './default_trigger'; export * from './visualize_field_trigger'; export * from './visualize_geo_field_trigger'; -export * from './categorize_field_trigger'; diff --git a/packages/kbn-unified-field-list/src/components/field_categorize_button/categorize_trigger_utils.ts b/packages/kbn-unified-field-list/src/components/field_categorize_button/categorize_trigger_utils.ts index afeb34e6572af..007a88b2c7f97 100644 --- a/packages/kbn-unified-field-list/src/components/field_categorize_button/categorize_trigger_utils.ts +++ b/packages/kbn-unified-field-list/src/components/field_categorize_button/categorize_trigger_utils.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import type { UiActionsStart, CategorizeFieldContext } from '@kbn/ui-actions-plugin/public'; -import { CATEGORIZE_FIELD_TRIGGER } from '@kbn/ui-actions-browser/src/triggers'; +import type { UiActionsStart } from '@kbn/ui-actions-plugin/public'; +import { CATEGORIZE_FIELD_TRIGGER, type CategorizeFieldContext } from '@kbn/ml-ui-actions'; import type { DataViewField, DataView } from '@kbn/data-views-plugin/public'; async function getCompatibleActions( diff --git a/packages/kbn-unified-field-list/src/components/field_categorize_button/field_categorize_button.test.tsx b/packages/kbn-unified-field-list/src/components/field_categorize_button/field_categorize_button.test.tsx index 4e0d00b4549ca..45569b3443370 100644 --- a/packages/kbn-unified-field-list/src/components/field_categorize_button/field_categorize_button.test.tsx +++ b/packages/kbn-unified-field-list/src/components/field_categorize_button/field_categorize_button.test.tsx @@ -14,9 +14,12 @@ import { stubLogstashDataView as dataView } from '@kbn/data-views-plugin/common/ import { ActionInternal } from '@kbn/ui-actions-plugin/public'; import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks'; import { getFieldCategorizeButton } from './field_categorize_button'; -import { ACTION_CATEGORIZE_FIELD, CategorizeFieldContext } from '@kbn/ui-actions-plugin/public'; +import { + CATEGORIZE_FIELD_TRIGGER, + ACTION_CATEGORIZE_FIELD, + type CategorizeFieldContext, +} from '@kbn/ml-ui-actions'; import { TriggerContract } from '@kbn/ui-actions-plugin/public/triggers'; -import { CATEGORIZE_FIELD_TRIGGER } from '@kbn/ui-actions-browser'; const ORIGINATING_APP = 'test'; const mockExecuteAction = jest.fn(); diff --git a/packages/kbn-unified-field-list/tsconfig.json b/packages/kbn-unified-field-list/tsconfig.json index 27cbb23cf3d7c..eeca808e1bee7 100644 --- a/packages/kbn-unified-field-list/tsconfig.json +++ b/packages/kbn-unified-field-list/tsconfig.json @@ -31,6 +31,7 @@ "@kbn/ebt-tools", "@kbn/shared-ux-button-toolbar", "@kbn/field-utils", + "@kbn/ml-ui-actions", ], "exclude": ["target/**/*"] } diff --git a/src/plugins/ui_actions/public/index.ts b/src/plugins/ui_actions/public/index.ts index ede7098b7e916..d996b6b4e2cdc 100644 --- a/src/plugins/ui_actions/public/index.ts +++ b/src/plugins/ui_actions/public/index.ts @@ -31,14 +31,11 @@ export { visualizeGeoFieldTrigger, ROW_CLICK_TRIGGER, rowClickTrigger, - CATEGORIZE_FIELD_TRIGGER, - categorizeFieldTrigger, } from '@kbn/ui-actions-browser/src/triggers'; -export type { VisualizeFieldContext, CategorizeFieldContext } from './types'; +export type { VisualizeFieldContext } from './types'; export { ACTION_VISUALIZE_FIELD, ACTION_VISUALIZE_GEO_FIELD, ACTION_VISUALIZE_LENS_FIELD, - ACTION_CATEGORIZE_FIELD, } from './types'; export type { ActionExecutionContext, ActionExecutionMeta, ActionMenuItemProps } from './actions'; diff --git a/src/plugins/ui_actions/public/plugin.ts b/src/plugins/ui_actions/public/plugin.ts index 52629aa3f572d..16060d4bf3435 100644 --- a/src/plugins/ui_actions/public/plugin.ts +++ b/src/plugins/ui_actions/public/plugin.ts @@ -9,7 +9,6 @@ import { CoreStart, CoreSetup, Plugin, PluginInitializerContext } from '@kbn/core/public'; import { PublicMethodsOf } from '@kbn/utility-types'; import { - categorizeFieldTrigger, rowClickTrigger, visualizeFieldTrigger, visualizeGeoFieldTrigger, @@ -39,7 +38,6 @@ export class UiActionsPlugin implements Plugin { this.service.registerTrigger(rowClickTrigger); this.service.registerTrigger(visualizeFieldTrigger); this.service.registerTrigger(visualizeGeoFieldTrigger); - this.service.registerTrigger(categorizeFieldTrigger); return this.service; } diff --git a/src/plugins/ui_actions/public/types.ts b/src/plugins/ui_actions/public/types.ts index 6d689f6776d96..c66ea2b1769bd 100644 --- a/src/plugins/ui_actions/public/types.ts +++ b/src/plugins/ui_actions/public/types.ts @@ -7,7 +7,7 @@ */ import type { DatatableColumn } from '@kbn/expressions-plugin/common'; import type { AggregateQuery } from '@kbn/es-query'; -import type { DataViewField, DataViewSpec, DataView } from '@kbn/data-views-plugin/public'; +import type { DataViewSpec } from '@kbn/data-views-plugin/public'; import { ActionInternal } from './actions/action_internal'; import { TriggerInternal } from './triggers/trigger_internal'; @@ -24,13 +24,6 @@ export interface VisualizeFieldContext { query?: AggregateQuery; } -export interface CategorizeFieldContext { - field: DataViewField; - dataView: DataView; - originatingApp: string; -} - export const ACTION_VISUALIZE_FIELD = 'ACTION_VISUALIZE_FIELD'; export const ACTION_VISUALIZE_GEO_FIELD = 'ACTION_VISUALIZE_GEO_FIELD'; export const ACTION_VISUALIZE_LENS_FIELD = 'ACTION_VISUALIZE_LENS_FIELD'; -export const ACTION_CATEGORIZE_FIELD = 'ACTION_CATEGORIZE_FIELD'; diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index bb14c06a53e36..45bf932799b30 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -59,6 +59,7 @@ "packages/ml/date_picker", "packages/ml/trained_models_utils", "packages/ml/category_validator", + "packages/ml/ui_actions", "plugins/ml" ], "xpack.monitoring": ["plugins/monitoring"], diff --git a/x-pack/packages/ml/ui_actions/index.ts b/x-pack/packages/ml/ui_actions/index.ts index 8077406b58675..7a82ca6d68d9c 100644 --- a/x-pack/packages/ml/ui_actions/index.ts +++ b/x-pack/packages/ml/ui_actions/index.ts @@ -9,4 +9,11 @@ export { CREATE_PATTERN_ANALYSIS_TO_ML_AD_JOB_ACTION, CREATE_PATTERN_ANALYSIS_TO_ML_AD_JOB_TRIGGER, type CreateCategorizationADJobContext, -} from './src/ui_actions'; +} from './src/ml/ui_actions'; + +export { + ACTION_CATEGORIZE_FIELD, + CATEGORIZE_FIELD_TRIGGER, + categorizeFieldTrigger, + type CategorizeFieldContext, +} from './src/aiops/ui_actions'; diff --git a/x-pack/packages/ml/ui_actions/src/aiops/ui_actions.ts b/x-pack/packages/ml/ui_actions/src/aiops/ui_actions.ts new file mode 100644 index 0000000000000..b5e9ca07031ba --- /dev/null +++ b/x-pack/packages/ml/ui_actions/src/aiops/ui_actions.ts @@ -0,0 +1,34 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { DataView, DataViewField } from '@kbn/data-views-plugin/common'; +import { i18n } from '@kbn/i18n'; +import type { Trigger } from '@kbn/ui-actions-plugin/public'; + +export interface CategorizeFieldContext { + field: DataViewField; + dataView: DataView; + originatingApp: string; + additionalFilter?: { + from: number; + to: number; + field?: { name: string; value: string }; + }; +} + +export const ACTION_CATEGORIZE_FIELD = 'ACTION_CATEGORIZE_FIELD'; + +export const CATEGORIZE_FIELD_TRIGGER = 'CATEGORIZE_FIELD_TRIGGER'; +export const categorizeFieldTrigger: Trigger = { + id: CATEGORIZE_FIELD_TRIGGER, + title: i18n.translate('xpack.ml.actions.runPatternAnalysis.title', { + defaultMessage: 'Run pattern analysis', + }), + description: i18n.translate('xpack.ml.actions.runPatternAnalysis.description', { + defaultMessage: 'Triggered when user wants to run pattern analysis on a field.', + }), +}; diff --git a/x-pack/packages/ml/ui_actions/src/ui_actions.ts b/x-pack/packages/ml/ui_actions/src/ml/ui_actions.ts similarity index 100% rename from x-pack/packages/ml/ui_actions/src/ui_actions.ts rename to x-pack/packages/ml/ui_actions/src/ml/ui_actions.ts diff --git a/x-pack/packages/ml/ui_actions/tsconfig.json b/x-pack/packages/ml/ui_actions/tsconfig.json index 25ae95b59b163..ca3f66082b5c9 100644 --- a/x-pack/packages/ml/ui_actions/tsconfig.json +++ b/x-pack/packages/ml/ui_actions/tsconfig.json @@ -16,5 +16,7 @@ "kbn_references": [ "@kbn/data-views-plugin", "@kbn/es-query", + "@kbn/ui-actions-plugin", + "@kbn/i18n", ] } diff --git a/x-pack/plugins/aiops/public/components/log_categorization/categorize_field_actions.ts b/x-pack/plugins/aiops/public/components/log_categorization/categorize_field_actions.ts index 4d03465605463..761948ab8c4fd 100644 --- a/x-pack/plugins/aiops/public/components/log_categorization/categorize_field_actions.ts +++ b/x-pack/plugins/aiops/public/components/log_categorization/categorize_field_actions.ts @@ -6,22 +6,19 @@ */ import { i18n } from '@kbn/i18n'; -import { - createAction, - ACTION_CATEGORIZE_FIELD, - type CategorizeFieldContext, -} from '@kbn/ui-actions-plugin/public'; +import { createAction } from '@kbn/ui-actions-plugin/public'; import type { CoreStart } from '@kbn/core/public'; +import { ACTION_CATEGORIZE_FIELD, type CategorizeFieldContext } from '@kbn/ml-ui-actions'; import { AiopsPluginStartDeps } from '../../types'; import { showCategorizeFlyout } from './show_flyout'; -export const categorizeFieldAction = (coreStart: CoreStart, plugins: AiopsPluginStartDeps) => +export const createCategorizeFieldAction = (coreStart: CoreStart, plugins: AiopsPluginStartDeps) => createAction({ type: ACTION_CATEGORIZE_FIELD, id: ACTION_CATEGORIZE_FIELD, getDisplayName: () => i18n.translate('xpack.aiops.categorizeFieldAction.displayName', { - defaultMessage: 'Categorize field', + defaultMessage: 'Pattern analysis', }), isCompatible: async ({ field }: CategorizeFieldContext) => { return field.esTypes?.includes('text') === true; diff --git a/x-pack/plugins/aiops/public/components/log_categorization/index.ts b/x-pack/plugins/aiops/public/components/log_categorization/index.ts index 550add8802747..ace01d4f03389 100644 --- a/x-pack/plugins/aiops/public/components/log_categorization/index.ts +++ b/x-pack/plugins/aiops/public/components/log_categorization/index.ts @@ -7,7 +7,7 @@ export type { LogCategorizationAppStateProps } from './log_categorization_app_state'; import { LogCategorizationAppState } from './log_categorization_app_state'; -export { categorizeFieldAction } from './categorize_field_actions'; +export { createCategorizeFieldAction } from './categorize_field_actions'; // required for dynamic import using React.lazy() // eslint-disable-next-line import/no-default-export diff --git a/x-pack/plugins/aiops/public/plugin.tsx b/x-pack/plugins/aiops/public/plugin.tsx index c896ccc7d5b3e..12a7f659135ae 100755 --- a/x-pack/plugins/aiops/public/plugin.tsx +++ b/x-pack/plugins/aiops/public/plugin.tsx @@ -25,49 +25,38 @@ export class AiopsPlugin core: AiopsCoreSetup, { embeddable, cases, licensing, uiActions }: AiopsPluginSetupDeps ) { - firstValueFrom(licensing.license$).then(async (license) => { - if (license.hasAtLeast('platinum')) { - if (embeddable) { - const { registerEmbeddable } = await import('./embeddable/register_embeddable'); - registerEmbeddable(core, embeddable); - } + Promise.all([ + firstValueFrom(licensing.license$), + import('./embeddable/register_embeddable'), + import('./ui_actions'), + import('./cases/register_change_point_charts_attachment'), + core.getStartServices(), + ]).then( + ([ + license, + { registerEmbeddable }, + { registerAiopsUiActions }, + { registerChangePointChartsAttachment }, + [coreStart, pluginStart], + ]) => { + if (license.hasAtLeast('platinum')) { + if (embeddable) { + registerEmbeddable(core, embeddable); + } - if (uiActions) { - const { registerAiopsUiActions } = await import('./ui_actions'); - registerAiopsUiActions(uiActions, core); - } + if (uiActions) { + registerAiopsUiActions(uiActions, coreStart, pluginStart); + } - if (cases) { - const [coreStart, pluginStart] = await core.getStartServices(); - const { registerChangePointChartsAttachment } = await import( - './cases/register_change_point_charts_attachment' - ); - registerChangePointChartsAttachment(cases, coreStart, pluginStart); + if (cases) { + registerChangePointChartsAttachment(cases, coreStart, pluginStart); + } } } - }); + ); } public start(core: CoreStart, plugins: AiopsPluginStartDeps): AiopsPluginStart { - // importing async to keep the aiops plugin size to a minimum - Promise.all([ - import('@kbn/ui-actions-plugin/public'), - import('./components/log_categorization'), - firstValueFrom(plugins.licensing.license$), - ]).then(([uiActionsImports, { categorizeFieldAction }, license]) => { - if (license.hasAtLeast('platinum')) { - const { ACTION_CATEGORIZE_FIELD, CATEGORIZE_FIELD_TRIGGER } = uiActionsImports; - if (plugins.uiActions.hasAction(ACTION_CATEGORIZE_FIELD)) { - plugins.uiActions.unregisterAction(ACTION_CATEGORIZE_FIELD); - } - - plugins.uiActions.addTriggerAction( - CATEGORIZE_FIELD_TRIGGER, - categorizeFieldAction(core, plugins) - ); - } - }); - return { EmbeddableChangePointChart: getEmbeddableChangePointChart(core, plugins), }; diff --git a/x-pack/plugins/aiops/public/ui_actions/edit_change_point_charts_panel.tsx b/x-pack/plugins/aiops/public/ui_actions/edit_change_point_charts_panel.tsx index ae50937921f33..d9401f6064cbf 100644 --- a/x-pack/plugins/aiops/public/ui_actions/edit_change_point_charts_panel.tsx +++ b/x-pack/plugins/aiops/public/ui_actions/edit_change_point_charts_panel.tsx @@ -8,14 +8,16 @@ import type { UiActionsActionDefinition } from '@kbn/ui-actions-plugin/public'; import { i18n } from '@kbn/i18n'; import { ViewMode } from '@kbn/embeddable-plugin/common'; +import type { CoreStart } from '@kbn/core/public'; import { EMBEDDABLE_CHANGE_POINT_CHART_TYPE } from '../../common/constants'; import type { EditChangePointChartsPanelContext } from '../embeddable/types'; -import type { AiopsCoreSetup } from '../plugin'; +import type { AiopsPluginStartDeps } from '../types'; export const EDIT_CHANGE_POINT_CHARTS_ACTION = 'editChangePointChartsPanelAction'; export function createEditChangePointChartsPanelAction( - getStartServices: AiopsCoreSetup['getStartServices'] + coreStart: CoreStart, + pluginStart: AiopsPluginStartDeps ): UiActionsActionDefinition { return { id: 'edit-change-point-charts', @@ -32,8 +34,6 @@ export function createEditChangePointChartsPanelAction( throw new Error('Not possible to execute an action without the embeddable context'); } - const [coreStart, pluginStart] = await getStartServices(); - try { const { resolveEmbeddableChangePointUserInput } = await import( '../embeddable/handle_explicit_input' diff --git a/x-pack/plugins/aiops/public/ui_actions/index.ts b/x-pack/plugins/aiops/public/ui_actions/index.ts index cd00842c662c8..14e1879027fff 100644 --- a/x-pack/plugins/aiops/public/ui_actions/index.ts +++ b/x-pack/plugins/aiops/public/ui_actions/index.ts @@ -7,16 +7,33 @@ import type { UiActionsSetup } from '@kbn/ui-actions-plugin/public'; import { CONTEXT_MENU_TRIGGER } from '@kbn/embeddable-plugin/public'; +import { + categorizeFieldTrigger, + CATEGORIZE_FIELD_TRIGGER, +} from '@kbn/ml-ui-actions/src/aiops/ui_actions'; + +import type { CoreStart } from '@kbn/core/public'; +import type { AiopsPluginStartDeps } from '../types'; import { createEditChangePointChartsPanelAction } from './edit_change_point_charts_panel'; -import type { AiopsCoreSetup } from '../plugin'; +import { createCategorizeFieldAction } from '../components/log_categorization'; -export function registerAiopsUiActions(uiActions: UiActionsSetup, core: AiopsCoreSetup) { +export function registerAiopsUiActions( + uiActions: UiActionsSetup, + coreStart: CoreStart, + pluginStart: AiopsPluginStartDeps +) { // Initialize actions const editChangePointChartPanelAction = createEditChangePointChartsPanelAction( - core.getStartServices + coreStart, + pluginStart + ); + // // Register actions and triggers + uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, editChangePointChartPanelAction); + + uiActions.registerTrigger(categorizeFieldTrigger); + + uiActions.addTriggerAction( + CATEGORIZE_FIELD_TRIGGER, + createCategorizeFieldAction(coreStart, pluginStart) ); - // Register actions - uiActions.registerAction(editChangePointChartPanelAction); - // Assign and register triggers - uiActions.attachAction(CONTEXT_MENU_TRIGGER, editChangePointChartPanelAction.id); }