Skip to content

Commit

Permalink
Check that user can bulk delete before showing bulk delete button/modal
Browse files Browse the repository at this point in the history
  • Loading branch information
p2edwards committed Aug 21, 2023
1 parent 128e97a commit bf559fb
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions jsapp/js/projects/projectsTable/projectBulkActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import type {AssetResponse, ProjectViewAsset} from 'js/dataInterface';
import Button from 'js/components/common/button';
import actionsStyles from './projectActions.module.scss';
import BulkDeletePrompt from './bulkActions/bulkDeletePrompt';
import {userCan} from 'js/components/permissions/utils';

interface ProjectBulkActionsProps {
/** A list of selected assets for bulk operations. */
assets: Array<AssetResponse | ProjectViewAsset>;
}

function userCanDeleteAssets(assets: Array<AssetResponse | ProjectViewAsset>) {
return assets.every((asset) => userCan('manage_asset', asset));
}

export default function ProjectBulkActions(props: ProjectBulkActionsProps) {
const [isDeletePromptOpen, setIsDeletePromptOpen] = useState(false);
const canBulkDelete = userCanDeleteAssets(props.assets);

return (
<div className={actionsStyles.root}>
Expand All @@ -37,18 +43,30 @@ export default function ProjectBulkActions(props: ProjectBulkActionsProps) {
/>

{/* Delete */}
<Button
type='bare'
color='storm'
size='s'
startIcon='trash'
tooltip={t('Delete ##count## projects').replace(
'##count##',
String(props.assets.length)
)}
onClick={() => setIsDeletePromptOpen(true)}
classNames={['right-tooltip']}
/>
{canBulkDelete ? (
<Button
type='bare'
color='storm'
size='s'
startIcon='trash'
tooltip={t('Delete ##count## projects').replace(
'##count##',
String(props.assets.length)
)}
onClick={() => setIsDeletePromptOpen(true)}
classNames={['right-tooltip']}
/>
) : (
<Button
isDisabled
type='bare'
color='storm'
size='s'
startIcon='trash'
tooltip={t('Delete projects')}
classNames={['right-tooltip']}
/>
)}

{isDeletePromptOpen && (
<BulkDeletePrompt
Expand Down

0 comments on commit bf559fb

Please sign in to comment.