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