Skip to content

Commit

Permalink
clear defaultIsTraining filter from url once applied
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Sep 28, 2020
1 parent ae49242 commit 907a789
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 75 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/ml/common/types/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export interface DataFrameAnalyticsExplorationQueryState {
ml: {
jobId: JobId;
analysisType: DataFrameAnalysisConfigType;
isTraining?: string;
defaultIsTraining?: boolean;
};
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { EvaluatePanel } from './evaluate_panel';

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

export const ClassificationExploration: FC<Props> = ({ jobId, isTraining }) => (
export const ClassificationExploration: FC<Props> = ({ jobId, defaultIsTraining }) => (
<ExplorationPageWrapper
jobId={jobId}
title={i18n.translate(
Expand All @@ -27,6 +27,6 @@ export const ClassificationExploration: FC<Props> = ({ jobId, isTraining }) => (
}
)}
EvaluatePanel={EvaluatePanel}
isTraining={isTraining}
defaultIsTraining={defaultIsTraining}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ interface Props {
jobId: string;
title: string;
EvaluatePanel: FC<EvaluatePanelProps>;
isTraining?: boolean;
defaultIsTraining?: boolean;
}

export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel, isTraining }) => {
export const ExplorationPageWrapper: FC<Props> = ({
jobId,
title,
EvaluatePanel,
defaultIsTraining,
}) => {
const {
indexPattern,
isInitialized,
Expand Down Expand Up @@ -71,7 +76,7 @@ export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel,
needsDestIndexPattern={needsDestIndexPattern}
setEvaluateSearchQuery={setSearchQuery}
title={title}
isTraining={isTraining}
defaultIsTraining={defaultIsTraining}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,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 @@ -54,7 +55,7 @@ interface Props {
needsDestIndexPattern: boolean;
setEvaluateSearchQuery: React.Dispatch<React.SetStateAction<object>>;
title: string;
isTraining?: boolean;
defaultIsTraining?: boolean;
}

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

Expand All @@ -80,9 +82,17 @@ export const ExplorationResultsTable: FC<Props> = React.memo(
}, [JSON.stringify(searchQuery)]);

useEffect(() => {
if (isTraining !== undefined) {
setSearchQuery(getDefaultTrainingFilterQuery(jobConfig.dest.results_field, isTraining));
setDefaultQueryString(`${jobConfig.dest.results_field}.is_training : ${isTraining}`);
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,
});
}
}, []);

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;
defaultIsTraining?: boolean;
}

export const RegressionExploration: FC<Props> = ({ jobId, isTraining }) => (
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}
isTraining={isTraining}
defaultIsTraining={defaultIsTraining}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,52 @@ import { DataFrameAnalysisConfigType } from '../../../../../common/types/data_fr
export const Page: FC<{
jobId: string;
analysisType: DataFrameAnalysisConfigType;
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>
);
};
defaultIsTraining?: boolean;
}> = ({ jobId, analysisType, defaultIsTraining }) => (
<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} defaultIsTraining={defaultIsTraining} />
)}
{analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<ClassificationExploration jobId={jobId} defaultIsTraining={defaultIsTraining} />
)}
</EuiPageContentBody>
</EuiPageBody>
</EuiPage>
</Fragment>
);
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +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;
const defaultIsTraining: boolean | undefined = globalState.ml.defaultIsTraining;

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

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

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

0 comments on commit 907a789

Please sign in to comment.