mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ML]DF Analytics exploration: default filter of results page by defaultIsTraining
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
This commit is contained in:
parent
3e426a0eab
commit
25682bf7ce
11 changed files with 80 additions and 34 deletions
|
@ -167,6 +167,7 @@ export interface DataFrameAnalyticsExplorationQueryState {
|
|||
ml: {
|
||||
jobId: JobId;
|
||||
analysisType: DataFrameAnalysisConfigType;
|
||||
defaultIsTraining?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -176,6 +177,7 @@ export type DataFrameAnalyticsExplorationUrlState = MLPageState<
|
|||
jobId: JobId;
|
||||
analysisType: DataFrameAnalysisConfigType;
|
||||
globalState?: MlCommonGlobalState;
|
||||
defaultIsTraining?: boolean;
|
||||
}
|
||||
>;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -8,6 +8,7 @@ export {
|
|||
getAnalysisType,
|
||||
getDependentVar,
|
||||
getPredictionFieldName,
|
||||
getDefaultTrainingFilterQuery,
|
||||
isOutlierAnalysis,
|
||||
refreshAnalyticsList$,
|
||||
useRefreshAnalyticsList,
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
|
@ -70,6 +76,7 @@ export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel
|
|||
needsDestIndexPattern={needsDestIndexPattern}
|
||||
setEvaluateSearchQuery={setSearchQuery}
|
||||
title={title}
|
||||
defaultIsTraining={defaultIsTraining}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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';
|
||||
|
@ -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',
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -140,6 +161,7 @@ export const ExplorationResultsTable: FC<Props> = React.memo(
|
|||
<ExplorationQueryBar
|
||||
indexPattern={indexPattern}
|
||||
setSearchQuery={setSearchQuery}
|
||||
defaultQueryString={defaultQueryString}
|
||||
/>
|
||||
</EuiFlexItem>
|
||||
</EuiFlexGroup>
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -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">
|
||||
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue