-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathproductSelection.tsx
494 lines (463 loc) · 17.5 KB
/
productSelection.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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
import type {ReactNode} from 'react';
import {useCallback, useEffect, useMemo, useRef} from 'react';
import {css} from '@emotion/react';
import styled from '@emotion/styled';
import {openModal} from 'sentry/actionCreators/modal';
import {FeatureDisabledModal} from 'sentry/components/acl/featureDisabledModal';
import {Button} from 'sentry/components/core/button';
import {Checkbox} from 'sentry/components/core/checkbox';
import ExternalLink from 'sentry/components/links/externalLink';
import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {Tooltip} from 'sentry/components/tooltip';
import {IconQuestion} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import ConfigStore from 'sentry/stores/configStore';
import HookStore from 'sentry/stores/hookStore';
import {space} from 'sentry/styles/space';
import type {Organization} from 'sentry/types/organization';
import type {PlatformKey} from 'sentry/types/project';
import {useOnboardingQueryParams} from 'sentry/views/onboarding/components/useOnboardingQueryParams';
interface DisabledProduct {
reason: ReactNode;
onClick?: () => void;
}
export type DisabledProducts = Partial<Record<ProductSolution, DisabledProduct>>;
function getDisabledProducts(organization: Organization): DisabledProducts {
const disabledProducts: DisabledProducts = {};
const hasSessionReplay = organization.features.includes('session-replay');
const hasPerformance = organization.features.includes('performance-view');
const hasProfiling = organization.features.includes('profiling-view');
const isSelfHostedErrorsOnly = ConfigStore.get('isSelfHostedErrorsOnly');
let reason = t('This feature is not enabled on your Sentry installation.');
const createClickHandler = (feature: string, featureName: string) => () => {
openModal(deps => (
<FeatureDisabledModal {...deps} features={[feature]} featureName={featureName} />
));
};
if (isSelfHostedErrorsOnly) {
reason = t('This feature is disabled for errors only self-hosted');
return Object.values(ProductSolution)
.filter(product => product !== ProductSolution.ERROR_MONITORING)
.reduce((acc, prod) => {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
acc[prod] = {reason};
return acc;
}, {});
}
if (!hasSessionReplay) {
disabledProducts[ProductSolution.SESSION_REPLAY] = {
reason,
onClick: createClickHandler('organizations:session-replay', 'Session Replay'),
};
}
if (!hasPerformance) {
disabledProducts[ProductSolution.PERFORMANCE_MONITORING] = {
reason,
onClick: createClickHandler('organizations:performance-view', 'Tracing'),
};
}
if (!hasProfiling) {
disabledProducts[ProductSolution.PROFILING] = {
reason,
onClick: createClickHandler('organizations:profiling-view', 'Profiling'),
};
}
return disabledProducts;
}
// This is the list of products that are available for each platform
// Since the ProductSelection component is rendered in the onboarding/project creation flow only, it is ok to have this list here
// NOTE: Please keep the prefix in alphabetical order
export const platformProductAvailability = {
android: [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
ProductSolution.SESSION_REPLAY,
],
'apple-ios': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
ProductSolution.SESSION_REPLAY,
],
'apple-macos': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
bun: [ProductSolution.PERFORMANCE_MONITORING],
capacitor: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.SESSION_REPLAY],
dotnet: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'dotnet-aspnet': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-aspnetcore': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-awslambda': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-gcpfunctions': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-maui': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-uwp': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-winforms': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-wpf': [ProductSolution.PERFORMANCE_MONITORING],
'dotnet-xamarin': [ProductSolution.PERFORMANCE_MONITORING],
flutter: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
kotlin: [ProductSolution.PERFORMANCE_MONITORING],
go: [ProductSolution.PERFORMANCE_MONITORING],
'go-echo': [ProductSolution.PERFORMANCE_MONITORING],
'go-fasthttp': [ProductSolution.PERFORMANCE_MONITORING],
'go-gin': [ProductSolution.PERFORMANCE_MONITORING],
'go-http': [ProductSolution.PERFORMANCE_MONITORING],
'go-iris': [ProductSolution.PERFORMANCE_MONITORING],
'go-martini': [ProductSolution.PERFORMANCE_MONITORING],
'go-negroni': [ProductSolution.PERFORMANCE_MONITORING],
ionic: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.SESSION_REPLAY],
java: [ProductSolution.PERFORMANCE_MONITORING],
'java-log4j2': [ProductSolution.PERFORMANCE_MONITORING],
'java-logback': [ProductSolution.PERFORMANCE_MONITORING],
'java-spring': [ProductSolution.PERFORMANCE_MONITORING],
'java-spring-boot': [ProductSolution.PERFORMANCE_MONITORING],
javascript: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.SESSION_REPLAY],
'javascript-react': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-vue': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-angular': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-ember': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-gatsby': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-solid': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-solidstart': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-svelte': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
'javascript-astro': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.SESSION_REPLAY,
],
node: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-azurefunctions': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
],
'node-awslambda': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-connect': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-express': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-fastify': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-gcpfunctions': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
],
'node-hapi': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-koa': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'node-nestjs': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
php: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'php-laravel': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'php-symfony': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
python: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-aiohttp': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-asgi': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-awslambda': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-bottle': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-celery': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-chalice': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-django': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-falcon': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-fastapi': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-flask': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-gcpfunctions': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
],
'python-quart': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-rq': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-serverless': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
],
'python-tornado': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-starlette': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'python-wsgi': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'react-native': [
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
ProductSolution.SESSION_REPLAY,
],
ruby: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'ruby-rack': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
'ruby-rails': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
} as Record<PlatformKey, ProductSolution[]>;
type ProductProps = {
/**
* If the product is checked. This information is grabbed from the URL.
*/
checked: boolean;
/**
* The name of the product
*/
label: string;
/**
* Brief product description
*/
description?: ReactNode;
/**
* If the product is disabled. It contains a reason and an optional onClick handler
*/
disabled?: DisabledProduct;
/**
* Link of the product documentation. Rendered if there is also a description.
*/
docLink?: string;
/**
* Click handler. If the product is enabled, by clicking on the button, the product is added or removed from the URL.
*/
onClick?: () => void;
/**
* A permanent disabled product is always disabled and cannot be enabled.
*/
permanentDisabled?: boolean;
};
function Product({
disabled,
permanentDisabled,
checked,
label,
onClick,
docLink,
description,
}: ProductProps) {
const ProductWrapper = permanentDisabled
? PermanentDisabledProductWrapper
: disabled
? DisabledProductWrapper
: ProductButtonWrapper;
return (
<Tooltip
title={
disabled?.reason ??
(description && (
<TooltipDescription>
{description}
{docLink && <ExternalLink href={docLink}>{t('Read the Docs')}</ExternalLink>}
</TooltipDescription>
))
}
delay={500}
isHoverable
>
<ProductWrapper
onClick={disabled?.onClick ?? onClick}
disabled={(disabled?.onClick ?? permanentDisabled) ? false : !!disabled}
priority={permanentDisabled || checked ? 'primary' : 'default'}
aria-label={label}
>
<ProductButtonInner>
<Checkbox
checked={checked}
disabled={permanentDisabled ? false : !!disabled}
aria-label={label}
size="xs"
readOnly
/>
<span>{label}</span>
<IconQuestion size="xs" color="subText" />
</ProductButtonInner>
</ProductWrapper>
</Tooltip>
);
}
export type ProductSelectionProps = {
/**
* The current organization
*/
organization: Organization;
/**
* List of products that are disabled. All of them have to contain a reason by default and optionally an onClick handler.
*/
disabledProducts?: DisabledProducts;
/**
* Fired when the product selection changes
*/
onChange?: (products: ProductSolution[]) => void;
/**
* Triggered when the component is loaded
*/
onLoad?: (products: ProductSolution[]) => void;
/**
* The platform key of the project (e.g. javascript-react, python-django, etc.)
*/
platform?: PlatformKey;
};
export function ProductSelection({
disabledProducts: disabledProductsProp,
organization,
platform,
onChange,
onLoad,
}: ProductSelectionProps) {
const [params, setParams] = useOnboardingQueryParams();
const urlProducts = useMemo(() => params.product ?? [], [params.product]);
const products: ProductSolution[] | undefined = platform
? platformProductAvailability[platform]
: undefined;
const disabledProducts = useMemo(
() => disabledProductsProp ?? getDisabledProducts(organization),
[organization, disabledProductsProp]
);
const safeDependencies = useRef({onLoad, urlProducts});
useEffect(() => {
safeDependencies.current = {onLoad, urlProducts};
});
useEffect(() => {
safeDependencies.current.onLoad?.(
safeDependencies.current.urlProducts as ProductSolution[]
);
}, []);
const handleClickProduct = useCallback(
(product: ProductSolution) => {
const newProduct = new Set(
urlProducts.includes(product)
? urlProducts.filter(p => p !== product)
: [...urlProducts, product]
);
if (products?.includes(ProductSolution.PROFILING)) {
// Ensure that if profiling is enabled, tracing is also enabled
if (
product === ProductSolution.PROFILING &&
newProduct.has(ProductSolution.PROFILING)
) {
newProduct.add(ProductSolution.PERFORMANCE_MONITORING);
} else if (
product === ProductSolution.PERFORMANCE_MONITORING &&
!newProduct.has(ProductSolution.PERFORMANCE_MONITORING)
) {
newProduct.delete(ProductSolution.PROFILING);
}
}
const selectedProducts = [...newProduct] as ProductSolution[];
onChange?.(selectedProducts);
setParams({product: selectedProducts});
if (organization.features.includes('project-create-replay-feedback')) {
HookStore.get('callback:on-create-project-product-selection').map(cb =>
cb({defaultProducts: products ?? [], organization, selectedProducts})
);
}
},
[products, organization, setParams, urlProducts, onChange]
);
if (!products) {
// if the platform does not support any product, we don't render anything
return null;
}
return (
<Products>
<Product
label={t('Error Monitoring')}
disabled={{reason: t("Let's admit it, we all have errors.")}}
checked
permanentDisabled
/>
{products.includes(ProductSolution.PERFORMANCE_MONITORING) && (
<Product
label={t('Tracing')}
description={t(
'Automatic performance issue detection across services and context on who is impacted, outliers, regressions, and the root cause of your slowdown.'
)}
docLink="https://docs.sentry.io/platforms/javascript/guides/react/tracing/"
onClick={() => handleClickProduct(ProductSolution.PERFORMANCE_MONITORING)}
disabled={disabledProducts[ProductSolution.PERFORMANCE_MONITORING]}
checked={urlProducts.includes(ProductSolution.PERFORMANCE_MONITORING)}
/>
)}
{products.includes(ProductSolution.PROFILING) && (
<Product
label={t('Profiling')}
description={tct(
'[strong:Requires Tracing]\nSee the exact lines of code causing your performance bottlenecks, for faster troubleshooting and resource optimization.',
{
strong: <strong />,
}
)}
docLink="https://docs.sentry.io/platforms/python/profiling/"
onClick={() => handleClickProduct(ProductSolution.PROFILING)}
disabled={disabledProducts[ProductSolution.PROFILING]}
checked={urlProducts.includes(ProductSolution.PROFILING)}
/>
)}
{products.includes(ProductSolution.SESSION_REPLAY) && (
<Product
label={t('Session Replay')}
description={t(
'Video-like reproductions of user sessions with debugging context to help you confirm issue impact and troubleshoot faster.'
)}
docLink="https://docs.sentry.io/platforms/javascript/guides/react/session-replay/"
onClick={() => handleClickProduct(ProductSolution.SESSION_REPLAY)}
disabled={disabledProducts[ProductSolution.SESSION_REPLAY]}
checked={urlProducts.includes(ProductSolution.SESSION_REPLAY)}
/>
)}
</Products>
);
}
const Products = styled('div')`
display: flex;
flex-wrap: wrap;
gap: ${space(1)};
`;
const ProductButtonWrapper = styled(Button)`
${p =>
p.priority === 'primary' &&
css`
&,
:hover,
:focus-visible {
background: ${p.theme.purple100};
color: ${p.theme.purple300};
}
`}
`;
const DisabledProductWrapper = styled(Button)`
&& {
cursor: ${p => (p.disabled ? 'not-allowed' : 'pointer')};
input {
cursor: ${p =>
p.disabled || p.priority === 'default' ? 'not-allowed' : 'pointer'};
}
}
`;
const PermanentDisabledProductWrapper = styled(Button)`
&& {
&,
:hover,
:focus-visible {
background: ${p => p.theme.purple100};
color: ${p => p.theme.purple300};
opacity: 0.5;
cursor: not-allowed;
input {
cursor: not-allowed;
}
}
}
`;
const ProductButtonInner = styled('div')`
display: grid;
grid-template-columns: repeat(3, max-content);
gap: ${space(1)};
align-items: center;
`;
const TooltipDescription = styled('div')`
display: flex;
flex-direction: column;
gap: ${space(0.5)};
justify-content: flex-start;
`;