Skip to content

Commit

Permalink
[Lens/SCSS] Replace expression legacy metric scss (elastic#209546)
Browse files Browse the repository at this point in the history
## Summary

Part of elastic#208908

Replaces scss to css-in-js.

### Checklist

- [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: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
(cherry picked from commit 8cb484c)
  • Loading branch information
mariairiartef committed Mar 3, 2025
1 parent 4f55a40 commit 2d56ed9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { formatValue, shouldApplyColor } from '../utils';
import { needsLightText } from '../utils/palette';
import { withAutoScale } from './with_auto_scale';

import './metric.scss';

export interface MetricVisComponentProps {
visParams: Pick<VisParams, 'metric' | 'dimensions'>;
visData: Datatable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import React, { CSSProperties, useLayoutEffect } from 'react';
import classNames from 'classnames';
import { i18n } from '@kbn/i18n';
import { UseEuiTheme, euiTextTruncate } from '@elastic/eui';
import { css } from '@emotion/react';
import type { MetricOptions, MetricStyle, MetricVisParam } from '../../common/types';

interface MetricVisValueProps {
Expand All @@ -24,6 +26,7 @@ interface MetricVisValueProps {

export const MetricVisValue = (props: MetricVisValueProps) => {
const { style, metric, onFilter, labelConfig, colorFullBackground, autoScale } = props;

const containerClassName = classNames('legacyMtrVis__container', {
'legacyMtrVis__container--light': metric.lightText,
'legacyMtrVis__container-isfilterable': onFilter,
Expand All @@ -38,11 +41,13 @@ export const MetricVisValue = (props: MetricVisValueProps) => {
const metricComponent = (
<div
className={containerClassName}
css={styles.legacyMtrVisContainer}
style={autoScale && colorFullBackground ? {} : { backgroundColor: metric.bgColor }}
>
<div
data-test-subj="metric_value"
className="legacyMtrVis__value"
css={styles.legacyMtrVisValue}
style={{
...(style.spec as CSSProperties),
...(metric.color ? { color: metric.color } : {}),
Expand Down Expand Up @@ -87,3 +92,42 @@ export const MetricVisValue = (props: MetricVisValueProps) => {

return metricComponent;
};

const styles = {
legacyMtrVisValue: ({ euiTheme }: UseEuiTheme) =>
css`
${euiTextTruncate()};
font-weight: ${euiTheme.font.weight.bold};
`,
legacyMtrVisContainer: ({ euiTheme }: UseEuiTheme) =>
css({
'&.legacyMtrVis__container': {
textAlign: 'center',
padding: euiTheme.size.base,
display: 'flex',
flexDirection: 'column',
},
'&.legacyMtrVis__container--light': {
color: euiTheme.colors.emptyShade,
},
'&.legacyMtrVis__container-isfull': {
minHeight: '100%',
minWidth: 'max-content',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
flex: '1 0 100%',
},
'&.legacyMtrVis__container-isfilterable': {
cursor: 'pointer',
transition: `transform ${euiTheme.animation.normal} ${euiTheme.animation.resistance}`,
transform: 'translate(0, 0)',

'&:hover, &:focus': {
boxShadow: 'none',
transform: 'translate(0, -2px)',
},
},
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
extractContainerType,
extractVisualizationType,
} from '@kbn/chart-expressions-common';
import { css } from '@emotion/react';
import { ExpressionLegacyMetricPluginStart } from '../plugin';
import { EXPRESSION_METRIC_NAME, MetricVisRenderConfig, VisParams } from '../../common';

Expand Down Expand Up @@ -113,10 +114,11 @@ export const getMetricVisRenderer: (
<KibanaRenderContextProvider {...core}>
<VisualizationContainer
data-test-subj="legacyMtrVis"
className="legacyMtrVis"
className="eui-scrollBar legacyMtrVis"
showNoResult={!visData.rows?.length}
renderComplete={renderComplete}
handlers={handlers}
css={legacyMtrVisCss}
>
<MetricVisComponent
visData={visData}
Expand All @@ -131,3 +133,14 @@ export const getMetricVisRenderer: (
);
},
});

const legacyMtrVisCss = css({
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
flexWrap: 'wrap',
overflow: 'auto',
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"common/**/*",
"public/**/*",
"server/**/*",
"../../../../../../typings/emotion.d.ts"
],
"kbn_references": [
{ "path": "../tsconfig.json" },
Expand Down
2 changes: 1 addition & 1 deletion test/functional/page_objects/visualize_editor_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class VisualizeEditorPageObject extends FtrService {

public async clickMetricByIndex(index: number) {
const metrics = await this.find.allByCssSelector(
'[data-test-subj="visualizationLoader"] .legacyMtrVis .legacyMtrVis__container'
'[data-test-subj="visualizationLoader"] [data-test-subj="legacyMtrVis"] .legacyMtrVis__container'
);
expect(metrics.length).greaterThan(index);
await metrics[index].click();
Expand Down

0 comments on commit 2d56ed9

Please sign in to comment.