RuleDetails.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { css } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. import { CombinedRule } from 'app/types/unified-alerting';
  6. import { AlertLabels } from '../AlertLabels';
  7. import { DetailsField } from '../DetailsField';
  8. import { RuleDetailsActionButtons } from './RuleDetailsActionButtons';
  9. import { RuleDetailsAnnotations } from './RuleDetailsAnnotations';
  10. import { RuleDetailsDataSources } from './RuleDetailsDataSources';
  11. import { RuleDetailsExpression } from './RuleDetailsExpression';
  12. import { RuleDetailsMatchingInstances } from './RuleDetailsMatchingInstances';
  13. interface Props {
  14. rule: CombinedRule;
  15. }
  16. export const RuleDetails: FC<Props> = ({ rule }) => {
  17. const styles = useStyles2(getStyles);
  18. const {
  19. namespace: { rulesSource },
  20. } = rule;
  21. const annotations = Object.entries(rule.annotations).filter(([_, value]) => !!value.trim());
  22. return (
  23. <div>
  24. <RuleDetailsActionButtons rule={rule} rulesSource={rulesSource} />
  25. <div className={styles.wrapper}>
  26. <div className={styles.leftSide}>
  27. {!!rule.labels && !!Object.keys(rule.labels).length && (
  28. <DetailsField label="Labels" horizontal={true}>
  29. <AlertLabels labels={rule.labels} />
  30. </DetailsField>
  31. )}
  32. <RuleDetailsExpression rulesSource={rulesSource} rule={rule} annotations={annotations} />
  33. <RuleDetailsAnnotations annotations={annotations} />
  34. </div>
  35. <div className={styles.rightSide}>
  36. <RuleDetailsDataSources rulesSource={rulesSource} rule={rule} />
  37. </div>
  38. </div>
  39. <RuleDetailsMatchingInstances rule={rule} />
  40. </div>
  41. );
  42. };
  43. export const getStyles = (theme: GrafanaTheme2) => ({
  44. wrapper: css`
  45. display: flex;
  46. flex-direction: row;
  47. ${theme.breakpoints.down('md')} {
  48. flex-direction: column;
  49. }
  50. `,
  51. leftSide: css`
  52. flex: 1;
  53. `,
  54. rightSide: css`
  55. ${theme.breakpoints.up('md')} {
  56. padding-left: 90px;
  57. width: 300px;
  58. }
  59. `,
  60. });