2024-06-30 15:36:44 +00:00
|
|
|
import { ContextMenuContent, ContextMenuItem, ContextMenuSubTrigger, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent } from "@/components/ui/context-menu"
|
2024-06-27 10:44:31 +00:00
|
|
|
import Link from "next/link"
|
2024-07-21 17:14:20 +00:00
|
|
|
import { ComponentProps, useState } from "react"
|
2024-06-30 15:36:44 +00:00
|
|
|
import { Row, Table, TableState } from "@tanstack/react-table"
|
2024-06-27 10:44:31 +00:00
|
|
|
|
2024-08-07 13:46:14 +00:00
|
|
|
export default function FormContextMenu({ table, row, openEditDialog, openDeleteDialog }: ComponentProps<"div"> & { table: Table<any>, row: Row<any>, openEditDialog: (row: Row<any>) => void, openDeleteDialog: (row: Row<any>) => void }) {
|
2024-06-30 15:36:44 +00:00
|
|
|
const pathname = table.options.meta.pathname
|
|
|
|
const selectedRows = table.getSelectedRowModel().flatRows
|
2024-07-21 17:14:20 +00:00
|
|
|
|
|
|
|
|
2024-06-27 10:44:31 +00:00
|
|
|
return (
|
2024-08-07 13:46:14 +00:00
|
|
|
<ContextMenuContent >
|
|
|
|
{pathname !== "/submission" && selectedRows.length <= 1 ?
|
|
|
|
<>
|
|
|
|
<Link href={`${pathname}/${row.original.id}`}>
|
|
|
|
<ContextMenuItem>Inspect</ContextMenuItem>
|
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
|
2024-09-26 10:37:52 +00:00
|
|
|
<ContextMenuItem onClick={() => openEditDialog(row)}>
|
|
|
|
Edit
|
|
|
|
</ContextMenuItem>
|
2024-07-21 17:14:20 +00:00
|
|
|
|
2024-08-07 13:46:14 +00:00
|
|
|
{
|
|
|
|
selectedRows.length > 0 ?
|
|
|
|
<ContextMenuItem onClick={() => { table.resetRowSelection() }}>Deselect</ContextMenuItem>
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
<ContextMenuSeparator />
|
|
|
|
<ContextMenuItem className="text-destructive" onClick={() => openDeleteDialog(row)}>Delete</ContextMenuItem>
|
|
|
|
</ContextMenuContent>
|
2024-06-27 10:44:31 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
}
|