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] Convert anomalies table to EUI / React #19352

Merged
merged 2 commits into from
May 24, 2018

Conversation

peteharverson
Copy link
Contributor

Converts the anomalies table, as used on the Single Metric Viewer and Anomaly Explorer to EUI / React.

Functionally the table is the same, but is now built from the EUI components.

Existing Angular based table:
image

New EUI / React table:
image

Addresses anomalies table and anomalies table service items in the components list of #18374. Note the interval and severity controls, and the parent pages (Angular controller based), will be converted to EUI in future PRs.

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui

@elasticmachine
Copy link
Contributor

💔 Build Failed

}
}
} else {
if (mouseOverRecord !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This could be } else if (mouseOverRecord !== undefined) {.

};

render() {
if (this.props.tableData === undefined ||
Copy link
Contributor

Choose a reason for hiding this comment

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

const { timefilter, tableData, filter } = this.props; could be added to the beginning of the render() method so in the code below this.props wouldn't be necessary all the time. This would make it clearer which props are used in the render() method. See section 4 in this article with more details about this pattern https://medium.com/walmartlabs/make-your-react-components-pretty-a1ae4ec0f56e

Copy link
Member

Choose a reason for hiding this comment

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

I like this pattern. as well as making it clear what props are being used in the function, it also cleans up the code throughout the function.

* a filter on this entity.
*/
export function EntityCell({ entityName, entityValue, filter }) {
const valueText = entityName !== 'mlcategory' ? entityValue : `mlcategory ${entityValue}`;
Copy link
Member

Choose a reason for hiding this comment

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

nit, entityName !== 'mlcategory' should be wrapped in parenthesis

import { formatValue } from 'plugins/ml/formatters/format_value';

const TIME_FIELD_NAME = 'timestamp';
const INFLUENCERS_LIMIT = 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is defined in the same way in anomaly_table.js, it could be moved to a common constants file or passed down in the component tree from the parent.

};

render() {
const button = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Like in the previous comment, the used props could be destructured like const { ... } = this.props; too.

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

LGTM, added a few comments about some minor possible improvements for readability.

field: 'severity',
name: `${(isAggregatedData === true) ? 'max ' : ''}severity`,
render: (score) => {
return (
Copy link
Member

Choose a reason for hiding this comment

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

these render functions are a bit inconsistent, the first omits the return but the others don't.
Personally I don't thing the return is necessary if it's just returning a single component, as in the first column.

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

LGTM
Apologies for all the nit picks about wrapping conditions in parenthesis :)

return anomaly.rowId === rowId;
});

return matching === undefined;
Copy link
Member

Choose a reason for hiding this comment

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

nit, similarly to ternary expressions, we should wrap conditions like this.
i.e. (matching === undefined)

if (itemIdToExpandedRowMap[item.rowId]) {
delete itemIdToExpandedRowMap[item.rowId];
} else {
const examples = item.entityName === 'mlcategory' ?
Copy link
Member

Choose a reason for hiding this comment

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

nit, should be (item.entityName === 'mlcategory')

if (expandButton.length > 0) {
const rowId = expandButton.attr('data-row-id');
mouseOverRecord = this.props.tableData.anomalies.find((anomaly) => {
return anomaly.rowId === rowId;
Copy link
Member

Choose a reason for hiding this comment

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

nit, should be (anomaly.rowId === rowId)

};

render() {
if (this.props.tableData === undefined ||
Copy link
Member

Choose a reason for hiding this comment

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

I like this pattern. as well as making it clear what props are being used in the function, it also cleans up the code throughout the function.


if (examples !== undefined && examples.length > 0) {
examples.forEach((example, index) => {
const title = index === 0 ? 'category examples' : '';
Copy link
Member

Choose a reason for hiding this comment

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

nit, should be (index === 0)

.then((resp) => {
// Prefix each of the terms with '+' so that the Elasticsearch Query String query
// run in a drilldown Kibana dashboard has to match on all terms.
const termsArray = _.map(resp.terms.split(' '), (term) => { return '+' + term; });
Copy link
Member

Choose a reason for hiding this comment

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

could be written as
const termsArray = resp.terms.split(' ').map(term => `+${term}`)

// Need to encode the _a parameter in case any entities contain unsafe characters such as '+'.
let path = chrome.getBasePath();
path += '/app/ml#/timeseriesexplorer';
path += '?_g=' + _g;
Copy link
Member

Choose a reason for hiding this comment

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

nit, should be using template literals

const indexPatterns = getIndexPatterns();

const job = mlJobService.getJob(this.props.anomaly.jobId);
const categorizationFieldName = job.analysis_config.categorization_field_name;
Copy link
Member

Choose a reason for hiding this comment

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

there is a low risk here that mlJobService.getJob will return undefined which will cause this line to throw an error

}
});

$timeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

same comment about $evalAsync

}
});

$timeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

$evalAsync should probably be used in situations like this.

@peteharverson peteharverson force-pushed the ml-anomalies-table-react branch from ce82449 to ab3695e Compare May 24, 2018 12:26
@elasticmachine
Copy link
Contributor

💔 Build Failed

@peteharverson peteharverson force-pushed the ml-anomalies-table-react branch from ab3695e to bc94853 Compare May 24, 2018 13:36
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@peteharverson peteharverson merged commit 1365799 into elastic:master May 24, 2018
@peteharverson peteharverson deleted the ml-anomalies-table-react branch May 24, 2018 14:49
peteharverson added a commit to peteharverson/kibana that referenced this pull request May 25, 2018
* [ML] Convert anomalies table to EUI / React

* [ML] Edits to EUI / React anomalies table after review
peteharverson added a commit that referenced this pull request May 25, 2018
* [ML] Convert anomalies table to EUI / React

* [ML] Edits to EUI / React anomalies table after review
@sophiec20 sophiec20 added the Feature:Anomaly Detection ML anomaly detection label Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants