Skip to content

Commit

Permalink
df exploration page: handle default isTraining filter in url
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Sep 28, 2020
1 parent c285287 commit d65c1f3
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 79 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;
isTraining?: string;
};
}

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

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

export const getDefaultTrainingFilterQuery = (resultsField: string, isTraining: boolean) => ({
bool: {
must: [
{
term: { [`${resultsField}.is_training`]: { value: 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;
isTraining?: 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, isTraining }) => (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.tableJobIdTitle',
{
defaultMessage: 'Destination index for classification job ID {jobId}',
values: { jobId },
}
)}
EvaluatePanel={EvaluatePanel}
isTraining={isTraining}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ interface Props {
jobId: string;
title: string;
EvaluatePanel: FC<EvaluatePanelProps>;
isTraining?: boolean;
}

export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel }) => {
export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel, isTraining }) => {
const {
indexPattern,
isInitialized,
Expand Down Expand Up @@ -70,6 +71,7 @@ export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel
needsDestIndexPattern={needsDestIndexPattern}
setEvaluateSearchQuery={setSearchQuery}
title={title}
isTraining={isTraining}
/>
)}
</>
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 Down Expand Up @@ -53,6 +54,7 @@ interface Props {
needsDestIndexPattern: boolean;
setEvaluateSearchQuery: React.Dispatch<React.SetStateAction<object>>;
title: string;
isTraining?: boolean;
}

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

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

useEffect(() => {
if (isTraining !== undefined) {
setSearchQuery(getDefaultTrainingFilterQuery(jobConfig.dest.results_field, isTraining));
setDefaultQueryString(`${jobConfig.dest.results_field}.is_training : ${isTraining}`);
}
}, []);

const analysisType = getAnalysisType(jobConfig.analysis);

const classificationData = useExplorationResults(
Expand Down Expand Up @@ -140,6 +151,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;
isTraining?: 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, isTraining }) => (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate('xpack.ml.dataframe.analytics.regressionExploration.tableJobIdTitle', {
defaultMessage: 'Destination index for regression job ID {jobId}',
values: { jobId },
})}
EvaluatePanel={EvaluatePanel}
isTraining={isTraining}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,58 @@ import { DataFrameAnalysisConfigType } from '../../../../../common/types/data_fr
export const Page: FC<{
jobId: string;
analysisType: DataFrameAnalysisConfigType;
}> = ({ jobId, analysisType }) => (
<Fragment>
<NavigationMenu tabId="data_frame_analytics" />
<EuiPage data-test-subj="mlPageDataFrameAnalyticsExploration">
<EuiPageBody style={{ maxWidth: 'calc(100% - 0px)' }}>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle>
<h1>
<FormattedMessage
id="xpack.ml.dataframe.analytics.exploration.title"
defaultMessage="Analytics exploration"
/>
<span>&nbsp;</span>
<EuiBetaBadge
label={i18n.translate(
'xpack.ml.dataframe.analytics.exploration.experimentalBadgeLabel',
{
defaultMessage: 'Experimental',
}
)}
tooltipContent={i18n.translate(
'xpack.ml.dataframe.analytics.exploration.experimentalBadgeTooltipContent',
{
defaultMessage: `Data frame analytics are an experimental feature. We'd love to hear your feedback.`,
}
)}
/>
</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody style={{ maxWidth: 'calc(100% - 0px)' }}>
<EuiSpacer size="l" />
{analysisType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && (
<OutlierExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.REGRESSION && (
<RegressionExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<ClassificationExploration jobId={jobId} />
)}
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
</Fragment>
);
isTraining?: string | boolean;
}> = ({ jobId, analysisType, isTraining }) => {
if (isTraining !== undefined) {
isTraining = isTraining === 'true';
}

return (
<Fragment>
<NavigationMenu tabId="data_frame_analytics" />
<EuiPage data-test-subj="mlPageDataFrameAnalyticsExploration">
<EuiPageBody style={{ maxWidth: 'calc(100% - 0px)' }}>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle>
<h1>
<FormattedMessage
id="xpack.ml.dataframe.analytics.exploration.title"
defaultMessage="Analytics exploration"
/>
<span>&nbsp;</span>
<EuiBetaBadge
label={i18n.translate(
'xpack.ml.dataframe.analytics.exploration.experimentalBadgeLabel',
{
defaultMessage: 'Experimental',
}
)}
tooltipContent={i18n.translate(
'xpack.ml.dataframe.analytics.exploration.experimentalBadgeTooltipContent',
{
defaultMessage: `Data frame analytics are an experimental feature. We'd love to hear your feedback.`,
}
)}
/>
</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody style={{ maxWidth: 'calc(100% - 0px)' }}>
<EuiSpacer size="l" />
{analysisType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && (
<OutlierExploration jobId={jobId} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.REGRESSION && (
<RegressionExploration jobId={jobId} isTraining={isTraining} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<ClassificationExploration jobId={jobId} isTraining={isTraining} />
)}
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
</Fragment>
);
};
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 isTraining: string | undefined = globalState.ml.isTraining;

return (
<PageLoader context={context}>
<Page {...{ jobId, analysisType }} />
<Page {...{ jobId, analysisType, isTraining }} />
</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, isTraining, globalState } = mlUrlGeneratorState;

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

0 comments on commit d65c1f3

Please sign in to comment.