Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Fix clear selection for the embeddable swim lane #79834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}