[ML] clear selection action (#79834)

This commit is contained in:
Dima Arnautov 2020-10-08 10:04:23 +02:00 committed by GitHub
parent 7c1e809555
commit 3d90401b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 1 deletions

View file

@ -85,6 +85,7 @@ export const EmbeddableSwimLaneContainer: FC<ExplorerSwimlaneContainerProps> = (
uiActions.getTrigger(SWIM_LANE_SELECTION_TRIGGER).exec({
embeddable: embeddableContext,
data: update,
updateCallback: setSelectedCells.bind(null, undefined),
});
}
},

View file

@ -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<typeof CLEAR_SELECTION_ACTION>({
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';
},
});
}

View file

@ -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;
}
}