Skip to content

Commit

Permalink
Fix table creator incorrectly allowing saving (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul authored Jan 7, 2025
1 parent 526fac5 commit 57d5fb2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/components/App/modals/table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Group, Modal, MultiSelect, Select, Stack, Tabs, TextInput } from "@mantine/core";
import { useInputState } from "@mantine/hooks";
import { useLayoutEffect, useState } from "react";
import { useLayoutEffect, useMemo, useState } from "react";
import { escapeIdent } from "surrealdb";
import { Form } from "~/components/Form";
import { Icon } from "~/components/Icon";
Expand Down Expand Up @@ -69,6 +69,16 @@ export function TableCreatorModal() {

useIntent("new-table", openTableCreator);

const isValid = useMemo(() => {
if (!tableName) return false;

if (createType === "relation") {
return tableIn.length > 0 && tableOut.length > 0;
}

return true;
}, [tableName, tableIn, tableOut, createType]);

return (
<>
<Modal
Expand Down Expand Up @@ -146,10 +156,7 @@ export function TableCreatorModal() {
type="submit"
variant="gradient"
flex={1}
disabled={
!tableName ||
(createType === "relation" && (!tableIn || !tableOut))
}
disabled={!isValid}
rightSection={<Icon path={iconPlus} />}
>
Create
Expand Down

0 comments on commit 57d5fb2

Please sign in to comment.