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

[Lens/SCSS] Replace expression legacy metric scss #209546

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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

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 @@ -8,10 +8,52 @@
*/

import React, { CSSProperties, useLayoutEffect } from 'react';
import classNames from 'classnames';
import { i18n } from '@kbn/i18n';
import { UseEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';
import { euiTextTruncate } from '@elastic/eui';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you move it together with the import above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import type { MetricOptions, MetricStyle, MetricVisParam } from '../../common/types';

const legacyMtrVisValueCss = ({ euiTheme }: UseEuiTheme) =>
css({
fontWeight: euiTheme.font.weight.bold,
});

const legacyMtrVisContainerCss = ({ euiTheme }: UseEuiTheme) =>
css({
textAlign: 'center',
padding: euiTheme.size.base,
display: 'flex',
flexDirection: 'column',
});

const legacyMtrVisContainerLightCss = ({ euiTheme }: UseEuiTheme) =>
css({
color: euiTheme.colors.emptyShade,
});

const legacyMtrVisContainerIsFilterableCss = ({ euiTheme }: UseEuiTheme) =>
css({
cursor: 'pointer',
transition: `transform ${euiTheme.animation.normal} ${euiTheme.animation.resistance}`,
transform: 'translate(0, 0)',
'&:hover, &:focus': {
boxShadow: 'none',
transform: 'translate(0, -2px)',
},
});

const legacyMtrVisContainerIsFullCss = () =>
css({
minHeight: '100%',
minWidth: 'max-content',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
flex: '1 0 100%',
});

interface MetricVisValueProps {
metric: MetricOptions;
onFilter?: () => void;
Expand All @@ -24,11 +66,6 @@ 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,
'legacyMtrVis__container-isfull': !autoScale && colorFullBackground,
});

useLayoutEffect(() => {
props.renderComplete?.();
Expand All @@ -37,12 +74,17 @@ export const MetricVisValue = (props: MetricVisValueProps) => {
// for autoScale true we should add background to upper level so that correct colorize full container
const metricComponent = (
<div
className={containerClassName}
css={[
legacyMtrVisContainerCss,
metric.lightText && legacyMtrVisContainerLightCss,
onFilter && legacyMtrVisContainerIsFilterableCss,
!autoScale && colorFullBackground && legacyMtrVisContainerIsFullCss,
]}
style={autoScale && colorFullBackground ? {} : { backgroundColor: metric.bgColor }}
>
<div
data-test-subj="metric_value"
className="legacyMtrVis__value"
css={[legacyMtrVisValueCss, euiTextTruncate()]}
style={{
...(style.spec as CSSProperties),
...(metric.color ? { color: metric.color } : {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ import {
extractContainerType,
extractVisualizationType,
} from '@kbn/chart-expressions-common';
import { UseEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';
import { ExpressionLegacyMetricPluginStart } from '../plugin';
import { EXPRESSION_METRIC_NAME, MetricVisRenderConfig, VisParams } from '../../common';

const legacyMtrVisCss = ({ euiTheme }: UseEuiTheme) =>
css({
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
flexWrap: 'wrap',
overflow: 'auto',
});

// @ts-ignore
const MetricVisComponent = lazy(() => import('../components/metric_component'));

Expand Down Expand Up @@ -113,10 +127,11 @@ export const getMetricVisRenderer: (
<KibanaRenderContextProvider {...core}>
<VisualizationContainer
data-test-subj="legacyMtrVis"
className="legacyMtrVis"
className="eui-scrollBar"
showNoResult={!visData.rows?.length}
renderComplete={renderComplete}
handlers={handlers}
css={legacyMtrVisCss}
>
<MetricVisComponent
visData={visData}
Expand Down
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