-
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.
Browse files
Browse the repository at this point in the history
* [ML] [WIP] Create watch from new jobs list * removing comments * adding interval calculation * adding checkbox to start datafeed modal * adding proptypes check to SelectSeverity * fixing typo * changes based on review * correcting input labels
- Loading branch information
1 parent
fc5dac6
commit 340178a
Showing
13 changed files
with
485 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ | |
|
||
|
||
import './select_severity_directive'; | ||
import './styles/main.less'; |
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
176 changes: 176 additions & 0 deletions
176
...lugins/ml/public/jobs/jobs_list_new/components/create_watch_flyout/create_watch_flyout.js
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,176 @@ | ||
/* | ||
* 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 PropTypes from 'prop-types'; | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiFlyout, | ||
EuiFlyoutBody, | ||
EuiFlyoutFooter, | ||
EuiFlyoutHeader, | ||
EuiTitle, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
} from '@elastic/eui'; | ||
|
||
import { toastNotifications } from 'ui/notify'; | ||
import { loadFullJob } from '../utils'; | ||
import { mlCreateWatchService } from '../../../../jobs/new_job/simple/components/watcher/create_watch_service'; | ||
import { CreateWatch } from '../../../../jobs/new_job/simple/components/watcher/create_watch_view'; | ||
|
||
|
||
function getSuccessToast(id, url) { | ||
return { | ||
title: `Watch ${id} created successfully`, | ||
text: ( | ||
<React.Fragment> | ||
<EuiFlexGroup justifyContent="flexEnd" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
size="s" | ||
href={url} | ||
target="_blank" | ||
iconType="link" | ||
> | ||
Edit watch | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</React.Fragment> | ||
) | ||
}; | ||
} | ||
|
||
export class CreateWatchFlyout extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
jobId: null, | ||
bucketSpan: null, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
if (typeof this.props.setShowFunction === 'function') { | ||
this.props.setShowFunction(this.showFlyout); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
if (typeof this.props.unsetShowFunction === 'function') { | ||
this.props.unsetShowFunction(); | ||
} | ||
} | ||
|
||
closeFlyout = () => { | ||
this.setState({ isFlyoutVisible: false }); | ||
} | ||
|
||
showFlyout = (jobId) => { | ||
loadFullJob(jobId) | ||
.then((job) => { | ||
const bucketSpan = job.analysis_config.bucket_span; | ||
mlCreateWatchService.config.includeInfluencers = (job.analysis_config.influencers.length > 0); | ||
|
||
this.setState({ | ||
job, | ||
jobId, | ||
bucketSpan, | ||
isFlyoutVisible: true, | ||
}); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
} | ||
|
||
save = () => { | ||
mlCreateWatchService.createNewWatch(this.state.jobId) | ||
.then((resp) => { | ||
toastNotifications.addSuccess(getSuccessToast(resp.id, resp.url)); | ||
this.closeFlyout(); | ||
}) | ||
.catch((error) => { | ||
toastNotifications.addDanger(`Could not save watch`); | ||
console.error(error); | ||
}); | ||
} | ||
|
||
|
||
render() { | ||
const { | ||
jobId, | ||
bucketSpan | ||
} = this.state; | ||
|
||
let flyout; | ||
|
||
if (this.state.isFlyoutVisible) { | ||
flyout = ( | ||
<EuiFlyout | ||
// ownFocus | ||
onClose={this.closeFlyout} | ||
size="s" | ||
> | ||
<EuiFlyoutHeader> | ||
<EuiTitle> | ||
<h2> | ||
Create watch for {jobId} | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody> | ||
|
||
<CreateWatch | ||
jobId={jobId} | ||
bucketSpan={bucketSpan} | ||
/> | ||
|
||
</EuiFlyoutBody> | ||
<EuiFlyoutFooter> | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
iconType="cross" | ||
onClick={this.closeFlyout} | ||
flush="left" | ||
> | ||
Close | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
onClick={this.save} | ||
fill | ||
> | ||
Save | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlyoutFooter> | ||
</EuiFlyout> | ||
); | ||
} | ||
return ( | ||
<div> | ||
{flyout} | ||
</div> | ||
); | ||
|
||
} | ||
} | ||
CreateWatchFlyout.propTypes = { | ||
setShowFunction: PropTypes.func.isRequired, | ||
unsetShowFunction: PropTypes.func.isRequired, | ||
}; | ||
|
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ml/public/jobs/jobs_list_new/components/create_watch_flyout/index.js
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,8 @@ | ||
/* | ||
* 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 { CreateWatchFlyout } from './create_watch_flyout'; |
Empty file.
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
Oops, something went wrong.