Skip to content

Commit

Permalink
[ML] Create watch from new jobs list (elastic#21112) (elastic#21132)
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
jgowdyelastic authored Jul 24, 2018
1 parent fc5dac6 commit 340178a
Show file tree
Hide file tree
Showing 13 changed files with 485 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@


import './select_severity_directive';
import './styles/main.less';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/*
* React component for rendering a select element with threshold levels.
*/
import PropTypes from 'prop-types';
import _ from 'lodash';
import React, { Component } from 'react';

Expand All @@ -18,6 +19,8 @@ import {
EuiHealth,
} from '@elastic/eui';

import './styles/main.less';

import { getSeverityColor } from 'plugins/ml/../common/util/anomaly_utils';

const OPTIONS = [
Expand Down Expand Up @@ -103,5 +106,8 @@ class SelectSeverity extends Component {
);
}
}
SelectSeverity.propTypes = {
mlSelectSeverityService: PropTypes.object.isRequired,
};

export { SelectSeverity };
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,
};

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.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EditJobFlyout extends Component {
this.state = {
job: {},
hasDatafeed: false,
isModalVisible: false,
isFlyoutVisible: false,
jobDescription: '',
jobGroups: [],
jobModelMemoryLimit: '',
Expand Down Expand Up @@ -68,7 +68,7 @@ export class EditJobFlyout extends Component {
}

closeFlyout = () => {
this.setState({ isModalVisible: false });
this.setState({ isFlyoutVisible: false });
}

showFlyout = (jobLite) => {
Expand All @@ -78,7 +78,7 @@ export class EditJobFlyout extends Component {
this.extractJob(job, hasDatafeed);
this.setState({
job,
isModalVisible: true,
isFlyoutVisible: true,
});
})
.catch((error) => {
Expand Down Expand Up @@ -185,7 +185,7 @@ export class EditJobFlyout extends Component {
render() {
let flyout;

if (this.state.isModalVisible) {
if (this.state.isFlyoutVisible) {
const {
job,
jobDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { JobFilterBar } from '../job_filter_bar';
import { EditJobFlyout } from '../edit_job_flyout';
import { DeleteJobModal } from '../delete_job_modal';
import { StartDatafeedModal } from '../start_datafeed_modal';
import { CreateWatchFlyout } from '../create_watch_flyout';
import { MultiJobActions } from '../multi_job_actions';

import PropTypes from 'prop-types';
Expand Down Expand Up @@ -45,6 +46,7 @@ export class JobsListView extends Component {
this.showEditJobFlyout = () => {};
this.showDeleteJobModal = () => {};
this.showStartDatafeedModal = () => {};
this.showCreateWatchFlyout = () => {};

this.blockRefresh = false;
}
Expand Down Expand Up @@ -191,6 +193,17 @@ export class JobsListView extends Component {
this.showStartDatafeedModal = () => {};
}

setShowCreateWatchFlyoutFunction = (func) => {
this.showCreateWatchFlyout = func;
}
unsetShowCreateWatchFlyoutFunction = () => {
this.showCreateWatchFlyout = () => {};
}
getShowCreateWatchFlyoutFunction = () => {
return this.showCreateWatchFlyout;
}


selectJobChange = (selectedJobs) => {
this.setState({ selectedJobs });
}
Expand Down Expand Up @@ -281,8 +294,14 @@ export class JobsListView extends Component {
<StartDatafeedModal
setShowFunction={this.setShowStartDatafeedModalFunction}
unsetShowFunction={this.unsetShowDeleteJobModalFunction}
getShowCreateWatchFlyoutFunction={this.getShowCreateWatchFlyoutFunction}
refreshJobs={() => this.refreshJobSummaryList(true)}
/>
<CreateWatchFlyout
setShowFunction={this.setShowCreateWatchFlyoutFunction}
unsetShowFunction={this.unsetShowCreateWatchFlyoutFunction}
compile={this.props.compile}
/>
</div>
);
}
Expand Down
Loading

0 comments on commit 340178a

Please sign in to comment.