Skip to content

Commit b19e909

Browse files
authored
[ML] clear selection action (#79834) (#79997)
1 parent c15f968 commit b19e909

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

x-pack/plugins/ml/public/embeddables/anomaly_swimlane/embeddable_swim_lane_container.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const EmbeddableSwimLaneContainer: FC<ExplorerSwimlaneContainerProps> = (
8585
uiActions.getTrigger(SWIM_LANE_SELECTION_TRIGGER).exec({
8686
embeddable: embeddableContext,
8787
data: update,
88+
updateCallback: setSelectedCells.bind(null, undefined),
8889
});
8990
}
9091
},
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { ActionContextMapping, createAction } from '../../../../../src/plugins/ui_actions/public';
9+
import { MlCoreSetup } from '../plugin';
10+
11+
export const CLEAR_SELECTION_ACTION = 'clearSelectionAction';
12+
13+
export interface ClearSelectionContext {
14+
updateCallback: () => void;
15+
}
16+
17+
export function createClearSelectionAction(getStartServices: MlCoreSetup['getStartServices']) {
18+
return createAction<typeof CLEAR_SELECTION_ACTION>({
19+
id: 'clear-selection-action',
20+
type: CLEAR_SELECTION_ACTION,
21+
getIconType(context: ActionContextMapping[typeof CLEAR_SELECTION_ACTION]): string {
22+
return 'cross';
23+
},
24+
getDisplayName: () =>
25+
i18n.translate('xpack.ml.actions.clearSelectionTitle', {
26+
defaultMessage: 'Clear selection',
27+
}),
28+
shouldAutoExecute: () => Promise.resolve(false),
29+
async execute({ updateCallback }: ClearSelectionContext) {
30+
updateCallback();
31+
},
32+
async isCompatible({ updateCallback }: ClearSelectionContext) {
33+
return typeof updateCallback === 'function';
34+
},
35+
});
36+
}

x-pack/plugins/ml/public/ui_actions/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import {
2626
createApplyTimeRangeSelectionAction,
2727
} from './apply_time_range_action';
2828
import { EditSwimlanePanelContext, SwimLaneDrilldownContext } from '../embeddables';
29+
import {
30+
CLEAR_SELECTION_ACTION,
31+
ClearSelectionContext,
32+
createClearSelectionAction,
33+
} from './clear_selection_action';
2934

3035
export { APPLY_TIME_RANGE_SELECTION_ACTION } from './apply_time_range_action';
3136
export { EDIT_SWIMLANE_PANEL_ACTION } from './edit_swimlane_panel_action';
@@ -46,12 +51,14 @@ export function registerMlUiActions(
4651
const openInExplorerAction = createOpenInExplorerAction(core.getStartServices);
4752
const applyInfluencerFiltersAction = createApplyInfluencerFiltersAction(core.getStartServices);
4853
const applyTimeRangeSelectionAction = createApplyTimeRangeSelectionAction(core.getStartServices);
54+
const clearSelectionAction = createClearSelectionAction(core.getStartServices);
4955

5056
// Register actions
5157
uiActions.registerAction(editSwimlanePanelAction);
5258
uiActions.registerAction(openInExplorerAction);
5359
uiActions.registerAction(applyInfluencerFiltersAction);
5460
uiActions.registerAction(applyTimeRangeSelectionAction);
61+
uiActions.registerAction(clearSelectionAction);
5562

5663
// Assign triggers
5764
uiActions.attachAction(CONTEXT_MENU_TRIGGER, editSwimlanePanelAction.id);
@@ -62,6 +69,7 @@ export function registerMlUiActions(
6269
uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, applyInfluencerFiltersAction);
6370
uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, applyTimeRangeSelectionAction);
6471
uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, openInExplorerAction);
72+
uiActions.addTriggerAction(SWIM_LANE_SELECTION_TRIGGER, clearSelectionAction);
6573
}
6674

6775
declare module '../../../../../src/plugins/ui_actions/public' {
@@ -70,9 +78,10 @@ declare module '../../../../../src/plugins/ui_actions/public' {
7078
[OPEN_IN_ANOMALY_EXPLORER_ACTION]: SwimLaneDrilldownContext;
7179
[APPLY_INFLUENCER_FILTERS_ACTION]: SwimLaneDrilldownContext;
7280
[APPLY_TIME_RANGE_SELECTION_ACTION]: SwimLaneDrilldownContext;
81+
[CLEAR_SELECTION_ACTION]: ClearSelectionContext;
7382
}
7483

7584
export interface TriggerContextMapping {
76-
[SWIM_LANE_SELECTION_TRIGGER]: SwimLaneDrilldownContext;
85+
[SWIM_LANE_SELECTION_TRIGGER]: SwimLaneDrilldownContext | ClearSelectionContext;
7786
}
7887
}

0 commit comments

Comments
 (0)