Skip to content

Commit

Permalink
[ML] clear selection action (#79834)
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov authored Oct 8, 2020
1 parent 7c1e809 commit 3d90401
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
}
},
Expand Down
36 changes: 36 additions & 0 deletions x-pack/plugins/ml/public/ui_actions/clear_selection_action.tsx
Original file line number Diff line number Diff line change
@@ -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';
},
});
}
11 changes: 10 additions & 1 deletion x-pack/plugins/ml/public/ui_actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand All @@ -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' {
Expand All @@ -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;
}
}

0 comments on commit 3d90401

Please sign in to comment.