import {Fragment} from 'react';
import styled from '@emotion/styled';
import Access from 'sentry/components/acl/access';
import {Role} from 'sentry/components/acl/role';
import ActionButton from 'sentry/components/actions/button';
import MenuItemActionLink from 'sentry/components/actions/menuItemActionLink';
import Button from 'sentry/components/button';
import ButtonBar from 'sentry/components/buttonBar';
import Confirm from 'sentry/components/confirm';
import DropdownLink from 'sentry/components/dropdownLink';
import Tooltip from 'sentry/components/tooltip';
import {IconDelete, IconDownload, IconEllipsis} from 'sentry/icons';
import {t} from 'sentry/locale';
import {Organization, Project} from 'sentry/types';
import {CandidateDownloadStatus, ImageCandidate} from 'sentry/types/debugImage';
const noPermissionToDownloadDebugFilesInfo = t(
'You do not have permission to download debug files'
);
const noPermissionToDeleteDebugFilesInfo = t(
'You do not have permission to delete debug files'
);
const debugFileDeleteConfirmationInfo = t('Are you sure you wish to delete this file?');
type Props = {
baseUrl: string;
candidate: ImageCandidate;
isInternalSource: boolean;
onDelete: (debugFileId: string) => void;
organization: Organization;
projSlug: Project['slug'];
};
function Actions({
candidate,
organization,
isInternalSource,
baseUrl,
projSlug,
onDelete,
}: Props) {
const {download, location: debugFileId} = candidate;
const {status} = download;
if (!debugFileId || !isInternalSource) {
return null;
}
const deleted = status === CandidateDownloadStatus.DELETED;
const downloadUrl = `${baseUrl}/projects/${organization.slug}/${projSlug}/files/dsyms/?id=${debugFileId}`;
const actions = (
{({hasRole}) => (
{({hasAccess}) => (
}
/>
}
anchorRight
>
}
title={t('Download')}
href={downloadUrl}
onClick={event => {
if (deleted) {
event.preventDefault();
}
}}
disabled={!hasRole || deleted}
>
{t('Download')}
onDelete(debugFileId)}
message={debugFileDeleteConfirmationInfo}
title={t('Delete')}
disabled={!hasAccess || deleted}
shouldConfirm
>
{t('Delete')}
}
href={downloadUrl}
disabled={!hasRole}
>
{t('Download')}
onDelete(debugFileId)}
disabled={!hasAccess}
>
}
size="xs"
disabled={!hasAccess}
aria-label={t('Delete')}
/>
)}
)}
);
if (!deleted) {
return actions;
}
return (
{actions}
);
}
export default Actions;
const StyledDropdownLink = styled(DropdownLink)`
display: none;
@media (min-width: ${props => props.theme.breakpoints.xxlarge}) {
display: flex;
align-items: center;
transition: none;
}
`;
const StyledButtonBar = styled(ButtonBar)`
@media (min-width: ${props => props.theme.breakpoints.xxlarge}) {
display: none;
}
`;