From fee22e8d94177202b84bb1225133de36f0903049 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Fri, 24 Jan 2020 11:25:55 +0100 Subject: [PATCH] [ML] Anomaly Explorer: Fix view by selection when filter is active. (#55717) Fixes the view-by selection when a KQL filter gets active and restores previous behavior: - If the filter includes AND view-by switches to Job ID. - Otherwise the view-by selection switches to the first available option present in the KQL filter - Additionally, the view-by dropdown options get filtered down to the options present in the KQL filter --- .../explorer_reducer/set_influencer_filter_settings.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts b/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts index 8d083a396582..0d84179c572d 100644 --- a/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts +++ b/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts @@ -23,17 +23,20 @@ export function setInfluencerFilterSettings( const { selectedCells, viewBySwimlaneOptions } = state; let selectedViewByFieldName = state.viewBySwimlaneFieldName; + const filteredViewBySwimlaneOptions = viewBySwimlaneOptions.filter(d => + filteredFields.includes(d) + ); // if it's an AND filter set view by swimlane to job ID as the others will have no results - if (isAndOperator && selectedCells === null) { + if (isAndOperator && selectedCells === undefined) { selectedViewByFieldName = VIEW_BY_JOB_LABEL; } else { // Set View by dropdown to first relevant fieldName based on incoming filter if there's no cell selection already // or if selected cell is from overall swimlane as this won't include an additional influencer filter for (let i = 0; i < filteredFields.length; i++) { if ( - viewBySwimlaneOptions.includes(filteredFields[i]) && - (selectedCells === null || (selectedCells && selectedCells.type === 'overall')) + filteredViewBySwimlaneOptions.includes(filteredFields[i]) && + (selectedCells === undefined || (selectedCells && selectedCells.type === 'overall')) ) { selectedViewByFieldName = filteredFields[i]; break; @@ -53,5 +56,6 @@ export function setInfluencerFilterSettings( selectedViewByFieldName === VIEW_BY_JOB_LABEL || filteredFields.includes(selectedViewByFieldName) === false, viewBySwimlaneFieldName: selectedViewByFieldName, + viewBySwimlaneOptions: filteredViewBySwimlaneOptions, }; }