-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Adding post create job options (#43205)
* [ML] Adding post create job options * adding toasts * fixing toast string * tweaking continue job function * updating ids * removing ts-ignore
- Loading branch information
1 parent
6da05e0
commit 4acfc04
Showing
11 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...blic/jobs/new_job_new/pages/components/summary_step/components/post_save_options/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { PostSaveOptions } from './post_save_options'; |
104 changes: 104 additions & 0 deletions
104
..._job_new/pages/components/summary_step/components/post_save_options/post_save_options.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* 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, Fragment, useContext, useState } from 'react'; | ||
import { toastNotifications } from 'ui/notify'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { JobRunner } from '../../../../../common/job_runner'; | ||
|
||
// @ts-ignore | ||
import { CreateWatchFlyout } from '../../../../../../jobs_list/components/create_watch_flyout'; | ||
import { JobCreatorContext } from '../../../../components/job_creator_context'; | ||
import { DATAFEED_STATE } from '../../../../../../../../common/constants/states'; | ||
|
||
interface Props { | ||
jobRunner: JobRunner | null; | ||
} | ||
|
||
type ShowFlyout = (jobId: string) => void; | ||
|
||
export const PostSaveOptions: FC<Props> = ({ jobRunner }) => { | ||
const { jobCreator } = useContext(JobCreatorContext); | ||
const [datafeedState, setDatafeedState] = useState(DATAFEED_STATE.STOPPED); | ||
const [watchFlyoutVisible, setWatchFlyoutVisible] = useState(false); | ||
const [watchCreated, setWatchCreated] = useState(false); | ||
|
||
function setShowCreateWatchFlyoutFunction(showFlyout: ShowFlyout) { | ||
showFlyout(jobCreator.jobId); | ||
} | ||
|
||
function flyoutHidden(jobCreated: boolean) { | ||
setWatchFlyoutVisible(false); | ||
setWatchCreated(jobCreated); | ||
} | ||
|
||
function unsetShowCreateWatchFlyoutFunction() { | ||
setWatchFlyoutVisible(false); | ||
} | ||
|
||
async function startJobInRealTime() { | ||
setDatafeedState(DATAFEED_STATE.STARTING); | ||
if (jobRunner !== null) { | ||
try { | ||
const started = await jobRunner.startDatafeedInRealTime(true); | ||
setDatafeedState(started === true ? DATAFEED_STATE.STARTED : DATAFEED_STATE.STOPPED); | ||
toastNotifications.addSuccess({ | ||
title: i18n.translate('xpack.ml.newJob.wizard.startJobInRealTimeSuccess', { | ||
defaultMessage: `Job {jobId} started`, | ||
values: { jobId: jobCreator.jobId }, | ||
}), | ||
}); | ||
} catch (error) { | ||
setDatafeedState(DATAFEED_STATE.STOPPED); | ||
toastNotifications.addDanger({ | ||
title: i18n.translate('xpack.ml.newJob.wizard.startJobInRealTimeError', { | ||
defaultMessage: `Error starting job`, | ||
}), | ||
text: error.message, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
  | ||
<EuiButton | ||
isDisabled={ | ||
datafeedState === DATAFEED_STATE.STARTING || datafeedState === DATAFEED_STATE.STARTED | ||
} | ||
onClick={startJobInRealTime} | ||
data-test-subj="mlButtonUseFullData3" | ||
> | ||
<FormattedMessage | ||
id="xpack.ml.newJob.wizard.startJobInRealTime" | ||
defaultMessage="Start job running in real time" | ||
/> | ||
</EuiButton> | ||
  | ||
<EuiButton | ||
isDisabled={ | ||
datafeedState === DATAFEED_STATE.STOPPED || | ||
datafeedState === DATAFEED_STATE.STARTING || | ||
watchCreated === true | ||
} | ||
onClick={() => setWatchFlyoutVisible(true)} | ||
data-test-subj="mlButtonUseFullData" | ||
> | ||
<FormattedMessage id="xpack.ml.newJob.wizard.createWatch" defaultMessage="Create watch" /> | ||
</EuiButton> | ||
{datafeedState === DATAFEED_STATE.STARTED && watchFlyoutVisible && ( | ||
<CreateWatchFlyout | ||
setShowFunction={setShowCreateWatchFlyoutFunction} | ||
unsetShowFunction={unsetShowCreateWatchFlyoutFunction} | ||
flyoutHidden={flyoutHidden} | ||
/> | ||
)} | ||
</Fragment> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters