Skip to content

Commit

Permalink
[Inspector] EUI Visual Refresh Integration (elastic#204436)
Browse files Browse the repository at this point in the history
## Summary

Related to elastic#203132.
Closes [elastic#204595](elastic#204595).

This replaces all references to euiThemeVars in favor of the useEuiTheme
hook in the inspector plugin.


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and viduni94 committed Jan 23, 2025
1 parent 02912ea commit b16cc3d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiHealth, EuiText, EuiTextProps } from '@elastic/eui';
import { HEALTH_HEX_CODES } from './gradient';
import { useHealthHexCodes } from './gradient';

interface Props {
count?: number;
Expand All @@ -24,29 +24,30 @@ const defaultTextProps: EuiTextProps = {
};

export function ClusterHealth({ count, status, textProps = defaultTextProps }: Props) {
const healthHexCodes = useHealthHexCodes();
if (typeof count === 'number' && count === 0) {
return null;
}

let color = 'subdued';
let statusLabel = status;
if (status === 'successful') {
color = HEALTH_HEX_CODES.successful;
color = healthHexCodes.successful;
statusLabel = i18n.translate('inspector.requests.clusters.successfulLabel', {
defaultMessage: 'successful',
});
} else if (status === 'partial') {
color = HEALTH_HEX_CODES.partial;
color = healthHexCodes.partial;
statusLabel = i18n.translate('inspector.requests.clusters.partialLabel', {
defaultMessage: 'partial',
});
} else if (status === 'skipped') {
color = HEALTH_HEX_CODES.skipped;
color = healthHexCodes.skipped;
statusLabel = i18n.translate('inspector.requests.clusters.skippedLabel', {
defaultMessage: 'skipped',
});
} else if (status === 'failed') {
color = HEALTH_HEX_CODES.failed;
color = healthHexCodes.failed;
statusLabel = i18n.translate('inspector.requests.clusters.failedLabel', {
defaultMessage: 'failed',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import React from 'react';
import { estypes } from '@elastic/elasticsearch';
import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui';
import { ClusterHealth } from './cluster_health';
import { getHeathBarLinearGradient } from './gradient';
import { useHeathBarLinearGradient } from './gradient';

interface Props {
clusters: Record<string, estypes.ClusterDetails>;
Expand All @@ -25,6 +24,8 @@ export function ClustersHealth({ clusters }: Props) {
let partial = 0;
let skipped = 0;
let failed = 0;
const { euiTheme } = useEuiTheme();

Object.values(clusters).forEach((clusterDetails) => {
if (clusterDetails.status === 'successful') {
successful++;
Expand Down Expand Up @@ -76,11 +77,11 @@ export function ClustersHealth({ clusters }: Props) {

<div
css={css`
background: ${getHeathBarLinearGradient(successful, partial, skipped, failed)};
border-radius: ${euiThemeVars.euiBorderRadiusSmall};
height: ${euiThemeVars.euiSizeS};
margin-top: ${euiThemeVars.euiSizeXS};
margin-bottom: ${euiThemeVars.euiSizeS};
background: ${useHeathBarLinearGradient(successful, partial, skipped, failed)};
border-radius: ${euiTheme.border.radius.small};
height: ${euiTheme.size.s};
margin-top: ${euiTheme.size.xs};
margin-bottom: ${euiTheme.size.s};
`}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,32 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getHeathBarLinearGradient, HEALTH_HEX_CODES } from './gradient';
import { useHeathBarLinearGradient, useHealthHexCodes } from './gradient';

jest.mock('@elastic/eui', () => ({
useEuiTheme: () => ({
euiTheme: {
colors: {
backgroundFilledSuccess: 'green',
backgroundLightWarning: 'yellow',
backgroundFilledDanger: 'red',
},
},
}),
}));

describe('useHeathBarLinearGradient', () => {
const healthHexCodes = useHealthHexCodes();

describe('getHeathBarLinearGradient', () => {
test('should return linear-gradient with percentages for each status', () => {
expect(getHeathBarLinearGradient(5, 1, 1, 2)).toBe(
`linear-gradient(to right, ${HEALTH_HEX_CODES.successful} 0% 56%, ${HEALTH_HEX_CODES.partial} 56% 67%, ${HEALTH_HEX_CODES.skipped} 67% 78%, ${HEALTH_HEX_CODES.failed} 78% 100%)`
expect(useHeathBarLinearGradient(5, 1, 1, 2)).toBe(
`linear-gradient(to right, ${healthHexCodes.successful} 0% 56%, ${healthHexCodes.partial} 56% 67%, ${healthHexCodes.skipped} 67% 78%, ${healthHexCodes.failed} 78% 100%)`
);
});

test('should return linear-gradient with percentages for each status with count above zero', () => {
expect(getHeathBarLinearGradient(5, 0, 0, 2)).toBe(
`linear-gradient(to right, ${HEALTH_HEX_CODES.successful} 0% 71%, ${HEALTH_HEX_CODES.failed} 71% 100%)`
expect(useHeathBarLinearGradient(5, 0, 0, 2)).toBe(
`linear-gradient(to right, ${healthHexCodes.successful} 0% 71%, ${healthHexCodes.failed} 71% 100%)`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { euiThemeVars } from '@kbn/ui-theme';

export const HEALTH_HEX_CODES = {
successful: euiThemeVars.euiColorSuccess,
partial: euiThemeVars.euiColorWarning,
skipped: '#DA8B45',
failed: euiThemeVars.euiColorDanger,
};
import { useEuiTheme } from '@elastic/eui';

export function useHealthHexCodes() {
const { euiTheme } = useEuiTheme();
return {
successful: euiTheme.colors.backgroundFilledSuccess,
partial: euiTheme.colors.backgroundLightWarning,
skipped: euiTheme.colors.backgroundFilledWarning,
failed: euiTheme.colors.backgroundFilledDanger,
};
}

export function getHeathBarLinearGradient(
export function useHeathBarLinearGradient(
successful: number,
partial: number,
skipped: number,
failed: number
) {
const healthHexCodes = useHealthHexCodes();

const total = successful + partial + skipped + failed;
const stops: string[] = [];
let startPercent: number = 0;
Expand All @@ -37,10 +42,10 @@ export function getHeathBarLinearGradient(
startPercent = endPercent;
}

addStop(successful, HEALTH_HEX_CODES.successful);
addStop(partial, HEALTH_HEX_CODES.partial);
addStop(skipped, HEALTH_HEX_CODES.skipped);
addStop(failed, HEALTH_HEX_CODES.failed);
addStop(successful, healthHexCodes.successful);
addStop(partial, healthHexCodes.partial);
addStop(skipped, healthHexCodes.skipped);
addStop(failed, healthHexCodes.failed);

const printedStops = stops
.map((stop, index) => {
Expand Down
1 change: 0 additions & 1 deletion src/platform/plugins/shared/inspector/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@kbn/core-ui-settings-browser-mocks",
"@kbn/core-ui-settings-browser",
"@kbn/std",
"@kbn/ui-theme",
"@kbn/code-editor",
"@kbn/core-lifecycle-browser",
"@kbn/react-kibana-mount"
Expand Down

0 comments on commit b16cc3d

Please sign in to comment.