Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Fixing missing advanced job summary items #48537

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export enum CREATED_BY_LABEL {

export const DEFAULT_MODEL_MEMORY_LIMIT = '10MB';
export const DEFAULT_BUCKET_SPAN = '15m';
export const DEFAULT_QUERY_DELAY = '60s';

export const SHARED_RESULTS_INDEX_NAME = 'shared';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { EuiFieldText } from '@elastic/eui';
import { JobCreatorContext } from '../../../job_creator_context';
import { Description } from './description';
import { useStringifiedValue } from '../hooks';

const DEFAULT_QUERY_DELAY = '60s';
import { DEFAULT_QUERY_DELAY } from '../../../../../common/job_creator/util/constants';

export const QueryDelayInput: FC = () => {
const { jobCreator, jobCreatorUpdate, jobValidator, jobValidatorUpdated } = useContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { FC, useState, useContext, useEffect } from 'react';
import { EuiFieldNumber } from '@elastic/eui';
import { newJobDefaults } from '../../../../../../new_job_new/utils/new_job_defaults';
import { newJobDefaults } from '../../../../../utils/new_job_defaults';
import { JobCreatorContext } from '../../../job_creator_context';
import { Description } from './description';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import React, { Fragment, FC, useEffect, useState } from 'react';
import { EuiHorizontalRule } from '@elastic/eui';

import { AdvancedDetectors } from './metric_selection';
import { AdvancedDetectorsSummary } from './metric_selection_summary';
import { AdvancedSettings } from './settings';
import { ExtraSettings } from './extra';

interface Props {
isActive: boolean;
setCanProceed?: (proceed: boolean) => void;
}

export const AdvancedView: FC<Props> = ({ setCanProceed }) => {
export const AdvancedView: FC<Props> = ({ isActive, setCanProceed }) => {
const [metricsValid, setMetricValid] = useState(false);
const [settingsValid, setSettingsValid] = useState(false);

Expand All @@ -27,13 +29,17 @@ export const AdvancedView: FC<Props> = ({ setCanProceed }) => {

return (
<Fragment>
<Fragment>
<ExtraSettings />
<EuiHorizontalRule margin="l" />
<AdvancedDetectors setIsValid={setMetricValid} />
<EuiHorizontalRule margin="l" />
<AdvancedSettings setIsValid={setSettingsValid} />
</Fragment>
{isActive === false ? (
<AdvancedDetectorsSummary />
) : (
<Fragment>
<ExtraSettings />
<EuiHorizontalRule margin="l" />
<AdvancedDetectors setIsValid={setMetricValid} />
<EuiHorizontalRule margin="l" />
<AdvancedSettings setIsValid={setSettingsValid} />
</Fragment>
)}
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import { AdvancedJobCreator } from '../../../../../common/job_creator';
import { detectorToString } from '../../../../../../../util/string_utils';

interface Props {
isActive: boolean;
onEditJob: (i: number) => void;
onDeleteJob: (i: number) => void;
}

export const DetectorList: FC<Props> = ({ onEditJob, onDeleteJob }) => {
export const DetectorList: FC<Props> = ({ isActive, onEditJob, onDeleteJob }) => {
const { jobCreator: jc, jobCreatorUpdated } = useContext(JobCreatorContext);
const jobCreator = jc as AdvancedJobCreator;
const [detectors, setDetectors] = useState(jobCreator.detectors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const AdvancedDetectors: FC<Props> = ({ setIsValid }) => {

return (
<Fragment>
<DetectorList onEditJob={onEditJob} onDeleteJob={onDeleteJob} />
<DetectorList isActive={true} onEditJob={onEditJob} onDeleteJob={onDeleteJob} />
<MetricSelector
payload={modalPayload}
fields={fields}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC } from 'react';

import { DetectorList } from './detector_list';

export const AdvancedDetectorsSummary: FC = () => (
<DetectorList isActive={false} onEditJob={() => {}} onDeleteJob={() => {}} />
);
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const MultiMetricView: FC<Props> = ({ isActive, setCanProceed }) => {

return (
<Fragment>
{isActive === false && <MultiMetricDetectorsSummary />}

{isActive === true && (
{isActive === false ? (
<MultiMetricDetectorsSummary />
) : (
<Fragment>
<MultiMetricDetectors setIsValid={setMetricValid} />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const PopulationView: FC<Props> = ({ isActive, setCanProceed }) => {

return (
<Fragment>
{isActive === false && <PopulationDetectorsSummary />}

{isActive === true && (
{isActive === false ? (
<PopulationDetectorsSummary />
) : (
<Fragment>
<PopulationDetectors setIsValid={setMetricValid} />
{metricsValid && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const SingleMetricView: FC<Props> = ({ isActive, setCanProceed }) => {

return (
<Fragment>
{isActive === false && <SingleMetricDetectorsSummary />}

{isActive === true && (
{isActive === false ? (
<SingleMetricDetectorsSummary />
) : (
<Fragment>
<SingleMetricDetectors setIsValid={setMetricValid} />
{metricsValid && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const PickFieldsStep: FC<StepProps> = ({ setCurrentStep, isCurrentStep })
{jobType === JOB_TYPE.POPULATION && (
<PopulationView isActive={isCurrentStep} setCanProceed={setNextActive} />
)}
{jobType === JOB_TYPE.ADVANCED && <AdvancedView setCanProceed={setNextActive} />}
{jobType === JOB_TYPE.ADVANCED && (
<AdvancedView isActive={isCurrentStep} setCanProceed={setNextActive} />
)}
<WizardNav
previous={() =>
setCurrentStep(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiTitle } from '@elastic/eui';

export interface ListItems {
title: string;
description: string | JSX.Element;
}

export const trueLabel = i18n.translate('xpack.ml.newJob.wizard.summaryStep.trueLabel', {
defaultMessage: 'True',
});

export const falseLabel = i18n.translate('xpack.ml.newJob.wizard.summaryStep.falseLabel', {
defaultMessage: 'False',
});

export const defaultLabel = i18n.translate('xpack.ml.newJob.wizard.summaryStep.defaultString', {
defaultMessage: 'default',
});

export const JobSectionTitle: FC = () => (
<EuiTitle size="s">
<h3>
<FormattedMessage
id="xpack.ml.newJob.wizard.summaryStep.jobConfig.title"
defaultMessage="Job configuration"
/>
</h3>
</EuiTitle>
);

export const DatafeedSectionTitle: FC = () => (
<EuiTitle size="s">
<h3>
<FormattedMessage
id="xpack.ml.newJob.wizard.summaryStep.datafeedConfig.title"
defaultMessage="Datafeed configuration"
/>
</h3>
</EuiTitle>
);

export const Italic: FC = ({ children }) => <span style={{ fontStyle: 'italic' }}>{children}</span>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC, useContext } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFlexGroup, EuiFlexItem, EuiDescriptionList, EuiFormRow } from '@elastic/eui';
import { JobCreatorContext } from '../../../job_creator_context';
import { MLJobEditor } from '../../../../../../jobs_list/components/ml_job_editor';
import { calculateDatafeedFrequencyDefaultSeconds } from '../../../../../../../../common/util/job_utils';
import { DEFAULT_QUERY_DELAY } from '../../../../../common/job_creator/util/constants';
import { newJobDefaults } from '../../../../../utils/new_job_defaults';
import { ListItems, defaultLabel, Italic } from '../common';

const EDITOR_HEIGHT = '200px';

export const DatafeedDetails: FC = () => {
const { jobCreator } = useContext(JobCreatorContext);
const { datafeeds } = newJobDefaults();

const queryString = JSON.stringify(jobCreator.query, null, 2);
const defaultFrequency = calculateDatafeedFrequencyDefaultSeconds(jobCreator.bucketSpanMs / 1000);
const scrollSizeDefault = datafeeds.scroll_size || '';

const queryDelay = jobCreator.queryDelay || (
<Italic>{`${DEFAULT_QUERY_DELAY} (${defaultLabel})`}</Italic>
);
const frequency = jobCreator.frequency || (
<Italic>{`${defaultFrequency} (${defaultLabel})`}</Italic>
);
const scrollSize =
jobCreator.scrollSize !== null ? (
`${jobCreator.scrollSize}`
) : (
<Italic>{`${scrollSizeDefault} (${defaultLabel})`}</Italic>
);

const datafeedDetails: ListItems[] = [
{
title: i18n.translate('xpack.ml.newJob.wizard.summaryStep.datafeedDetails.timeField.title', {
defaultMessage: 'Time field',
}),
description: jobCreator.timeFieldName,
},
{
title: i18n.translate('xpack.ml.newJob.wizard.summaryStep.datafeedDetails.queryDelay.title', {
defaultMessage: 'Query delay',
}),
description: queryDelay,
},

{
title: i18n.translate('xpack.ml.newJob.wizard.summaryStep.datafeedDetails.frequency.title', {
defaultMessage: 'Frequency',
}),
description: frequency,
},

{
title: i18n.translate('xpack.ml.newJob.wizard.summaryStep.datafeedDetails.scrollSize.title', {
defaultMessage: 'Scroll size',
}),
description: scrollSize,
},
];

const queryTitle = i18n.translate(
'xpack.ml.newJob.wizard.summaryStep.datafeedDetails.query.title',
{
defaultMessage: 'Scroll size',
}
);

return (
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow label={queryTitle} fullWidth={true}>
<MLJobEditor value={queryString} height={EDITOR_HEIGHT} readOnly={true} />
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiDescriptionList compressed listItems={datafeedDetails} />
</EuiFlexItem>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export { DatafeedDetails } from './datafeed_details';
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

import React, { Fragment, FC, useContext } from 'react';
import { JobCreatorContext } from '../job_creator_context';
import { JOB_TYPE } from '../../../common/job_creator/util/constants';
import { SingleMetricView } from '../pick_fields_step/components/single_metric_view';
import { MultiMetricView } from '../pick_fields_step/components/multi_metric_view';
import { PopulationView } from '../pick_fields_step/components/population_view';
import { JobCreatorContext } from '../../../job_creator_context';
import { JOB_TYPE } from '../../../../../common/job_creator/util/constants';
import { SingleMetricView } from '../../../pick_fields_step/components/single_metric_view';
import { MultiMetricView } from '../../../pick_fields_step/components/multi_metric_view';
import { PopulationView } from '../../../pick_fields_step/components/population_view';
import { AdvancedView } from '../../../pick_fields_step/components/advanced_view';

export const DetectorChart: FC = () => {
const { jobCreator } = useContext(JobCreatorContext);
Expand All @@ -19,6 +20,7 @@ export const DetectorChart: FC = () => {
{jobCreator.type === JOB_TYPE.SINGLE_METRIC && <SingleMetricView isActive={false} />}
{jobCreator.type === JOB_TYPE.MULTI_METRIC && <MultiMetricView isActive={false} />}
{jobCreator.type === JOB_TYPE.POPULATION && <PopulationView isActive={false} />}
{jobCreator.type === JOB_TYPE.ADVANCED && <AdvancedView isActive={false} />}
</Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { DetectorChart } from './detector_chart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export { JobDetails } from './job_details';
Loading