From cda91cf0cb02c27827543d34489b905f8d253fa5 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 10 Jan 2020 13:07:28 +0000 Subject: [PATCH] [ML] Auto selecting categorization field (#54365) * [ML] Auto selecting categorization field * updating translations * reverting unrelated translation changes --- .../common/job_creator/util/general.ts | 8 +++---- .../categorization_field.tsx | 9 ++++---- .../categorization_field/description.tsx | 22 ++++++++++++++----- .../jobs/new_job/pages/new_job/page.tsx | 6 +++++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts index 22b727452dd8dc..6443539a9877da 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/util/general.ts @@ -297,10 +297,10 @@ export function getJobCreatorTitle(jobCreator: JobCreatorType) { return i18n.translate('xpack.ml.newJob.wizard.jobCreatorTitle.advanced', { defaultMessage: 'Advanced', }); - // case JOB_TYPE.CATEGORIZATION: - // return i18n.translate('xpack.ml.newJob.wizard.jobCreatorTitle.categorization', { - // defaultMessage: 'Categorization', - // }); + case JOB_TYPE.CATEGORIZATION: + return i18n.translate('xpack.ml.newJob.wizard.jobCreatorTitle.categorization', { + defaultMessage: 'Categorization', + }); default: return ''; } diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field.tsx b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field.tsx index 015300debb1569..7f7659d8bb6fd6 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field.tsx +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field.tsx @@ -10,19 +10,20 @@ import { CategorizationFieldSelect } from './categorization_field_select'; import { JobCreatorContext } from '../../../job_creator_context'; import { newJobCapsService } from '../../../../../../../services/new_job_capabilities_service'; import { - MultiMetricJobCreator, - PopulationJobCreator, AdvancedJobCreator, + CategorizationJobCreator, + isCategorizationJobCreator, } from '../../../../../common/job_creator'; import { Description } from './description'; export const CategorizationField: FC = () => { const { jobCreator: jc, jobCreatorUpdate, jobCreatorUpdated } = useContext(JobCreatorContext); - const jobCreator = jc as MultiMetricJobCreator | PopulationJobCreator | AdvancedJobCreator; + const jobCreator = jc as AdvancedJobCreator | CategorizationJobCreator; const { catFields } = newJobCapsService; const [categorizationFieldName, setCategorizationFieldName] = useState( jobCreator.categorizationFieldName ); + const isCategorizationJob = isCategorizationJobCreator(jobCreator); useEffect(() => { if (jobCreator.categorizationFieldName !== categorizationFieldName) { @@ -36,7 +37,7 @@ export const CategorizationField: FC = () => { }, [jobCreatorUpdated]); return ( - + { +interface Props { + isOptional: boolean; +} +export const Description: FC = memo(({ children, isOptional }) => { const title = i18n.translate('xpack.ml.newJob.wizard.pickFieldsStep.categorizationField.title', { defaultMessage: 'Categorization field', }); @@ -18,10 +21,19 @@ export const Description: FC = memo(({ children }) => { idAria="description" title={

{title}

} description={ - + <> + {isOptional ? ( + + ) : ( + + )} + } > diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/new_job/page.tsx b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/new_job/page.tsx index 3a37934e6203af..ece43e00f2eb1a 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/new_job/page.tsx +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/pages/new_job/page.tsx @@ -133,6 +133,12 @@ export const Page: FC = ({ existingJobsAndGroups, jobType }) => { // auto set the time range if creating a new advanced job autoSetTimeRange = isAdvancedJobCreator(jobCreator); initCategorizationSettings(); + if (isCategorizationJobCreator(jobCreator)) { + const { catFields } = newJobCapsService; + if (catFields.length === 1) { + jobCreator.categorizationFieldName = catFields[0].name; + } + } } if (autoSetTimeRange && isAdvancedJobCreator(jobCreator)) {