Skip to content

Commit 693aa7b

Browse files
committed
polish up initial dolt integration
1 parent ca9187a commit 693aa7b

File tree

5 files changed

+362
-60
lines changed

5 files changed

+362
-60
lines changed

src/components/common-dialog/index.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DialogDescription,
1515
DialogFooter,
1616
DialogHeader,
17+
DialogTitle,
1718
} from "../ui/dialog";
1819
import { Button } from "../ui/button";
1920
import { Icon } from "@phosphor-icons/react";
@@ -70,20 +71,22 @@ export function CommonDialogProvider({ children }: PropsWithChildren) {
7071
<DialogHeader
7172
className={dialogOption?.destructive ? "text-red-500" : ""}
7273
>
73-
{dialogOption.title}
74+
<DialogTitle>{dialogOption.title}</DialogTitle>
7475
</DialogHeader>
75-
<DialogDescription className="flex flex-col gap-2">
76-
{errorMessage && (
77-
<div className="text-sm text-red-500 font-mono flex gap-4 items-end">
78-
<p>{errorMessage}</p>
79-
</div>
80-
)}
8176

82-
<div>{dialogOption.content}</div>
83-
{dialogOption.previewCode && (
84-
<CodePreview code={dialogOption.previewCode} />
85-
)}
86-
</DialogDescription>
77+
{errorMessage && (
78+
<div className="text-sm text-red-500 font-mono flex gap-4 items-end">
79+
<p>{errorMessage}</p>
80+
</div>
81+
)}
82+
83+
<div>{dialogOption.content}</div>
84+
{dialogOption.previewCode && (
85+
<CodePreview code={dialogOption.previewCode} />
86+
)}
87+
88+
<DialogDescription className="flex flex-col gap-2"></DialogDescription>
89+
8790
<DialogFooter>
8891
{dialogOption.actions?.map((action) => (
8992
<Button

src/components/gui/database-gui.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import SavedDocTab from "./sidebar/saved-doc-tab";
2020
import { useSchema } from "@/context/schema-provider";
2121
import { Binoculars, GearSix, Table } from "@phosphor-icons/react";
2222
import DoltSidebar from "./database-specified/dolt/dolt-sidebar";
23+
import { DoltIcon } from "../icons/outerbase-icon";
2324

2425
export default function DatabaseGui() {
2526
const DEFAULT_WIDTH = 300;
@@ -111,11 +112,7 @@ export default function DatabaseGui() {
111112
key: "dolt",
112113
name: "Dolt",
113114
content: <DoltSidebar />,
114-
icon: (
115-
<div className="font-mono text-3xl font-bold text-green-500">
116-
d
117-
</div>
118-
),
115+
icon: <DoltIcon className="w-7 h-7 text-green-500" />,
119116
}
120117
: undefined,
121118
].filter(Boolean) as SidebarTabItem[];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { Button } from "@/components/ui/button";
2+
import {
3+
Dialog,
4+
DialogContent,
5+
DialogDescription,
6+
DialogFooter,
7+
DialogHeader,
8+
DialogTitle,
9+
} from "@/components/ui/dialog";
10+
import { Input } from "@/components/ui/input";
11+
import { useDatabaseDriver } from "@/context/driver-provider";
12+
import { GitBranch, Loader } from "lucide-react";
13+
import { useCallback, useMemo, useState } from "react";
14+
15+
export default function useDoltCreateBranchModal(refreshStatus: () => void) {
16+
const { databaseDriver } = useDatabaseDriver();
17+
const [open, setOpen] = useState(false);
18+
const [loading, setLoading] = useState(false);
19+
const [errorMessage, setErrorMessage] = useState<string | undefined>();
20+
const [branchName, setBranchName] = useState<string>();
21+
const [commitHash, setCommitHash] = useState<string | undefined>();
22+
23+
const onSaveClicked = useCallback(() => {
24+
const command = commitHash
25+
? `CALL DOLT_CHECKOUT('-b', ${databaseDriver.escapeValue(branchName)}, ${databaseDriver.escapeValue(commitHash)});`
26+
: `CALL DOLT_CHECKOUT('-b', ${databaseDriver.escapeValue(branchName)});`;
27+
28+
setLoading(true);
29+
databaseDriver
30+
.query(command)
31+
.then(() => {
32+
refreshStatus();
33+
setOpen(false);
34+
})
35+
.catch((e) => {
36+
setLoading(false);
37+
if (e instanceof Error) {
38+
setErrorMessage(e.message);
39+
} else {
40+
setErrorMessage("An error occurred");
41+
}
42+
});
43+
}, [databaseDriver, refreshStatus, commitHash, branchName]);
44+
45+
const modal = useMemo(() => {
46+
if (!open) return null;
47+
48+
return (
49+
<Dialog open={open} onOpenChange={setOpen}>
50+
<DialogContent>
51+
<DialogHeader>
52+
<DialogTitle>Create Branch</DialogTitle>
53+
</DialogHeader>
54+
55+
<DialogDescription>
56+
{commitHash ? (
57+
<>
58+
Creating new branch from{" "}
59+
<span className="bg-muted rounded inline-flex font-mono px-2">
60+
{commitHash}
61+
</span>
62+
</>
63+
) : (
64+
"Creating new branch"
65+
)}
66+
</DialogDescription>
67+
68+
{errorMessage && (
69+
<div className="py-2 font-mono text-red-500">{errorMessage}</div>
70+
)}
71+
72+
<div>
73+
<Input
74+
value={branchName}
75+
placeholder="Branch Name"
76+
onChange={(e) => setBranchName(e.currentTarget.value)}
77+
/>
78+
</div>
79+
80+
<DialogFooter>
81+
<Button disabled={!branchName || loading} onClick={onSaveClicked}>
82+
{loading ? (
83+
<Loader className="mr-2 w-4 h-4 animate-spin" />
84+
) : (
85+
<GitBranch className="mr-2 w-4 h-4" />
86+
)}
87+
Create
88+
</Button>
89+
</DialogFooter>
90+
</DialogContent>
91+
</Dialog>
92+
);
93+
}, [open, branchName, commitHash, onSaveClicked, loading, errorMessage]);
94+
95+
const openModal = (commitHash?: string) => {
96+
setCommitHash(commitHash);
97+
setBranchName("");
98+
setLoading(false);
99+
setOpen(true);
100+
setErrorMessage(undefined);
101+
};
102+
103+
return { modal, openModal };
104+
}

0 commit comments

Comments
 (0)