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] Improve Explorer Chart labels. #23494

Merged
merged 21 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cce639f
[ML] Tweak Explorer Chart labels.
walterra Sep 25, 2018
2a7d9af
[ML] Wrap all chart labels if one is too long.
walterra Sep 26, 2018
f271f23
[ML] Split up components into their own files.
walterra Sep 26, 2018
c80911e
[ML] Adds jest tests.
walterra Sep 26, 2018
b0e14a9
[ML] Use same icon as in jobs list for single series viewer button.
walterra Sep 26, 2018
3933602
[ML] Updated jest tests.
walterra Sep 26, 2018
d028c76
[ML] Use EuiButtonEmpty instead of code based on Font Awesome.
walterra Sep 26, 2018
39c749a
[ML] Restructred after feedback.
walterra Sep 26, 2018
9bdef67
[ML] Fix comment.
walterra Sep 26, 2018
aee9e06
[ML] Tweaked conditional rendering.
walterra Sep 26, 2018
a6309e3
Merge branch 'master' into ml-anomaly-explorer-chart-labels
walterra Sep 27, 2018
8d7e763
[ML] Don't use string concatentation.
walterra Sep 27, 2018
d6ed62f
[ML] Changed comment to be in line with style guide.
walterra Sep 27, 2018
3cf3c47
[ML] Use a proper React key.
walterra Sep 27, 2018
467d845
[ML] Update jest snapshot to reflect new React key.
walterra Sep 27, 2018
68bb3f8
[ML] Updated PropTypes and argument default value for wrapLabel.
walterra Sep 27, 2018
62f2e21
[ML] Fix layout issue with mixed charts with some having no entity fi…
walterra Sep 27, 2018
874948f
[ML] BR tag isn't necessary anymore because entity fields are in a DIV.
walterra Sep 27, 2018
669f7f4
[ML] Fixes potentially hidden info icon. Fixes various CSS issues.
walterra Sep 27, 2018
1f70b46
[ML] Fixes missing space between detector label and info icon.
walterra Sep 27, 2018
fc06389
Merge branch 'master' into ml-anomaly-explorer-chart-labels
walterra Sep 27, 2018
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
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/public/explorer/explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ <h4 class="euiTitle euiTitle--small">No {{swimlaneViewByFieldName}} influencers
</div>
</div>

<div class="euiSpacer euiSpacer--m"></div>

<div class="euiText explorer-charts">
<ml-explorer-charts-container />
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ExplorerChartLabelBadge Render the chart label in one line. 1`] = `
<React.Fragment>
<span
className="ml-explorer-chart-label"
>
<span
className="ml-explorer-chart-label-detector"
>
high_sum(nginx.access.body_sent.bytes) over nginx.access.remote_ip (population-03)
<React.Fragment>
 – 
</React.Fragment>
</span>
<React.Fragment>
<React.Fragment
key="nginx.access.remote_ip 72.57.0.53"
>
<ExplorerChartLabelBadge
entity={
Object {
"$$hashKey": "object:813",
"fieldName": "nginx.access.remote_ip",
"fieldValue": "72.57.0.53",
}
}
/>

</React.Fragment>

<span
className="ml-explorer-chart-info-icon"
>
<EuiIconTip
aria-label="Info"
content={
<ExplorerChartTooltip
aggregationInterval="1h"
chartFunction="sum nginx.access.body_sent.bytes"
entityFields={
Array [
Object {
"fieldName": "nginx.access.remote_ip",
"fieldValue": "72.57.0.53",
},
]
}
jobId="population-03"
/>
}
position="top"
size="s"
type="questionInCircle"
/>
</span>
</React.Fragment>
</span>
</React.Fragment>
`;

exports[`ExplorerChartLabelBadge Render the chart label in two lines. 1`] = `
<React.Fragment>
<span
className="ml-explorer-chart-label"
>
<span
className="ml-explorer-chart-label-detector"
>
high_sum(nginx.access.body_sent.bytes) over nginx.access.remote_ip (population-03)
<React.Fragment>

</React.Fragment>
</span>
<span
className="ml-explorer-chart-info-icon"
>
<EuiIconTip
aria-label="Info"
content={
<ExplorerChartTooltip
aggregationInterval="1h"
chartFunction="sum nginx.access.body_sent.bytes"
entityFields={
Array [
Object {
"fieldName": "nginx.access.remote_ip",
"fieldValue": "72.57.0.53",
},
]
}
jobId="population-03"
/>
}
position="top"
size="s"
type="questionInCircle"
/>
</span>
</span>
<div
className="ml-explorer-chart-label-fields"
>
<React.Fragment
key="nginx.access.remote_ip 72.57.0.53"
>
<ExplorerChartLabelBadge
entity={
Object {
"$$hashKey": "object:813",
"fieldName": "nginx.access.remote_ip",
"fieldValue": "72.57.0.53",
}
}
/>

</React.Fragment>
</div>
</React.Fragment>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ExplorerChartLabelBadge Render entity label badge. 1`] = `
<span
className="ml-explorer-chart-label-badge"
>
<EuiBadge
color="hollow"
iconSide="left"
>
nginx.access.remote_ip

<strong>
72.57.0.53
</strong>
</EuiBadge>
</span>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 './styles/explorer_chart_label.less';

import PropTypes from 'prop-types';
import React from 'react';

import {
EuiIconTip
} from '@elastic/eui';

import { ExplorerChartLabelBadge } from './explorer_chart_label_badge';
import { ExplorerChartTooltip } from '../../explorer_chart_tooltip';

export function ExplorerChartLabel({ detectorLabel, entityFields, infoTooltip, wrapLabel = false }) {
// Depending on whether we wrap the entityField badges to a new line, we render this differently:
//
// 1. All in one line:
// <detectorLabel> - <entityBadge1> <entityBadge2> ... <infoIcon>
//
// 2. Multiple lines:
// <detectorLabel> <infoIcon>
// <entityBadge1> <entityBadge2> ...

// Using &nbsp;s here to make sure those spaces get rendered.
const labelSeparator = (
wrapLabel === true ||
(entityFields.length === 0 || detectorLabel.length === 0)
) ? (<React.Fragment>&nbsp;</React.Fragment>) : (<React.Fragment>&nbsp;&ndash;&nbsp;</React.Fragment>);

const entityFieldBadges = entityFields.map((entity) => {
return (
<React.Fragment key={`${entity.fieldName} ${entity.fieldValue}`}>
<ExplorerChartLabelBadge entity={entity} />&nbsp;
</React.Fragment>
);
});

walterra marked this conversation as resolved.
Show resolved Hide resolved
const infoIcon = (
<span className="ml-explorer-chart-info-icon">
<EuiIconTip
content={<ExplorerChartTooltip {...infoTooltip} />}
position="top"
size="s"
/>
</span>
);

return (
<React.Fragment>
<span className="ml-explorer-chart-label">
<span className="ml-explorer-chart-label-detector">
{detectorLabel}{labelSeparator}
</span>
{wrapLabel && infoIcon}
{!wrapLabel && (
<React.Fragment>{entityFieldBadges} {infoIcon}</React.Fragment>
)}
</span>
{wrapLabel && (
<div className="ml-explorer-chart-label-fields">{entityFieldBadges}</div>
)}
</React.Fragment>
);
}
ExplorerChartLabel.propTypes = {
detectorLabel: PropTypes.string.isRequired,
entityFields: PropTypes.arrayOf(ExplorerChartLabelBadge.propTypes.entity),
infoTooltip: PropTypes.object.isRequired,
wrapLabel: PropTypes.bool
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 seriesConfig from '../../__mocks__/mock_series_config_filebeat.json';

import { shallow } from 'enzyme';
import React from 'react';

import { ExplorerChartLabel } from './explorer_chart_label';


describe('ExplorerChartLabelBadge', () => {

test('Render the chart label in one line.', () => {

const wrapper = shallow(
<ExplorerChartLabel
detectorLabel={seriesConfig.detectorLabel}
entityFields={seriesConfig.entityFields}
infoTooltip={seriesConfig.infoTooltip}
wrapLabel={false}
/>
);
expect(wrapper).toMatchSnapshot();

});

test('Render the chart label in two lines.', () => {

const wrapper = shallow(
<ExplorerChartLabel
detectorLabel={seriesConfig.detectorLabel}
entityFields={seriesConfig.entityFields}
infoTooltip={seriesConfig.infoTooltip}
wrapLabel={true}
/>
);
expect(wrapper).toMatchSnapshot();

});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 './styles/explorer_chart_label_badge.less';

import PropTypes from 'prop-types';
import React from 'react';

import {
EuiBadge
} from '@elastic/eui';

export function ExplorerChartLabelBadge({ entity }) {
return (
<span className="ml-explorer-chart-label-badge">
<EuiBadge color="hollow">
{entity.fieldName} <strong>{entity.fieldValue}</strong>
</EuiBadge>
</span>
);
}
ExplorerChartLabelBadge.propTypes = {
entity: PropTypes.shape({
fieldName: PropTypes.string.isRequired,
fieldValue: PropTypes.string.isRequired
})
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 seriesConfig from '../../__mocks__/mock_series_config_filebeat.json';

import { shallow } from 'enzyme';
import React from 'react';

import { ExplorerChartLabelBadge } from './explorer_chart_label_badge';


describe('ExplorerChartLabelBadge', () => {

test('Render entity label badge.', () => {

const wrapper = shallow(<ExplorerChartLabelBadge entity={seriesConfig.entityFields[0]} />);
expect(wrapper).toMatchSnapshot();

});

});
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 * from './explorer_chart_label';
Loading