Skip to content

Commit

Permalink
disable the edit table button when there is a job is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewThien committed Dec 5, 2024
1 parent 33e7698 commit 5b8e4db
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions app/next-client-app/components/scanreports/EditButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Link from "next/link";
import { Button } from "../ui/button";
import { Pencil } from "lucide-react";
import { Tooltips } from "../Tooltips";
import { cn } from "@/lib/utils";

export function EditButton({
scanreportId,
Expand All @@ -9,46 +11,42 @@ export function EditButton({
type,
permissions,
prePath,
generalStatus,
}: {
scanreportId?: number;
tableId?: number;
fieldID?: number;
prePath?: string;
type: string;
permissions: Permission[];
generalStatus?: string;
}) {
const canEdit =
permissions.includes("CanEdit") || permissions.includes("CanAdmin");
(permissions.includes("CanEdit") || permissions.includes("CanAdmin")) &&
generalStatus != "IN_PROGRESS";
return (
<Link
href={
canEdit
? type === "table" || type === "table-row"
? type === "table"
? `/scanreports/${scanreportId}/tables/${tableId}/update`
: type === "field"
? `${prePath}/fields/${fieldID}/update`
: ""
: ""
}
className={canEdit ? "cursor-pointer" : "cursor-not-allowed"}
className={cn(canEdit ? "cursor-pointer" : "cursor-not-allowed", "flex")}
>
<Button
variant={
type === "table" || type === "field"
? "secondary"
: type === "table-row"
? "outline"
: "default"
}
variant={type === "table" || type === "field" ? "secondary" : "default"}
disabled={canEdit ? false : true}
>
{type === "table" || type === "table-row"
? "Edit Table"
: type === "field"
? "Edit Field"
: ""}
{type === "table" ? "Edit Table" : type === "field" ? "Edit Field" : ""}
<Pencil className="ml-2 size-4" />
</Button>
{generalStatus == "IN_PROGRESS" && (
<Tooltips content="You can update the table after jobs running in this scan report finished." />
)}
</Link>
);
}

0 comments on commit 5b8e4db

Please sign in to comment.