header.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import isPropValid from '@emotion/is-prop-valid';
  2. import styled from '@emotion/styled';
  3. import Access from 'sentry/components/acl/access';
  4. import SnoozeAlert from 'sentry/components/alerts/snoozeAlert';
  5. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  6. import {LinkButton} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import IdBadge from 'sentry/components/idBadge';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import {IconCopy, IconEdit} from 'sentry/icons';
  11. import {t} from 'sentry/locale';
  12. import type {Organization} from 'sentry/types/organization';
  13. import type {Project} from 'sentry/types/project';
  14. import type {MetricRule} from 'sentry/views/alerts/rules/metric/types';
  15. import {getAlertRuleActionCategory} from 'sentry/views/alerts/rules/utils';
  16. type Props = {
  17. hasMetricRuleDetailsError: boolean;
  18. onSnooze: (nextState: {
  19. snooze: boolean;
  20. snoozeCreatedBy?: string;
  21. snoozeForEveryone?: boolean;
  22. }) => void;
  23. organization: Organization;
  24. project?: Project;
  25. rule?: MetricRule;
  26. };
  27. function DetailsHeader({
  28. hasMetricRuleDetailsError,
  29. rule,
  30. organization,
  31. project,
  32. onSnooze,
  33. }: Props) {
  34. const isRuleReady = !!rule && !hasMetricRuleDetailsError;
  35. const ruleTitle = rule && !hasMetricRuleDetailsError ? rule.name : '';
  36. const settingsLink = rule
  37. ? `/organizations/${organization.slug}/alerts/metric-rules/${project?.slug ?? rule?.projects?.[0]}/${rule.id}/`
  38. : '#';
  39. const duplicateLink = {
  40. pathname: `/organizations/${organization.slug}/alerts/new/metric/`,
  41. query: {
  42. project: project?.slug,
  43. duplicateRuleId: rule?.id,
  44. createFromDuplicate: 'true',
  45. referrer: 'metric_rule_details',
  46. },
  47. };
  48. const isSnoozed = rule?.snooze ?? false;
  49. return (
  50. <Layout.Header>
  51. <Layout.HeaderContent>
  52. <Breadcrumbs
  53. crumbs={[
  54. {label: t('Alerts'), to: `/organizations/${organization.slug}/alerts/rules/`},
  55. {label: ruleTitle},
  56. ]}
  57. />
  58. <RuleTitle data-test-id="incident-rule-title" loading={!isRuleReady}>
  59. {project && (
  60. <IdBadge
  61. project={project}
  62. avatarSize={28}
  63. hideName
  64. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  65. />
  66. )}
  67. {ruleTitle}
  68. </RuleTitle>
  69. </Layout.HeaderContent>
  70. <Layout.HeaderActions>
  71. <ButtonBar gap={1}>
  72. {rule && project && (
  73. <Access access={['alerts:write']}>
  74. {({hasAccess}) => (
  75. <SnoozeAlert
  76. isSnoozed={isSnoozed}
  77. onSnooze={onSnooze}
  78. ruleId={rule.id}
  79. projectSlug={project.slug}
  80. ruleActionCategory={getAlertRuleActionCategory(rule)}
  81. hasAccess={hasAccess}
  82. type="metric"
  83. />
  84. )}
  85. </Access>
  86. )}
  87. <LinkButton size="sm" icon={<IconCopy />} to={duplicateLink}>
  88. {t('Duplicate')}
  89. </LinkButton>
  90. <LinkButton size="sm" icon={<IconEdit />} to={settingsLink}>
  91. {t('Edit Rule')}
  92. </LinkButton>
  93. </ButtonBar>
  94. </Layout.HeaderActions>
  95. </Layout.Header>
  96. );
  97. }
  98. export default DetailsHeader;
  99. const RuleTitle = styled(Layout.Title, {
  100. shouldForwardProp: p => typeof p === 'string' && isPropValid(p) && p !== 'loading',
  101. })<{loading: boolean}>`
  102. ${p => p.loading && 'opacity: 0'};
  103. `;