-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathintegrationRow.tsx
More file actions
234 lines (212 loc) · 6.19 KB
/
integrationRow.tsx
File metadata and controls
234 lines (212 loc) · 6.19 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import styled from '@emotion/styled';
import startCase from 'lodash/startCase';
import {Alert} from 'sentry/components/core/alert';
import {Tag} from 'sentry/components/core/badge/tag';
import {LinkButton} from 'sentry/components/core/button';
import Link from 'sentry/components/links/link';
import PanelItem from 'sentry/components/panels/panelItem';
import {t} from 'sentry/locale';
import PluginIcon from 'sentry/plugins/components/pluginIcon';
import {space} from 'sentry/styles/space';
import type {
IntegrationInstallationStatus,
PluginWithProjectList,
SentryApp,
SentryAppStatus,
} from 'sentry/types/integrations';
import type {Organization} from 'sentry/types/organization';
import {
convertIntegrationTypeToSnakeCase,
trackIntegrationAnalytics,
} from 'sentry/utils/integrationUtil';
import AlertContainer from './integrationAlertContainer';
import IntegrationStatus from './integrationStatus';
import PluginDeprecationAlert from './pluginDeprecationAlert';
type Props = {
categories: string[];
configurations: number;
displayName: string;
organization: Organization;
publishStatus: SentryAppStatus;
slug: string;
type: 'plugin' | 'firstParty' | 'sentryApp' | 'docIntegration';
/**
* If provided, render an alert message with this text.
*/
alertText?: string;
customAlert?: React.ReactNode;
customIcon?: React.ReactNode;
plugin?: PluginWithProjectList;
/**
* If `alertText` was provided, this text overrides the "Resolve now" message
* in the alert.
*/
resolveText?: string;
status?: IntegrationInstallationStatus;
};
const urlMap = {
plugin: 'plugins',
firstParty: 'integrations',
sentryApp: 'sentry-apps',
docIntegration: 'document-integrations',
};
function IntegrationRow(props: Props) {
const {
organization,
type,
slug,
displayName,
status,
publishStatus,
configurations,
categories,
alertText,
resolveText,
plugin,
customAlert,
customIcon,
} = props;
const baseUrl =
publishStatus === 'internal'
? `/settings/${organization.slug}/developer-settings/${slug}/`
: `/settings/${organization.slug}/${urlMap[type]}/${slug}/`;
const renderDetails = () => {
if (type === 'sentryApp') {
return publishStatus !== 'published' && <PublishStatus status={publishStatus} />;
}
// TODO: Use proper translations
return configurations > 0 ? (
<StyledLink to={`${baseUrl}?tab=configurations`}>{`${configurations} Configuration${
configurations > 1 ? 's' : ''
}`}</StyledLink>
) : null;
};
const renderStatus = () => {
// status should be undefined for document integrations
if (status) {
return <IntegrationStatus status={status} />;
}
return <LearnMore to={baseUrl}>{t('Learn More')}</LearnMore>;
};
return (
<PanelRow noPadding data-test-id={slug}>
<FlexContainer>
{customIcon ?? <PluginIcon size={36} pluginId={slug} />}
<TitleContainer>
<IntegrationName to={baseUrl}>{displayName}</IntegrationName>
<IntegrationDetails>
{renderStatus()}
{renderDetails()}
</IntegrationDetails>
</TitleContainer>
<TagsContainer>
{categories?.map(category => (
<Tag
key={category}
type={category === publishStatus ? 'highlight' : 'default'}
>
{category === 'api' ? 'API' : startCase(category)}
</Tag>
))}
</TagsContainer>
</FlexContainer>
{alertText && (
<AlertContainer>
<Alert.Container>
<Alert
type="warning"
showIcon
trailingItems={
<ResolveNowButton
href={`${baseUrl}?tab=configurations&referrer=directory_resolve_now`}
size="xs"
onClick={() =>
trackIntegrationAnalytics('integrations.resolve_now_clicked', {
integration_type: convertIntegrationTypeToSnakeCase(type),
integration: slug,
organization,
})
}
>
{resolveText || t('Resolve Now')}
</ResolveNowButton>
}
>
{alertText}
</Alert>
</Alert.Container>
</AlertContainer>
)}
{customAlert}
{plugin?.deprecationDate && (
<PluginDeprecationAlertWrapper>
<PluginDeprecationAlert organization={organization} plugin={plugin} />
</PluginDeprecationAlertWrapper>
)}
</PanelRow>
);
}
const PluginDeprecationAlertWrapper = styled('div')`
padding: 0px ${space(3)} 0px 68px;
`;
const PanelRow = styled(PanelItem)`
flex-direction: column;
`;
const FlexContainer = styled('div')`
display: flex;
align-items: center;
padding: ${space(2)};
`;
const TitleContainer = styled('div')`
flex: 1;
padding: 0 16px;
white-space: nowrap;
`;
const TagsContainer = styled('div')`
flex: 3;
padding: 0 ${space(2)};
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: ${space(1)};
justify-content: flex-end;
`;
const IntegrationName = styled(Link)`
font-weight: ${p => p.theme.fontWeightBold};
`;
const IntegrationDetails = styled('div')`
display: flex;
align-items: center;
font-size: ${p => p.theme.fontSizeSmall};
`;
const StyledLink = styled(Link)`
color: ${p => p.theme.subText};
&:before {
content: '|';
color: ${p => p.theme.subText};
margin-right: ${space(0.75)};
}
`;
const LearnMore = styled(Link)`
color: ${p => p.theme.subText};
`;
type PublishStatusProps = {status: SentryApp['status']};
const PublishStatus = styled(({status, ...props}: PublishStatusProps) => (
<div {...props}>{status}</div>
))`
color: ${p => (p.status === 'published' ? p.theme.success : p.theme.gray300)};
font-weight: light;
margin-right: ${space(0.75)};
text-transform: capitalize;
&:before {
content: '|';
color: ${p => p.theme.subText};
margin-right: ${space(0.75)};
font-weight: ${p => p.theme.fontWeightNormal};
}
`;
const ResolveNowButton = styled(LinkButton)`
color: ${p => p.theme.subText};
float: right;
`;
export default IntegrationRow;