Skip to content

Commit

Permalink
[ML]DF Analytics exploration: default filter of results page by `defa…
Browse files Browse the repository at this point in the history
…ultIsTraining` value in url (#78303)

* df exploration page: handle default isTraining filter in url

* default training query updated to match what the searchBar would produce. fixes evaluate panel dataset label

* clear defaultIsTraining filter from url once applied
  • Loading branch information
alvarezmelissa87 authored Sep 28, 2020
1 parent 3e426a0 commit 25682bf
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 34 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/common/types/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export interface DataFrameAnalyticsExplorationQueryState {
ml: {
jobId: JobId;
analysisType: DataFrameAnalysisConfigType;
defaultIsTraining?: boolean;
};
}

Expand All @@ -176,6 +177,7 @@ export type DataFrameAnalyticsExplorationUrlState = MLPageState<
jobId: JobId;
analysisType: DataFrameAnalysisConfigType;
globalState?: MlCommonGlobalState;
defaultIsTraining?: boolean;
}
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ export const defaultSearchQuery = {
match_all: {},
};

export const getDefaultTrainingFilterQuery = (resultsField: string, isTraining: boolean) => ({
bool: {
minimum_should_match: 1,
should: [
{
match: { [`${resultsField}.is_training`]: isTraining },
},
],
},
});

export interface SearchQuery {
track_total_hits?: boolean;
query: SavedSearchQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
getAnalysisType,
getDependentVar,
getPredictionFieldName,
getDefaultTrainingFilterQuery,
isOutlierAnalysis,
refreshAnalyticsList$,
useRefreshAnalyticsList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import { EvaluatePanel } from './evaluate_panel';

interface Props {
jobId: string;
defaultIsTraining?: boolean;
}

export const ClassificationExploration: FC<Props> = ({ jobId }) => {
return (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.tableJobIdTitle',
{
defaultMessage: 'Destination index for classification job ID {jobId}',
values: { jobId },
}
)}
EvaluatePanel={EvaluatePanel}
/>
);
};
export const ClassificationExploration: FC<Props> = ({ jobId, defaultIsTraining }) => (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.tableJobIdTitle',
{
defaultMessage: 'Destination index for classification job ID {jobId}',
values: { jobId },
}
)}
EvaluatePanel={EvaluatePanel}
defaultIsTraining={defaultIsTraining}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ interface Props {
jobId: string;
title: string;
EvaluatePanel: FC<EvaluatePanelProps>;
defaultIsTraining?: boolean;
}

export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel }) => {
export const ExplorationPageWrapper: FC<Props> = ({
jobId,
title,
EvaluatePanel,
defaultIsTraining,
}) => {
const {
indexPattern,
isInitialized,
Expand Down Expand Up @@ -70,6 +76,7 @@ export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel
needsDestIndexPattern={needsDestIndexPattern}
setEvaluateSearchQuery={setSearchQuery}
title={title}
defaultIsTraining={defaultIsTraining}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
if (defaultQueryString !== undefined) {
setSearchInput({ query: defaultQueryString, language: SEARCH_QUERY_LANGUAGE.KUERY });
}
}, []);
}, [defaultQueryString !== undefined]);

const searchChangeHandler = (query: Query) => setSearchInput(query);
const searchSubmitHandler = (query: Query) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SEARCH_SIZE,
defaultSearchQuery,
getAnalysisType,
getDefaultTrainingFilterQuery,
} from '../../../../common';
import { getTaskStateBadge } from '../../../analytics_management/components/analytics_list/use_columns';
import { DATA_FRAME_TASK_STATE } from '../../../analytics_management/components/analytics_list/common';
Expand All @@ -30,6 +31,7 @@ import { IndexPatternPrompt } from '../index_pattern_prompt';
import { useExplorationResults } from './use_exploration_results';
import { useMlKibana } from '../../../../../contexts/kibana';
import { DataFrameAnalysisConfigType } from '../../../../../../../common/types/data_frame_analytics';
import { useUrlState } from '../../../../../util/url_state';

const showingDocs = i18n.translate(
'xpack.ml.dataframe.analytics.explorationResults.documentsShownHelpText',
Expand All @@ -53,6 +55,7 @@ interface Props {
needsDestIndexPattern: boolean;
setEvaluateSearchQuery: React.Dispatch<React.SetStateAction<object>>;
title: string;
defaultIsTraining?: boolean;
}

export const ExplorationResultsTable: FC<Props> = React.memo(
Expand All @@ -63,18 +66,36 @@ export const ExplorationResultsTable: FC<Props> = React.memo(
needsDestIndexPattern,
setEvaluateSearchQuery,
title,
defaultIsTraining,
}) => {
const {
services: {
mlServices: { mlApiServices },
},
} = useMlKibana();
const [globalState, setGlobalState] = useUrlState('_g');
const [searchQuery, setSearchQuery] = useState<SavedSearchQuery>(defaultSearchQuery);
const [defaultQueryString, setDefaultQueryString] = useState<string | undefined>();

useEffect(() => {
setEvaluateSearchQuery(searchQuery);
}, [JSON.stringify(searchQuery)]);

useEffect(() => {
if (defaultIsTraining !== undefined) {
// Apply defaultIsTraining filter
setSearchQuery(
getDefaultTrainingFilterQuery(jobConfig.dest.results_field, defaultIsTraining)
);
setDefaultQueryString(`${jobConfig.dest.results_field}.is_training : ${defaultIsTraining}`);
// Clear defaultIsTraining from url
setGlobalState('ml', {
analysisType: globalState.ml.analysisType,
jobId: globalState.ml.jobId,
});
}
}, []);

const analysisType = getAnalysisType(jobConfig.analysis);

const classificationData = useExplorationResults(
Expand Down Expand Up @@ -140,6 +161,7 @@ export const ExplorationResultsTable: FC<Props> = React.memo(
<ExplorationQueryBar
indexPattern={indexPattern}
setSearchQuery={setSearchQuery}
defaultQueryString={defaultQueryString}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import { EvaluatePanel } from './evaluate_panel';

interface Props {
jobId: string;
defaultIsTraining?: boolean;
}

export const RegressionExploration: FC<Props> = ({ jobId }) => {
return (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate('xpack.ml.dataframe.analytics.regressionExploration.tableJobIdTitle', {
defaultMessage: 'Destination index for regression job ID {jobId}',
values: { jobId },
})}
EvaluatePanel={EvaluatePanel}
/>
);
};
export const RegressionExploration: FC<Props> = ({ jobId, defaultIsTraining }) => (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate('xpack.ml.dataframe.analytics.regressionExploration.tableJobIdTitle', {
defaultMessage: 'Destination index for regression job ID {jobId}',
values: { jobId },
})}
EvaluatePanel={EvaluatePanel}
defaultIsTraining={defaultIsTraining}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { DataFrameAnalysisConfigType } from '../../../../../common/types/data_fr
export const Page: FC<{
jobId: string;
analysisType: DataFrameAnalysisConfigType;
}> = ({ jobId, analysisType }) => (
defaultIsTraining?: boolean;
}> = ({ jobId, analysisType, defaultIsTraining }) => (
<Fragment>
<NavigationMenu tabId="data_frame_analytics" />
<EuiPage data-test-subj="mlPageDataFrameAnalyticsExploration">
Expand Down Expand Up @@ -70,10 +71,10 @@ export const Page: FC<{
<OutlierExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.REGRESSION && (
<RegressionExploration jobId={jobId} />
<RegressionExploration jobId={jobId} defaultIsTraining={defaultIsTraining} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<ClassificationExploration jobId={jobId} />
<ClassificationExploration jobId={jobId} defaultIsTraining={defaultIsTraining} />
)}
</EuiPageContentBody>
</EuiPageBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ const PageWrapper: FC<PageProps> = ({ location, deps }) => {
}
const jobId: string = globalState.ml.jobId;
const analysisType: DataFrameAnalysisConfigType = globalState.ml.analysisType;
const defaultIsTraining: boolean | undefined = globalState.ml.defaultIsTraining;

return (
<PageLoader context={context}>
<Page {...{ jobId, analysisType }} />
<Page {...{ jobId, analysisType, defaultIsTraining }} />
</PageLoader>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ export function createDataFrameAnalyticsExplorationUrl(
let url = `${appBasePath}/${ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION}`;

if (mlUrlGeneratorState) {
const { jobId, analysisType, globalState } = mlUrlGeneratorState;
const { jobId, analysisType, defaultIsTraining, globalState } = mlUrlGeneratorState;

const queryState: DataFrameAnalyticsExplorationQueryState = {
ml: {
jobId,
analysisType,
defaultIsTraining,
},
...globalState,
};
Expand Down

0 comments on commit 25682bf

Please sign in to comment.