From bbb21b1c854c1b141ec3267fc9b34a820e4aa754 Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Thu, 28 Mar 2019 14:57:14 -0400 Subject: [PATCH] [Monitoring] Address shard allocation color mismatch (#34086) * Address mismatch and add a couple starter tests * More tests and fixing a bug --- .../__snapshots__/shard.test.js.snap | 109 ++++++++++++++++++ .../shard_allocation/components/shard.js | 43 ++++--- .../shard_allocation/components/shard.test.js | 107 +++++++++++++++++ 3 files changed, 242 insertions(+), 17 deletions(-) create mode 100644 x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/__snapshots__/shard.test.js.snap create mode 100644 x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.test.js diff --git a/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/__snapshots__/shard.test.js.snap b/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/__snapshots__/shard.test.js.snap new file mode 100644 index 000000000000..2a43104005c7 --- /dev/null +++ b/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/__snapshots__/shard.test.js.snap @@ -0,0 +1,109 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Shard should show for assigned primary shards 1`] = ` +
+ + 0 + +
+`; + +exports[`Shard should show for assigned replica shards 1`] = ` +
+ + 0 + +
+`; + +exports[`Shard should show for initializing shards 1`] = ` +
+ + 0 + +
+`; + +exports[`Shard should show for relocating shards 1`] = ` +
+ + 0 + +
+`; + +exports[`Shard should show unassigned primary shards 1`] = ` +
+ + 0 + +
+`; + +exports[`Shard should show unassigned replica shards 1`] = ` +
+ + 0 + +
+`; diff --git a/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.js b/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.js index b5033e625ba6..7e1b240d5717 100644 --- a/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.js +++ b/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.js @@ -13,25 +13,34 @@ import { i18n } from '@kbn/i18n'; import { EuiToolTip, EuiBadge } from '@elastic/eui'; function getColor(classes) { - return classes.split(' ').reduce((color, cls) => { - if (color) { - return color; - } + const classList = classes.split(' '); - switch (cls) { - case 'primary': - return 'hollow'; - case 'replica': - return 'secondary'; - case 'relocation': - return 'accent'; - case 'initializing': - return 'default'; - case 'emergency': - case 'unassigned': - return 'danger'; + if (classList.includes('emergency')) { + return 'danger'; + } + + if (classList.includes('unassigned')) { + if (classList.includes('replica')) { + return 'warning'; } - }, null); + return 'danger'; + } + + if (classList.includes('relocating')) { + return 'accent'; + } + + if (classList.includes('initializing')) { + return 'default'; + } + + if (classList.includes('primary')) { + return 'primary'; + } + + if (classList.includes('replica')) { + return 'secondary'; + } } export class Shard extends React.Component { diff --git a/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.test.js b/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.test.js new file mode 100644 index 000000000000..4239b1846b8f --- /dev/null +++ b/x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.test.js @@ -0,0 +1,107 @@ +/* + * 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 React from 'react'; +import { shallow } from 'enzyme'; +import { Shard } from './shard'; + +describe('Shard', () => { + it('should show unassigned primary shards', () => { + const props = { + shard: { + state: 'UNASSIGNED', + primary: true, + shard: 0, + tooltip_message: 'Unassigned', + type: 'shard', + master: true + } + }; + + const component = shallow(); + expect(component).toMatchSnapshot(); + }); + + it('should show unassigned replica shards', () => { + const props = { + shard: { + state: 'UNASSIGNED', + primary: false, + shard: 0, + tooltip_message: 'Unassigned', + type: 'shard', + master: false + } + }; + + const component = shallow(); + expect(component).toMatchSnapshot(); + }); + + it('should show for assigned primary shards', () => { + const props = { + shard: { + state: 'STARTED', + primary: true, + shard: 0, + tooltip_message: 'Started', + type: 'shard', + master: true + } + }; + + const component = shallow(); + expect(component).toMatchSnapshot(); + }); + + it('should show for assigned replica shards', () => { + const props = { + shard: { + state: 'STARTED', + primary: false, + shard: 0, + tooltip_message: 'Started', + type: 'shard', + master: true + } + }; + + const component = shallow(); + expect(component).toMatchSnapshot(); + }); + + it('should show for relocating shards', () => { + const props = { + shard: { + state: 'RELOCATING', + primary: true, + shard: 0, + tooltip_message: 'Relocating', + type: 'shard', + master: true + } + }; + + const component = shallow(); + expect(component).toMatchSnapshot(); + }); + + it('should show for initializing shards', () => { + const props = { + shard: { + state: 'INITIALIZING', + primary: true, + shard: 0, + tooltip_message: 'Initializing', + type: 'shard', + master: true + } + }; + + const component = shallow(); + expect(component).toMatchSnapshot(); + }); +});