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

[APM]Changing status code colors on trace summary #47114

Merged
merged 1 commit into from
Oct 2, 2019
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 @@ -6,29 +6,40 @@

import React from 'react';
import { shallow, mount } from 'enzyme';
import { palettes } from '@elastic/eui';
import { HttpInfoSummaryItem } from './';
import * as exampleTransactions from '../__fixtures__/transactions';
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { HttpInfoSummaryItem } from '../';
import * as exampleTransactions from '../../__fixtures__/transactions';

describe('HttpInfoSummaryItem', () => {
describe('render', () => {
const transaction = exampleTransactions.httpOk;
const url = 'https://example.com';
const method = 'get';
const props = { transaction, url, method, status: 200 };
const props = { transaction, url, method, status: 100 };

it('renders', () => {
expect(() =>
shallow(<HttpInfoSummaryItem {...props} />)
).not.toThrowError();
});

describe('with status code 200', () => {
describe('with status code 100', () => {
it('shows a success color', () => {
const wrapper = mount(<HttpInfoSummaryItem {...props} />);

expect(wrapper.find('HttpStatusBadge EuiBadge').prop('color')).toEqual(
palettes.euiPaletteForStatus.colors[0]
theme.euiColorDarkShade
);
});
});

describe('with status code 200', () => {
it('shows a success color', () => {
const p = { ...props, status: 200 };
const wrapper = mount(<HttpInfoSummaryItem {...p} />);

expect(wrapper.find('HttpStatusBadge EuiBadge').prop('color')).toEqual(
theme.euiColorSecondary
);
});
});
Expand All @@ -40,7 +51,7 @@ describe('HttpInfoSummaryItem', () => {
const wrapper = mount(<HttpInfoSummaryItem {...p} />);

expect(wrapper.find('HttpStatusBadge EuiBadge').prop('color')).toEqual(
palettes.euiPaletteForStatus.colors[4]
theme.euiColorDarkShade
);
});
});
Expand All @@ -52,7 +63,7 @@ describe('HttpInfoSummaryItem', () => {
const wrapper = mount(<HttpInfoSummaryItem {...p} />);

expect(wrapper.find('HttpStatusBadge EuiBadge').prop('color')).toEqual(
palettes.euiPaletteForStatus.colors[9]
theme.euiColorWarning
);
});
});
Expand All @@ -64,7 +75,7 @@ describe('HttpInfoSummaryItem', () => {
const wrapper = mount(<HttpInfoSummaryItem {...p} />);

expect(wrapper.find('HttpStatusBadge EuiBadge').prop('color')).toEqual(
palettes.euiPaletteForStatus.colors[9]
theme.euiColorDanger
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@

import React from 'react';
import { EuiToolTip, EuiBadge } from '@elastic/eui';
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { i18n } from '@kbn/i18n';
import styled from 'styled-components';
import { palettes } from '@elastic/eui';
import { units, px, truncate, unit } from '../../../../style/variables';
import { statusCodes } from './statusCodes';

const statusColors = {
success: palettes.euiPaletteForStatus.colors[0],
warning: palettes.euiPaletteForStatus.colors[4],
error: palettes.euiPaletteForStatus.colors[9]
};
const {
euiColorDarkShade,
euiColorSecondary,
euiColorWarning,
euiColorDanger
} = theme;

function getStatusColor(status: number) {
const colors: { [key: string]: string } = {
2: statusColors.success,
3: statusColors.warning,
4: statusColors.error,
5: statusColors.error
1: euiColorDarkShade,
2: euiColorSecondary,
3: euiColorDarkShade,
4: euiColorWarning,
5: euiColorDanger
};

return colors[status.toString().substr(0, 1)] || 'default';
Expand Down