From 88ba41f39a474f0815da26ac9cac2a2a57a832a8 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Sat, 25 Jan 2020 12:07:03 +0100 Subject: [PATCH] [ML] Anomaly Explorer: Fix cell selection when view-by is job id. (#55841) Fixes loading influencers, charts and anomaly table if view-by selection is job ID and cells in the overall swimlanes are selected. Previously, the check to return the job ids to filter on for the query would return the wrong value for a selection in the overall swimlane. This PR move the wrong and redundant code to a fixed util function getSelectionJobIds(). --- .../explorer/actions/load_explorer_data.ts | 9 ++------- .../application/explorer/explorer_utils.d.ts | 7 ++++++- .../application/explorer/explorer_utils.js | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/explorer/actions/load_explorer_data.ts b/x-pack/legacy/plugins/ml/public/application/explorer/actions/load_explorer_data.ts index ed734051342248..819db630c0609d 100644 --- a/x-pack/legacy/plugins/ml/public/application/explorer/actions/load_explorer_data.ts +++ b/x-pack/legacy/plugins/ml/public/application/explorer/actions/load_explorer_data.ts @@ -12,11 +12,11 @@ import { forkJoin, of, Observable, Subject } from 'rxjs'; import { mergeMap, switchMap, tap } from 'rxjs/operators'; import { anomalyDataChange } from '../explorer_charts/explorer_charts_container_service'; -import { VIEW_BY_JOB_LABEL } from '../explorer_constants'; import { explorerService } from '../explorer_dashboard_service'; import { getDateFormatTz, getSelectionInfluencers, + getSelectionJobIds, getSelectionTimeRange, loadAnnotationsTableData, loadAnomaliesTableData, @@ -114,12 +114,7 @@ function loadExplorerData(config: LoadExplorerDataConfig): Observable d.id); - + const jobIds = getSelectionJobIds(selectedCells, selectedJobs); const timerange = getSelectionTimeRange( selectedCells, swimlaneBucketInterval.asSeconds(), diff --git a/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.d.ts b/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.d.ts index 0ab75b1db29722..c60b2d55d86862 100644 --- a/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.d.ts +++ b/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.d.ts @@ -35,10 +35,15 @@ export declare const getDefaultSwimlaneData: () => SwimlaneData; export declare const getInfluencers: (selectedJobs: any[]) => string[]; +export declare const getSelectionJobIds: ( + selectedCells: AppStateSelectedCells | undefined, + selectedJobs: ExplorerJob[] +) => string[]; + export declare const getSelectionInfluencers: ( selectedCells: AppStateSelectedCells | undefined, fieldName: string -) => any[]; +) => string[]; interface SelectionTimeRange { earliestMs: number; diff --git a/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.js b/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.js index 14d356c0d1c81c..4818856b8a8d2e 100644 --- a/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.js +++ b/x-pack/legacy/plugins/ml/public/application/explorer/explorer_utils.js @@ -222,6 +222,19 @@ export function getSelectionInfluencers(selectedCells, fieldName) { return []; } +export function getSelectionJobIds(selectedCells, selectedJobs) { + if ( + selectedCells !== undefined && + selectedCells.type !== SWIMLANE_TYPE.OVERALL && + selectedCells.viewByFieldName !== undefined && + selectedCells.viewByFieldName === VIEW_BY_JOB_LABEL + ) { + return selectedCells.lanes; + } + + return selectedJobs.map(d => d.id); +} + export function getSwimlaneBucketInterval(selectedJobs, swimlaneContainerWidth) { // Bucketing interval should be the maximum of the chart related interval (i.e. time range related) // and the max bucket span for the jobs shown in the chart. @@ -587,10 +600,7 @@ export async function loadAnomaliesTableData( tableSeverity, influencersFilterQuery ) { - const jobIds = - selectedCells !== undefined && selectedCells.viewByFieldName === VIEW_BY_JOB_LABEL - ? selectedCells.lanes - : selectedJobs.map(d => d.id); + const jobIds = getSelectionJobIds(selectedCells, selectedJobs); const influencers = getSelectionInfluencers(selectedCells, fieldName); const timeRange = getSelectionTimeRange(selectedCells, interval, bounds);