grafana/public/app/features/dashboard/components/VersionHistory/DiffTitle.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

61 lines
1.6 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme } from '@grafana/data';
import { useStyles, Icon } from '@grafana/ui';
import { DiffValues } from './DiffValues';
import { Diff, getDiffText } from './utils';
type DiffTitleProps = {
diff?: Diff;
title: string;
};
const replaceDiff: Diff = { op: 'replace', originalValue: undefined, path: [''], value: undefined, startLineNumber: 0 };
export const DiffTitle: React.FC<DiffTitleProps> = ({ diff, title }) => {
const styles = useStyles(getDiffTitleStyles);
return diff ? (
<>
<Icon type="mono" name="circle" className={styles[diff.op]} /> <span className={styles.embolden}>{title}</span>{' '}
<span>{getDiffText(diff, diff.path.length > 1)}</span> <DiffValues diff={diff} />
</>
) : (
<div className={styles.withoutDiff}>
<Icon type="mono" name="circle" className={styles.replace} /> <span className={styles.embolden}>{title}</span>{' '}
<span>{getDiffText(replaceDiff, false)}</span>
</div>
);
};
const getDiffTitleStyles = (theme: GrafanaTheme) => ({
embolden: css`
font-weight: ${theme.typography.weight.bold};
`,
add: css`
color: ${theme.palette.online};
`,
replace: css`
color: ${theme.palette.warn};
`,
move: css`
color: ${theme.palette.warn};
`,
copy: css`
color: ${theme.palette.warn};
`,
_get: css`
color: ${theme.palette.warn};
`,
test: css`
color: ${theme.palette.warn};
`,
remove: css`
color: ${theme.palette.critical};
`,
withoutDiff: css`
margin-bottom: ${theme.spacing.md};
`,
});