-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
261 additions
and
50 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useDatabaseDriver } from "@/context/DatabaseDriverProvider"; | ||
import { DatabaseTriggerSchema } from "@/drivers/base-driver"; | ||
import { useEffect, useState } from "react"; | ||
import { Input } from "../ui/input"; | ||
import SqlEditor from "../sql-editor"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "../ui/select"; | ||
import TableCombobox from "../table-combobox/TableCombobox"; | ||
|
||
export default function TriggerTab({ name }: { name: string }) { | ||
const { databaseDriver } = useDatabaseDriver(); | ||
const [trigger, setTrigger] = useState<DatabaseTriggerSchema>(); | ||
const [error, setError] = useState<string>(); | ||
|
||
useEffect(() => { | ||
databaseDriver | ||
.trigger(name) | ||
.then(setTrigger) | ||
.catch((e: Error) => { | ||
setError(e.message); | ||
}); | ||
}, [databaseDriver, name]); | ||
|
||
if (error) { | ||
return <div className="p-4">{error}</div>; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col overflow-hidden w-full h-full"> | ||
<div className="p-4 flex flex-col gap-2"> | ||
<div className="text-xs text-gray-800">Trigger Name</div> | ||
<Input value={trigger?.name ?? ""} readOnly /> | ||
|
||
<div className="flex gap-2"> | ||
<div className="w-[200px]"> | ||
<Select value={trigger?.when ?? "BEFORE"}> | ||
<SelectTrigger> | ||
<SelectValue placeholder="When" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectItem value="BEFORE">Before</SelectItem> | ||
<SelectItem value="AFTER">After</SelectItem> | ||
<SelectItem value="INSTEAD_OF">Instead Of</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
<div className="w-[200px]"> | ||
<Select value={trigger?.operation}> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Operation" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectItem value="INSERT">Insert</SelectItem> | ||
<SelectItem value="UPDATE">Update</SelectItem> | ||
<SelectItem value="DELETE">Delete</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
<TableCombobox value={trigger?.tableName} onChange={() => {}} /> | ||
</div> | ||
</div> | ||
<div className="grow overflow-hidden"> | ||
<div className="h-full"> | ||
<SqlEditor value={trigger?.statement ?? ""} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.