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] Migrate bucket span estimator button to EUI/React. #19045

Merged
merged 5 commits into from
May 17, 2018
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 @@ -9,8 +9,6 @@ import React from 'react';

import { ValidateJob } from './validate_job_view';

jest.mock('ui/chrome', () => { }, { virtual: true });

const job = {
job_id: 'test-id'
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BucketSpanEstimator renders the button 1`] = `
<div
className="bucket-span-estimator"
>
<EuiToolTip
content="Experimental feature for estimating bucket span."
position="bottom"
>
<EuiButton
color="primary"
disabled={true}
fill={true}
iconSide="right"
isLoading={true}
onClick={[Function]}
size="s"
type="button"
>
Estimating bucket span
</EuiButton>
</EuiToolTip>
</div>
`;

exports[`BucketSpanEstimator renders the loading button 1`] = `
<div
className="bucket-span-estimator"
>
<EuiToolTip
content="Experimental feature for estimating bucket span."
position="bottom"
>
<EuiButton
color="primary"
disabled={true}
fill={true}
iconSide="right"
isLoading={true}
onClick={[Function]}
size="s"
type="button"
>
Estimating bucket span
</EuiButton>
</EuiToolTip>
</div>
`;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import ReactDOM from 'react-dom';


import template from './bucket_span_estimator.html';
import { BucketSpanEstimator } from './bucket_span_estimator_view';
import { getQueryFromSavedSearch } from 'plugins/ml/jobs/new_job/utils/new_job_utils';
import { EVENT_RATE_COUNT_FIELD } from 'plugins/ml/jobs/new_job/simple/components/constants/general';
import { ml } from 'plugins/ml/services/ml_api_service';
Expand All @@ -26,15 +27,13 @@ module.directive('mlBucketSpanEstimator', function () {
ui: '=ui',
exportedFunctions: '='
},
template,
link: function ($scope) {
link: function ($scope, $element) {
const STATUS = {
FAILED: -1,
NOT_RUNNING: 0,
RUNNING: 1,
FINISHED: 2
};
$scope.STATUS = STATUS;

const errorHandler = (error) => {
console.log('Bucket span could not be estimated', error);
Expand Down Expand Up @@ -101,6 +100,38 @@ module.directive('mlBucketSpanEstimator', function () {
$scope.exportedFunctions.guessBucketSpan = $scope.guessBucketSpan;
}

// watch for these changes
$scope.$watch('formConfig.agg.type', updateButton, true);
$scope.$watch('jobStateWrapper.jobState', updateButton, true);
$scope.$watch('[ui.showJobInput,ui.formValid,ui.bucketSpanEstimator.status]', updateButton, true);

function updateButton() {
const buttonDisabled = (
$scope.ui.showJobInput === false ||
$scope.ui.formValid === false ||
$scope.formConfig.agg.type === undefined ||
$scope.jobStateWrapper.jobState === $scope.JOB_STATE.RUNNING ||
$scope.jobStateWrapper.jobState === $scope.JOB_STATE.STOPPING ||
$scope.jobStateWrapper.jobState === $scope.JOB_STATE.FINISHED ||
$scope.ui.bucketSpanEstimator.status === STATUS.RUNNING
);
const estimatorRunning = ($scope.ui.bucketSpanEstimator.status === STATUS.RUNNING);
const buttonText = (estimatorRunning) ? 'Estimating bucket span' : 'Estimate bucket span';

const props = {
buttonDisabled,
estimatorRunning,
guessBucketSpan: $scope.guessBucketSpan,
buttonText
};

ReactDOM.render(
React.createElement(BucketSpanEstimator, props),
$element[0]
);
}

updateButton();
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 from 'react';

import {
EuiButton,
EuiToolTip
} from '@elastic/eui';

export function BucketSpanEstimator({ buttonDisabled, buttonText, estimatorRunning, guessBucketSpan }) {
return (
<div className="bucket-span-estimator">
<EuiToolTip
content="Experimental feature for estimating bucket span."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this warning about it being an experimental feature is still needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding in k-api tests shortly. I'm not sure how far we'll get in terms of depth of coverage in this release, so let's keep as experimental till we have a stronger set of data scenario tests.

position="bottom"
>
<EuiButton
disabled={buttonDisabled}
fill
iconSide="right"
isLoading={estimatorRunning}
onClick={guessBucketSpan}
size="s"
>
{buttonText}
</EuiButton>
</EuiToolTip>
</div>
);
}
BucketSpanEstimator.propTypes = {
buttonDisabled: PropTypes.bool.isRequired,
buttonText: PropTypes.string.isRequired,
estimatorRunning: PropTypes.bool.isRequired,
guessBucketSpan: PropTypes.func.isRequired
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 { shallow } from 'enzyme';
import React from 'react';

import { BucketSpanEstimator } from './bucket_span_estimator_view';

describe('BucketSpanEstimator', () => {
const props = {
buttonDisabled: false,
estimatorRunning: false,
guessBucketSpan: () => {},
buttonText: 'Estimate bucket span'
};

const component = (
<BucketSpanEstimator {...props} />
);

const wrapper = shallow(component);

test('renders the button', () => {
expect(wrapper).toMatchSnapshot();
});

props.buttonDisabled = true;
props.estimatorRunning = true;
props.buttonText = 'Estimating bucket span';
wrapper.setProps(props);

test('renders the loading button', () => {
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
.bucket-span-estimator {
float: right;
margin-right: 5px;
margin-top: -27px;

button {
float: right;
margin-right: 5px;
margin-top: -27px;
}
button:disabled {
background-color: #D9D9D9;
}
button.running {
color: #2D2D2D;
button.euiButton.euiButton--small {
font-size: 12px;
height: 22px;

.euiButton__content {
padding: 2px 8px 3px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
.form-controls {
.bucket-span-container {
white-space: nowrap;
width: calc(~"100% - 40px");

.bucket-span-input {
width: calc(~"100% - 40px");
display: inline-block;
background-color: transparent;
float: left;
}
Expand All @@ -31,12 +30,6 @@
background-color: #D9D9D9;
}

.bucket-span-estimator {
button {
margin-right: 45px;
}
}

.validation-error {
margin-bottom: -25px;
}
Expand Down