2022-04-22 14:33:13 +01:00
|
|
|
import { css } from '@emotion/css';
|
2021-04-21 08:38:00 +01:00
|
|
|
import { isArray, isObject, isUndefined } from 'lodash';
|
2022-04-22 14:33:13 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2021-05-03 09:45:54 +02:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { useStyles2, Icon } from '@grafana/ui';
|
|
|
|
|
|
2021-03-25 11:51:09 +01:00
|
|
|
import { Diff } from './utils';
|
|
|
|
|
|
|
|
|
|
type DiffProps = {
|
|
|
|
|
diff: Diff;
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-15 07:56:09 -07:00
|
|
|
export const DiffValues = ({ diff }: DiffProps) => {
|
2021-04-21 14:25:43 +02:00
|
|
|
const styles = useStyles2(getStyles);
|
2021-03-25 11:51:09 +01:00
|
|
|
const hasLeftValue =
|
2021-04-21 08:38:00 +01:00
|
|
|
!isUndefined(diff.originalValue) && !isArray(diff.originalValue) && !isObject(diff.originalValue);
|
|
|
|
|
const hasRightValue = !isUndefined(diff.value) && !isArray(diff.value) && !isObject(diff.value);
|
2021-03-25 11:51:09 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{hasLeftValue && <span className={styles}>{String(diff.originalValue)}</span>}
|
|
|
|
|
{hasLeftValue && hasRightValue ? <Icon name="arrow-right" /> : null}
|
|
|
|
|
{hasRightValue && <span className={styles}>{String(diff.value)}</span>}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-03 09:45:54 +02:00
|
|
|
const getStyles = (theme: GrafanaTheme2) => css`
|
2021-04-21 15:34:08 +02:00
|
|
|
background-color: ${theme.colors.action.hover};
|
2023-08-01 14:46:07 +01:00
|
|
|
border-radius: ${theme.shape.radius.default};
|
2021-04-21 15:34:08 +02:00
|
|
|
color: ${theme.colors.text.primary};
|
2021-04-21 14:25:43 +02:00
|
|
|
font-size: ${theme.typography.body.fontSize};
|
|
|
|
|
margin: 0 ${theme.spacing(0.5)};
|
|
|
|
|
padding: ${theme.spacing(0.5, 1)};
|
2021-03-25 11:51:09 +01:00
|
|
|
`;
|