2022-04-22 14:33:13 +01:00
|
|
|
import { css } from '@emotion/css';
|
2021-04-21 08:38:00 +01:00
|
|
|
import { last } from 'lodash';
|
2022-04-22 14:33:13 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2022-11-03 13:54:18 +00:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
|
|
|
|
import { useStyles2 } from '@grafana/ui';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2021-03-25 11:51:09 +01:00
|
|
|
import { DiffTitle } from './DiffTitle';
|
|
|
|
|
import { DiffValues } from './DiffValues';
|
|
|
|
|
import { Diff, getDiffText } from './utils';
|
|
|
|
|
|
|
|
|
|
type DiffGroupProps = {
|
|
|
|
|
diffs: Diff[];
|
|
|
|
|
title: string;
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-03 13:54:18 +00:00
|
|
|
export const DiffGroup = ({ diffs, title }: DiffGroupProps) => {
|
|
|
|
|
const styles = useStyles2(getStyles);
|
2021-03-25 11:51:09 +01:00
|
|
|
|
|
|
|
|
if (diffs.length === 1) {
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.container} data-testid="diffGroup">
|
|
|
|
|
<DiffTitle title={title} diff={diffs[0]} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.container} data-testid="diffGroup">
|
|
|
|
|
<DiffTitle title={title} />
|
|
|
|
|
<ul className={styles.list}>
|
|
|
|
|
{diffs.map((diff: Diff, idx: number) => {
|
|
|
|
|
return (
|
2021-04-21 08:38:00 +01:00
|
|
|
<li className={styles.listItem} key={`${last(diff.path)}__${idx}`}>
|
2021-03-25 11:51:09 +01:00
|
|
|
<span>{getDiffText(diff)}</span> <DiffValues diff={diff} />
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-03 13:54:18 +00:00
|
|
|
const getStyles = (theme: GrafanaTheme2) => ({
|
2021-03-25 11:51:09 +01:00
|
|
|
container: css`
|
2022-11-03 13:54:18 +00:00
|
|
|
background-color: ${theme.colors.background.secondary};
|
|
|
|
|
font-size: ${theme.typography.h6.fontSize};
|
|
|
|
|
margin-bottom: ${theme.spacing(2)};
|
|
|
|
|
padding: ${theme.spacing(2)};
|
2021-03-25 11:51:09 +01:00
|
|
|
`,
|
|
|
|
|
list: css`
|
2022-11-03 13:54:18 +00:00
|
|
|
margin-left: ${theme.spacing(4)};
|
2021-03-25 11:51:09 +01:00
|
|
|
`,
|
|
|
|
|
listItem: css`
|
2022-11-03 13:54:18 +00:00
|
|
|
margin-bottom: ${theme.spacing(1)};
|
2021-03-25 11:51:09 +01:00
|
|
|
`,
|
|
|
|
|
});
|