Skip to content

Commit

Permalink
[ML] Auto selecting categorization field (#54365)
Browse files Browse the repository at this point in the history
* [ML] Auto selecting categorization field

* updating translations

* reverting unrelated translation changes
  • Loading branch information
jgowdyelastic authored Jan 10, 2020
1 parent 9ee9f3d commit cda91cf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -36,7 +37,7 @@ export const CategorizationField: FC = () => {
}, [jobCreatorUpdated]);

return (
<Description>
<Description isOptional={isCategorizationJob === false}>
<CategorizationFieldSelect
fields={catFields}
changeHandler={setCategorizationFieldName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiDescribedFormGroup, EuiFormRow } from '@elastic/eui';

export const Description: FC = memo(({ children }) => {
interface Props {
isOptional: boolean;
}
export const Description: FC<Props> = memo(({ children, isOptional }) => {
const title = i18n.translate('xpack.ml.newJob.wizard.pickFieldsStep.categorizationField.title', {
defaultMessage: 'Categorization field',
});
Expand All @@ -18,10 +21,19 @@ export const Description: FC = memo(({ children }) => {
idAria="description"
title={<h3>{title}</h3>}
description={
<FormattedMessage
id="xpack.ml.newJob.wizard.pickFieldsStep.categorizationField.description"
defaultMessage="Optional, for use if analyzing unstructured log data. Using text data types is recommended."
/>
<>
{isOptional ? (
<FormattedMessage
id="xpack.ml.newJob.wizard.pickFieldsStep.categorizationFieldOptional.description"
defaultMessage="Optional, for use if analyzing unstructured log data. Using text data types is recommended."
/>
) : (
<FormattedMessage
id="xpack.ml.newJob.wizard.pickFieldsStep.categorizationField.description"
defaultMessage="Specifies which field will be categorized. Using text data types is recommended."
/>
)}
</>
}
>
<EuiFormRow label={title} describedByIds={['description']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export const Page: FC<PageProps> = ({ 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)) {
Expand Down

0 comments on commit cda91cf

Please sign in to comment.