Skip to content

Commit

Permalink
[ML] Update to undefined,rename stashCombinedJob to stashJobForCloning
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Feb 4, 2021
1 parent 9ae79cc commit 658bccc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export function checkForAutoStartDatafeed() {
if (job !== undefined) {
mlJobService.tempJobCloningObjects.job = undefined;
mlJobService.tempJobCloningObjects.datafeed = undefined;
mlJobService.tempJobCloningObjects.createdBy = undefined;

const hasDatafeed = typeof datafeed === 'object' && Object.keys(datafeed).length > 0;
const datafeedId = hasDatafeed ? datafeed.datafeed_id : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,18 @@ export function isSparseDataJob(job: Job, datafeed: Datafeed): boolean {
return false;
}

function stashCombinedJob(
function stashJobForCloning(
jobCreator: JobCreatorType,
skipTimeRangeStep: boolean = false,
includeTimeRange: boolean = false
) {
mlJobService.tempJobCloningObjects.job = jobCreator.jobConfig;
mlJobService.tempJobCloningObjects.datafeed = jobCreator.datafeedConfig;
mlJobService.tempJobCloningObjects.createdBy = jobCreator.createdBy;
if (jobCreator.createdBy === null) {
mlJobService.tempJobCloningObjects.createdBy = undefined;
} else {
mlJobService.tempJobCloningObjects.createdBy = jobCreator.createdBy;
}

// skip over the time picker step of the wizard
mlJobService.tempJobCloningObjects.skipTimeRangeStep = skipTimeRangeStep;
Expand All @@ -256,21 +260,21 @@ export function convertToMultiMetricJob(
) {
jobCreator.createdBy = CREATED_BY_LABEL.MULTI_METRIC;
jobCreator.modelPlot = false;
stashCombinedJob(jobCreator, true, true);
stashJobForCloning(jobCreator, true, true);

navigateToPath(`jobs/new_job/${JOB_TYPE.MULTI_METRIC}`, true);
}

export function convertToAdvancedJob(jobCreator: JobCreatorType, navigateToPath: NavigateToPath) {
jobCreator.createdBy = null;
stashCombinedJob(jobCreator, true, true);
stashJobForCloning(jobCreator, true, true);

navigateToPath(`jobs/new_job/${JOB_TYPE.ADVANCED}`, true);
}

export function resetJob(jobCreator: JobCreatorType, navigateToPath: NavigateToPath) {
jobCreator.jobId = '';
stashCombinedJob(jobCreator, true, true);
stashJobForCloning(jobCreator, true, true);
navigateToPath('/jobs/new_job');
}

Expand All @@ -279,7 +283,7 @@ export function advancedStartDatafeed(
navigateToPath: NavigateToPath
) {
if (jobCreator !== null) {
stashCombinedJob(jobCreator, false, false);
stashJobForCloning(jobCreator, false, false);
}
navigateToPath('/jobs');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const Page: FC<PageProps> = ({ existingJobsAndGroups, jobType }) => {
mlJobService.tempJobCloningObjects.skipTimeRangeStep = false;
mlJobService.tempJobCloningObjects.job = undefined;
mlJobService.tempJobCloningObjects.datafeed = undefined;
mlJobService.tempJobCloningObjects.createdBy = null;
mlJobService.tempJobCloningObjects.createdBy = undefined;

if (
mlJobService.tempJobCloningObjects.start !== undefined &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { SearchResponse } from 'elasticsearch';
import { TimeRange } from 'src/plugins/data/common/query/timefilter/types';
import { CombinedJob, Datafeed } from '../../../common/types/anomaly_detection_jobs';
import { Calendar } from '../../../common/types/calendars';
import { CREATED_BY_LABEL } from '../../../common/constants/new_job';

export interface ExistingJobsAndGroups {
jobIds: string[];
Expand All @@ -20,7 +19,7 @@ declare interface JobService {
jobs: CombinedJob[];
createResultsUrlForJobs: (jobs: any[], target: string, timeRange?: TimeRange) => string;
tempJobCloningObjects: {
createdBy?: CREATED_BY_LABEL | null;
createdBy?: string;
datafeed?: Datafeed;
job: any;
skipTimeRangeStep: boolean;
Expand Down

0 comments on commit 658bccc

Please sign in to comment.