Skip to content

Commit

Permalink
[Stack Monitoring] Visual refresh changes (elastic#204258)
Browse files Browse the repository at this point in the history
## Summary

This PR introduces changes to `x-pack/plugins/monitoring` necessary for
the Visual Refresh project
(elastic#199715):

- replacing `euiThemeVars` with `euiTheme` context
- replacing old tokens with `euiTheme`
- making sure all color palette functions are run within the context of
the `EuiProvider`

Additionally:

- I migrated Sass to `@emotion/react`
- I migrated `euiStyled` to `@emotion/react`
- I extended `emotion.d.ts` in `tsconfig.json` for typing of the EUI
theme

closes [elastic#8228](elastic/eui#8228)

### QA

We need to test the critical paths in the Stack monitoring, paying close
attention to:

- [ ] color palette, visibility and contrast ratio of elements in
Amsterdam / Borealis

Specific paths:
- [ ] Monitoring time-series "Zoom out" button hover behavior -
`x-pack/plugins/monitoring/public/components/chart/monitoring_timeseries_container.tsx`
- [ ] Shard allocation (especially color mapping with shard type and
status):
- [ ]
`x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/assigned.js`
- [ ]
`x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/shard.js`
- [ ] Kuery bar suggestions and autocomplete field:
- [ ]
`x-pack/plugins/monitoring/public/components/kuery_bar/autocomplete_field.tsx`
- [ ]
`x-pack/plugins/monitoring/public/components/kuery_bar/suggestion_item.tsx`

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated
- [x] 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)

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Jan 6, 2025
1 parent 750ccb1 commit b95211b
Show file tree
Hide file tree
Showing 75 changed files with 1,168 additions and 968 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,6 @@ x-pack/solutions/security/plugins/security_solution/server/lib/security_integrat

# Observability design
/x-pack/platform/plugins/shared/fleet/**/*.scss @elastic/observability-design
/x-pack/platform/plugins/private/monitoring/**/*.scss @elastic/observability-design

# Ent. Search design
/x-pack/solutions/search/plugins/enterprise_search/**/*.scss @elastic/search-design
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const LogStashNodePipelinesPage: React.FC<ComponentProps> = ({ clusters }
{data.pipelines && (
<div data-test-subj="logstashPipelinesListing">
<PipelineListing
className="monitoringLogstashPipelinesTable"
data-test-subj="monitoringLogstashPipelinesTable"
onBrush={onBrush}
zoomInfo={zoomInfo}
stats={data.nodeSummary}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const LogStashPipelinesPage: React.FC<ComponentProps> = ({ clusters }) =>
const upgradeMessage = pageData ? makeUpgradeMessage(clusterStatus.versions) : null;
return (
<PipelineListing
className="monitoringLogstashPipelinesTable"
data-test-subj="monitoringLogstashPipelinesTable"
onBrush={(xaxis: any) => onBrush({ xaxis })}
stats={clusterStatus}
data={pipelines}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ function getColumns(setupMode: SetupMode, cgroup: unknown) {
};

setupModeStatus = (
<div className="monTableCell__setupModeStatus">
<SetupModeBadge
setupMode={setupMode}
status={status}
instance={instance}
productName={APM_SYSTEM_ID}
/>
</div>
<SetupModeBadge
setupMode={setupMode}
status={status}
instance={instance}
productName={APM_SYSTEM_ID}
/>
);
}

Expand Down Expand Up @@ -187,7 +185,7 @@ export function ApmServerInstances({ apms, setupMode, alerts }: Props) {
<EuiPanel>
{setupModeCallout}
<EuiMonitoringTable
className="apmInstancesTable"
data-test-subj="apmInstancesTable"
rows={data.apms}
columns={getColumns(setupMode, data.cgroup)}
sorting={sorting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ export class Listing extends PureComponent {
};

setupModeStatus = (
<div className="monTableCell__setupModeStatus">
<SetupModeBadge
setupMode={setupMode}
status={status}
instance={instance}
productName={BEATS_SYSTEM_ID}
/>
</div>
<SetupModeBadge
setupMode={setupMode}
status={status}
instance={instance}
productName={BEATS_SYSTEM_ID}
/>
);
}

Expand Down Expand Up @@ -161,7 +159,7 @@ export class Listing extends PureComponent {
<EuiPanel>
{setupModeCallOut}
<EuiMonitoringTable
className="beatsTable"
data-test-subj="beatsTable"
rows={data}
setupMode={setupMode}
productName={BEATS_SYSTEM_ID}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,86 @@
* 2.0.
*/

import React from 'react';
import React, { MouseEvent } from 'react';
import {
EuiFlexItem,
EuiFlexGroup,
EuiIcon,
UseEuiTheme,
euiFontSize,
logicalCSS,
} from '@elastic/eui';
import { css } from '@emotion/react';
import { includes, isFunction } from 'lodash';
import { EuiFlexItem, EuiFlexGroup, EuiIcon } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import './horizontal_legend.scss';

export class HorizontalLegend extends React.Component {
constructor() {
super();
const legendItemStyle = (isDisabled: boolean) => (theme: UseEuiTheme) =>
css`
display: flex;
font-size: ${euiFontSize(theme, 'xs').fontSize};
cursor: pointer;
color: ${theme.euiTheme.colors.textParagraph};
display: flex;
flex-direction: row;
align-items: center;
${isDisabled ? 'opacity: 0.5;' : ''}
`;

const legendHorizontalStyle = ({ euiTheme }: UseEuiTheme) => css`
${logicalCSS('margin-top', euiTheme.size.xs)}
`;

const legendLabelStyle = css`
overflow: hidden;
white-space: nowrap;
display: flex;
flex-direction: row;
align-items: center;
`;

const legendValueStyle = ({ euiTheme }: UseEuiTheme) => css`
overflow: hidden;
white-space: nowrap;
${logicalCSS('margin-left', euiTheme.size.xs)}
`;

interface Row {
id: string;
label: string;
legend?: boolean;
color?: string;
tickFormatter?: (arg: number) => number;
}

interface Props {
series: Row[];
seriesValues: { [key: string]: number };
seriesFilter: string[];
onToggle: (event: MouseEvent<HTMLButtonElement>, id: string) => void;
legendFormatter?: (value: number) => number;
tickFormatter?: (value: number) => number;
}

export class HorizontalLegend extends React.Component<Props> {
constructor(props: Props) {
super(props);
this.formatter = this.formatter.bind(this);
this.createSeries = this.createSeries.bind(this);
}

/**
* @param {Number} value Final value to display
*/
displayValue(value) {
return <span className="monRhythmChart__legendValue">{value}</span>;
displayValue(value: number) {
return <span css={legendValueStyle}>{value}</span>;
}

/**
* @param {Number} value True if value is falsy and/or not a number
*/
validValue(value) {
validValue(value: number) {
return value !== null && value !== undefined && (typeof value === 'string' || !isNaN(value));
}

Expand All @@ -38,7 +93,7 @@ export class HorizontalLegend extends React.Component {
* A null means no data for the time bucket and will be formatted as 'N/A'
* @param {Object} row Props passed form a parent by row index
*/
formatter(value, row) {
formatter(value: number, row: Row) {
if (!this.validValue(value)) {
return (
<FormattedMessage
Expand All @@ -48,7 +103,7 @@ export class HorizontalLegend extends React.Component {
);
}

if (row && row.tickFormatter) {
if (row?.tickFormatter) {
return this.displayValue(row.tickFormatter(value));
}

Expand All @@ -60,25 +115,19 @@ export class HorizontalLegend extends React.Component {
return this.displayValue(value);
}

createSeries(row, rowIdx) {
const classes = ['monRhythmChart__legendItem'];

if (!includes(this.props.seriesFilter, row.id)) {
classes.push('monRhythmChart__legendItem-isDisabled');
}
createSeries(row: Row, rowIdx: number) {
if (!row.label || row.legend === false) {
return <div key={rowIdx} style={{ display: 'none' }} />;
}

return (
<EuiFlexItem grow={false} key={rowIdx}>
<button
className={classes.join(' ')}
css={legendItemStyle(!includes(this.props.seriesFilter, row.id))}
onClick={(event) => this.props.onToggle(event, row.id)}
>
<span className="monRhythmChart__legendLabel">
<span css={legendLabelStyle}>
<EuiIcon
className="monRhythmChart__legendIndicator"
aria-label={i18n.translate(
'xpack.monitoring.chart.horizontalLegend.toggleButtonAriaLabel',
{ defaultMessage: 'toggle button' }
Expand All @@ -87,7 +136,7 @@ export class HorizontalLegend extends React.Component {
type="dot"
color={row.color}
/>
{' ' + row.label + ' '}
{` ${row.label} `}
</span>
{this.formatter(this.props.seriesValues[row.id], row)}
</button>
Expand All @@ -99,8 +148,8 @@ export class HorizontalLegend extends React.Component {
const rows = this.props.series.map(this.createSeries);

return (
<div className="monRhythmChart__legendHorizontal">
<EuiFlexGroup wrap={true} gutterSize="s" className="monRhythmChart__legendSeries">
<div css={legendHorizontalStyle}>
<EuiFlexGroup wrap={true} gutterSize="s">
{rows}
</EuiFlexGroup>
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,36 @@
*/

import React from 'react';
import { css } from '@emotion/react';
import { euiFontSize, UseEuiTheme } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n-react';
import './info_tooltip.scss';

export function InfoTooltip({ series, bucketSize }) {
import { Series } from './types';

const tooltipLabelStyle = (theme: UseEuiTheme) => css`
text-align: left;
font-size: ${euiFontSize(theme, 'xs').fontSize};
padding: ${theme.euiTheme.size.xs};
word-wrap: break-word;
white-space: normal;
font-weight: ${theme.euiTheme.font.weight.bold};
`;

const tooltipValueStyle = (theme: UseEuiTheme) => css`
text-align: left;
font-size: ${euiFontSize(theme, 'xs').fontSize};
padding: ${theme.euiTheme.size.xs};
word-wrap: break-word;
white-space: normal;
`;

interface Props {
series: Series[];
bucketSize?: string;
}

export function InfoTooltip({ series, bucketSize }: Props) {
const tableRows = series.map((item, index) => {
return (
<tr
Expand All @@ -19,8 +45,8 @@ export function InfoTooltip({ series, bucketSize }) {
data-debug-metric-is-derivative={item.metric.isDerivative}
data-debug-metric-has-calculation={item.metric.hasCalculation}
>
<td className="monChart__tooltipLabel">{item.metric.label}</td>
<td className="monChart__tooltipValue">{item.metric.description}</td>
<td css={tooltipLabelStyle}>{item.metric.label}</td>
<td css={tooltipValueStyle}>{item.metric.description}</td>
</tr>
);
});
Expand All @@ -29,13 +55,13 @@ export function InfoTooltip({ series, bucketSize }) {
<table>
<tbody>
<tr>
<td className="monChart__tooltipLabel">
<td css={tooltipLabelStyle}>
<FormattedMessage
id="xpack.monitoring.chart.infoTooltip.intervalLabel"
defaultMessage="Interval"
/>
</td>
<td className="monChart__tooltipValue">{bucketSize}</td>
<td css={tooltipValueStyle}>{bucketSize}</td>
</tr>
{tableRows}
</tbody>
Expand Down

This file was deleted.

Loading

0 comments on commit b95211b

Please sign in to comment.