-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(frontend): Pass action button into data table toolbar
- Loading branch information
Showing
5 changed files
with
122 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/sections/profiles/components/profile-actions-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu'; | ||
import { Button } from '@/components/ui/button'; | ||
import { ChevronDown } from 'lucide-react'; | ||
import { | ||
AlertDialog, | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogTitle, | ||
} from '@/components/ui/alert-dialog'; | ||
import ProfileFormDialog from '@/sections/profiles/components/profile-form-dialog'; | ||
import { Profile } from '@/modules/profiles/domain'; | ||
|
||
interface DataTableActionsButtonProps { | ||
selectedRows: Profile[]; | ||
} | ||
|
||
export default function ProfileActionsButton({ | ||
selectedRows, | ||
}: Readonly<DataTableActionsButtonProps>) { | ||
const [showDeleteDialog, setShowDeleteDialog] = React.useState(false); | ||
const [showUpdateDialog, setShowUpdateDialog] = React.useState(false); | ||
const [showCreateDialog, setShowCreateDialog] = React.useState(false); | ||
|
||
async function onDelete() { | ||
console.info('deleted', selectedRows); | ||
// invoke('delete_profile', { profileName: profile.name }).then(() => { | ||
// mutate('get_profiles'); | ||
// }); | ||
// setShowDeleteDialog(false); | ||
} | ||
|
||
return ( | ||
<> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button | ||
variant='outline' | ||
size='sm' | ||
className='ml-auto hidden h-8 border-dashed lg:flex' | ||
> | ||
<ChevronDown className='mr-2 h-4 w-4' /> | ||
Actions | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align='end' className='w-[150px]'> | ||
<DropdownMenuItem onSelect={() => setShowCreateDialog(true)}> | ||
Create new | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
onSelect={() => setShowUpdateDialog(true)} | ||
disabled={!selectedRows || selectedRows?.length !== 1} | ||
> | ||
Edit | ||
</DropdownMenuItem> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItem | ||
onSelect={() => setShowDeleteDialog(true)} | ||
disabled={!selectedRows || selectedRows?.length === 0} | ||
> | ||
Delete all | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
|
||
<ProfileFormDialog | ||
open={showCreateDialog} | ||
setOpen={setShowCreateDialog} | ||
/> | ||
|
||
<ProfileFormDialog | ||
profile={selectedRows[0]} | ||
open={showUpdateDialog} | ||
setOpen={setShowUpdateDialog} | ||
/> | ||
|
||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>Are you sure?</AlertDialogTitle> | ||
<AlertDialogDescription> | ||
This action cannot be undone. This will permanently delete the{' '} | ||
<strong> ALL</strong> selected profiles as well as it's{' '} | ||
corresponding configuration settings and credentials. | ||
</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel>Cancel</AlertDialogCancel> | ||
<AlertDialogAction onClick={onDelete}>Continue</AlertDialogAction> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters