From 91742cb6734bea180d99d4a97f8d2bf0ffe927cc Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 8 Oct 2020 10:04:23 +0200 Subject: [PATCH] [ML] clear selection action (#79834) --- .../embeddable_swim_lane_container.tsx | 1 + .../ui_actions/clear_selection_action.tsx | 36 +++++++++++++++++++ x-pack/plugins/ml/public/ui_actions/index.ts | 11 +++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/ml/public/ui_actions/clear_selection_action.tsx diff --git a/x-pack/plugins/ml/public/embeddables/anomaly_swimlane/embeddable_swim_lane_container.tsx b/x-pack/plugins/ml/public/embeddables/anomaly_swimlane/embeddable_swim_lane_container.tsx index d638e2c231468..17ae97e3c07bb 100644 --- a/x-pack/plugins/ml/public/embeddables/anomaly_swimlane/embeddable_swim_lane_container.tsx +++ b/x-pack/plugins/ml/public/embeddables/anomaly_swimlane/embeddable_swim_lane_container.tsx @@ -85,6 +85,7 @@ export const EmbeddableSwimLaneContainer: FC = ( uiActions.getTrigger(SWIM_LANE_SELECTION_TRIGGER).exec({ embeddable: embeddableContext, data: update, + updateCallback: setSelectedCells.bind(null, undefined), }); } }, diff --git a/x-pack/plugins/ml/public/ui_actions/clear_selection_action.tsx b/x-pack/plugins/ml/public/ui_actions/clear_selection_action.tsx new file mode 100644 index 0000000000000..acafc787d05c2 --- /dev/null +++ b/x-pack/plugins/ml/public/ui_actions/clear_selection_action.tsx @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +import { ActionContextMapping, createAction } from '../../../../../src/plugins/ui_actions/public'; +import { MlCoreSetup } from '../plugin'; + +export const CLEAR_SELECTION_ACTION = 'clearSelectionAction'; + +export interface ClearSelectionContext { + updateCallback: () => void; +} + +export function createClearSelectionAction(getStartServices: MlCoreSetup['getStartServices']) { + return createAction({ + id: 'clear-selection-action', + type: CLEAR_SELECTION_ACTION, + getIconType(context: ActionContextMapping[typeof CLEAR_SELECTION_ACTION]): string { + return 'cross'; + }, + getDisplayName: () => + i18n.translate('xpack.ml.actions.clearSelectionTitle', { + defaultMessage: 'Clear selection', + }), + shouldAutoExecute: () => Promise.resolve(false), + async execute({ updateCallback }: ClearSelectionContext) { + updateCallback(); + }, + async isCompatible({ updateCallback }: ClearSelectionContext) { + return typeof updateCallback === 'function'; + }, + }); +} diff --git a/x-pack/plugins/ml/public/ui_actions/index.ts b/x-pack/plugins/ml/public/ui_actions/index.ts index 437a38acf6f8b..2b01a74070b22 100644 --- a/x-pack/plugins/ml/public/ui_actions/index.ts +++ b/x-pack/plugins/ml/public/ui_actions/index.ts @@ -26,6 +26,11 @@ import { createApplyTimeRangeSelectionAction, } from './apply_time_range_action'; import { EditSwimlanePanelContext, SwimLaneDrilldownContext } from '../embeddables'; +import { + CLEAR_SELECTION_ACTION, + ClearSelectionContext, + createClearSelectionAction, +} from './clear_selection_action'; export { APPLY_TIME_RANGE_SELECTION_ACTION } from './apply_time_range_action'; export { EDIT_SWIMLANE_PANEL_ACTION } from './edit_swimlane_panel_action'; @@ -46,12 +51,14 @@ export function registerMlUiActions( const openInExplorerAction = createOpenInExplorerAction(core.getStartServices); const applyInfluencerFiltersAction = createApplyInfluencerFiltersAction(core.getStartServices); const applyTimeRangeSelectionAction = createApplyTimeRangeSelectionAction(core.getStartServices); + const clearSelectionAction = createClearSelectionAction(core.getStartServices); // Register actions uiActions.registerAction(editSwimlanePanelAction); uiActions.registerAction(openInExplorerAction); uiActions.registerAction(applyInfluencerFiltersAction); uiActions.registerAction(applyTimeRangeSelectionAction); + uiActions.registerAction(clearSelectionAction); // Assign triggers uiActions.attachAction(CONTEXT_MENU_TRIGGER, editSwimlanePanelAction.id); @@ -62,6 +69,7 @@ export function registerMlUiActions( uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, applyInfluencerFiltersAction); uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, applyTimeRangeSelectionAction); uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, openInExplorerAction); + uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, clearSelectionAction); } declare module '../../../../../src/plugins/ui_actions/public' { @@ -70,9 +78,10 @@ declare module '../../../../../src/plugins/ui_actions/public' { [OPEN_IN_ANOMALY_EXPLORER_ACTION]: SwimLaneDrilldownContext; [APPLY_INFLUENCER_FILTERS_ACTION]: SwimLaneDrilldownContext; [APPLY_TIME_RANGE_SELECTION_ACTION]: SwimLaneDrilldownContext; + [CLEAR_SELECTION_ACTION]: ClearSelectionContext; } export interface TriggerContextMapping { - [SWIM_LANE_SELECTION_TRIGGER]: SwimLaneDrilldownContext; + [SWIM_LANE_SELECTION_TRIGGER]: SwimLaneDrilldownContext | ClearSelectionContext; } }