|
| 1 | +import {hasEveryAccess} from 'sentry/components/acl/access'; |
| 2 | +import {Alert} from 'sentry/components/core/alert'; |
| 3 | +import Link from 'sentry/components/links/link'; |
| 4 | +import useReplayBulkDeleteAuditLog from 'sentry/components/replays/bulkDelete/useReplayBulkDeleteAuditLog'; |
| 5 | +import {t, tct} from 'sentry/locale'; |
| 6 | +import useOrganization from 'sentry/utils/useOrganization'; |
| 7 | +import useProjectFromId from 'sentry/utils/useProjectFromId'; |
| 8 | + |
| 9 | +interface Props { |
| 10 | + projectId: string; |
| 11 | +} |
| 12 | + |
| 13 | +export default function BulkDeleteAlert({projectId}: Props) { |
| 14 | + const organization = useOrganization(); |
| 15 | + const project = useProjectFromId({project_id: projectId}); |
| 16 | + const hasWriteAccess = hasEveryAccess(['project:write'], {organization, project}); |
| 17 | + |
| 18 | + const {data} = useReplayBulkDeleteAuditLog({ |
| 19 | + projectSlug: project?.slug ?? '', |
| 20 | + query: {per_page: 10, offset: 0, referrer: 'replay-list'}, |
| 21 | + enabled: project && hasWriteAccess, |
| 22 | + }); |
| 23 | + |
| 24 | + if (!hasWriteAccess || !project) { |
| 25 | + return null; |
| 26 | + } |
| 27 | + |
| 28 | + // TODO: This only looks at the first page of results. |
| 29 | + // It would be better to be able to search for jobs in progress to be sure. |
| 30 | + // The expectation is that only one job is running at a time. |
| 31 | + const hasAnyInProgress = data?.data?.some(job => |
| 32 | + ['pending', 'in-progress'].includes(job?.status ?? '') |
| 33 | + ); |
| 34 | + |
| 35 | + if (hasAnyInProgress) { |
| 36 | + return ( |
| 37 | + <Alert |
| 38 | + type="info" |
| 39 | + showIcon |
| 40 | + expand={tct('Visit the [link: Job log] to see more details and track progress.', { |
| 41 | + link: ( |
| 42 | + <Link |
| 43 | + to={`/organizations/${organization.slug}/settings/projects/${project.slug}/replays/?replaySettingsTab=bulk-delete`} |
| 44 | + /> |
| 45 | + ), |
| 46 | + })} |
| 47 | + > |
| 48 | + {t( |
| 49 | + 'Replays are being deleted in the background. Items shown below may be stale.' |
| 50 | + )} |
| 51 | + </Alert> |
| 52 | + ); |
| 53 | + } |
| 54 | + return null; |
| 55 | +} |
0 commit comments