Skip to content

Commit e9eca9c

Browse files
authored
deployment 2025-03-11 (#399)
* combine useConfig and useDatabaseDriver into one context * Merge pull request #398 from outerbase/custom-format-cell feat: custom format cell
2 parents eeab8eb + 47a0fb3 commit e9eca9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+478
-312
lines changed

src/components/gui/connection-dialog.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Button } from "@/components/ui/button";
2-
import { useConfig } from "@/context/config-provider";
2+
import { useStudioContext } from "@/context/driver-provider";
33
import { useMemo } from "react";
44
import ServerLoadingAnimation from "../icons/server-loading";
55

@@ -11,7 +11,7 @@ export default function ConnectingDialog({
1111
message?: string;
1212
onRetry?: () => void;
1313
}>) {
14-
const { name, onBack } = useConfig();
14+
const { name, onBack } = useStudioContext();
1515

1616
const isElectron = useMemo(() => {
1717
return typeof window !== "undefined" && window.outerbaseIpc;
@@ -56,7 +56,7 @@ export default function ConnectingDialog({
5656
}
5757

5858
return (
59-
<div className="w-screen h-screen flex items-center justify-center flex-col gap-4">
59+
<div className="flex h-screen w-screen flex-col items-center justify-center gap-4">
6060
<ServerLoadingAnimation />
6161
{body}
6262
</div>

src/components/gui/database-gui.tsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
"use client";
2+
import QueryWindow from "@/components/gui/tabs/query-tab";
23
import {
34
ResizableHandle,
45
ResizablePanel,
56
ResizablePanelGroup,
67
} from "@/components/ui/resizable";
78
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8-
import WindowTabs, { WindowTabItemProps } from "./windows-tab";
9-
import QueryWindow from "@/components/gui/tabs/query-tab";
10-
import SidebarTab, { SidebarTabItem } from "./sidebar-tab";
119
import SchemaView from "./schema-sidebar";
10+
import SidebarTab, { SidebarTabItem } from "./sidebar-tab";
1211
import ToolSidebar from "./sidebar/tools-sidebar";
12+
import WindowTabs, { WindowTabItemProps } from "./windows-tab";
1313

14-
import { useDatabaseDriver } from "@/context/driver-provider";
15-
import SavedDocTab from "./sidebar/saved-doc-tab";
14+
import { useStudioContext } from "@/context/driver-provider";
1615
import { useSchema } from "@/context/schema-provider";
17-
import { Binoculars, GearSix, Table } from "@phosphor-icons/react";
18-
import { normalizedPathname, sendAnalyticEvents } from "@/lib/tracking";
19-
import { useConfig } from "@/context/config-provider";
20-
import { cn } from "@/lib/utils";
2116
import { scc } from "@/core/command";
2217
import {
2318
tabCloseChannel,
2419
tabOpenChannel,
2520
tabReplaceChannel,
2621
} from "@/core/extension-tab";
22+
import { normalizedPathname, sendAnalyticEvents } from "@/lib/tracking";
23+
import { cn } from "@/lib/utils";
24+
import { Binoculars, GearSix, Table } from "@phosphor-icons/react";
25+
import SavedDocTab from "./sidebar/saved-doc-tab";
2726

2827
export default function DatabaseGui() {
2928
const DEFAULT_WIDTH = 300;
@@ -34,8 +33,8 @@ export default function DatabaseGui() {
3433
setDefaultWidthPercentage((DEFAULT_WIDTH / window.innerWidth) * 100);
3534
}, []);
3635

37-
const { databaseDriver, docDriver } = useDatabaseDriver();
38-
const { extensions, containerClassName } = useConfig();
36+
const { databaseDriver, docDriver, extensions, containerClassName } =
37+
useStudioContext();
3938

4039
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
4140
const { currentSchemaName } = useSchema();

src/components/gui/main-connection.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
import { TooltipProvider } from "@/components/ui/tooltip";
33
import { WEBSITE_NAME } from "@/const";
44
import { AutoCompleteProvider } from "@/context/auto-complete-provider";
5-
import { useConfig } from "@/context/config-provider";
6-
import { useDatabaseDriver } from "@/context/driver-provider";
5+
import { useStudioContext } from "@/context/driver-provider";
76
import { SchemaProvider } from "@/context/schema-provider";
87
import { useEffect } from "react";
98
import { DialogProvider } from "../create-dialog";
109
import ContextMenuHandler from "./context-menu-handler";
1110
import DatabaseGui from "./database-gui";
1211

1312
function MainConnection() {
14-
const { databaseDriver: driver } = useDatabaseDriver();
13+
const { databaseDriver: driver } = useStudioContext();
1514

1615
useEffect(() => {
1716
return () => {
@@ -28,7 +27,7 @@ function MainConnection() {
2827
}
2928

3029
function MainConnectionContainer() {
31-
const { name } = useConfig();
30+
const { name } = useStudioContext();
3231

3332
useEffect(() => {
3433
document.title = name + " - " + WEBSITE_NAME;

src/components/gui/query-result-table.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import OptimizeTable, {
22
OptimizeTableHeaderWithIndexProps,
33
} from "@/components/gui/table-optimized";
44
import OptimizeTableState from "@/components/gui/table-optimized/OptimizeTableState";
5-
import { useConfig } from "@/context/config-provider";
5+
import { useStudioContext } from "@/context/driver-provider";
66
import { ColumnSortOption } from "@/drivers/base-driver";
77
import { exportDataAsDelimitedText } from "@/lib/export-helper";
88
import { KEY_BINDING } from "@/lib/key-matcher";
@@ -52,7 +52,8 @@ function Header({
5252

5353
if (internalState.getSelectedColIndex().includes(colIndex)) {
5454
if (internalState.isFullSelectionCol(colIndex)) {
55-
textClass = "grow line-clamp-1 font-mono font-bold text-black dark:text-white font-bold";
55+
textClass =
56+
"grow line-clamp-1 font-mono font-bold text-black dark:text-white font-bold";
5657
thClass =
5758
"flex grow items-center px-2 overflow-hidden bg-neutral-100 dark:bg-neutral-900";
5859
} else {
@@ -126,7 +127,7 @@ export default function ResultTable({
126127
}: ResultTableProps) {
127128
const [stickyHeaderIndex, setStickHeaderIndex] = useState<number>();
128129

129-
const { extensions } = useConfig();
130+
const { extensions } = useStudioContext();
130131

131132
const headerIndex = useMemo(() => {
132133
if (visibleColumnIndexList) return visibleColumnIndexList;
@@ -135,7 +136,7 @@ export default function ResultTable({
135136

136137
const renderHeader = useCallback(
137138
(header: OptimizeTableHeaderWithIndexProps) => {
138-
const extensionMenu = extensions.getQueryHeaderContextMenu(header);
139+
const extensionMenu = extensions.getQueryHeaderContextMenu(header, data);
139140
const extensionMenuItems = extensionMenu.map((item) => {
140141
if (item.component) {
141142
return (

src/components/gui/save-doc-button.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { useStudioContext } from "@/context/driver-provider";
12
import {
23
SavedDocData,
34
SavedDocInput,
45
SavedDocNamespace,
56
} from "@/drivers/saved-doc/saved-doc-driver";
6-
import { Button } from "../ui/button";
7-
import { useDatabaseDriver } from "@/context/driver-provider";
8-
import { useCallback, useState } from "react";
97
import { LucideFolderGit, LucideLoader } from "lucide-react";
8+
import { useCallback, useState } from "react";
9+
import { Button } from "../ui/button";
1010
import {
1111
DropdownMenu,
1212
DropdownMenuContent,
@@ -29,7 +29,7 @@ export default function SaveDocButton({
2929
}: Props) {
3030
const [open, setOpen] = useState(false);
3131
const [loading, setLoading] = useState(false);
32-
const { docDriver } = useDatabaseDriver();
32+
const { docDriver } = useStudioContext();
3333
const [namespaceList, setNamespaceList] = useState<SavedDocNamespace[]>([]);
3434

3535
const onSaveQuery = useCallback(
@@ -86,7 +86,7 @@ export default function SaveDocButton({
8686
variant={"secondary"}
8787
>
8888
{loading ? (
89-
<LucideLoader className="w-4 h-4 animate-spin mr-2" />
89+
<LucideLoader className="mr-2 h-4 w-4 animate-spin" />
9090
) : (
9191
<></>
9292
)}
@@ -104,7 +104,7 @@ export default function SaveDocButton({
104104
onSaveQuery(n.id);
105105
}}
106106
>
107-
<LucideFolderGit className="w-4 h-4 mr-2" /> {n.name}
107+
<LucideFolderGit className="mr-2 h-4 w-4" /> {n.name}
108108
</DropdownMenuItem>
109109
);
110110
})}

src/components/gui/schema-editor/column-default-value-input.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
PopoverContent,
66
PopoverTrigger,
77
} from "@/components/ui/popover";
8-
import { useDatabaseDriver } from "@/context/driver-provider";
8+
import { useStudioContext } from "@/context/driver-provider";
99
import { DatabaseTableColumnConstraint } from "@/drivers/base-driver";
1010
import { ChevronsUpDown } from "lucide-react";
1111
import { ChangeEvent, useCallback, useMemo } from "react";
@@ -20,7 +20,7 @@ export default function ColumnDefaultValueInput({
2020
disabled?: boolean;
2121
onChange: (constraint: DatabaseTableColumnConstraint) => void;
2222
}>) {
23-
const { databaseDriver } = useDatabaseDriver();
23+
const { databaseDriver } = useStudioContext();
2424
const display = useMemo(() => {
2525
if (
2626
constraint?.defaultValue !== undefined &&

src/components/gui/schema-editor/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useDatabaseDriver } from "@/context/driver-provider";
1+
import { useStudioContext } from "@/context/driver-provider";
22
import { DatabaseTableSchemaChange } from "@/drivers/base-driver";
33
import { checkSchemaChange } from "@/lib/sql/sql-generate.schema";
44
import { LucideCode, LucideCopy, LucidePlus, LucideSave } from "lucide-react";
@@ -27,7 +27,7 @@ export default function SchemaEditor({
2727
onSave,
2828
onDiscard,
2929
}: Readonly<Props>) {
30-
const { databaseDriver } = useDatabaseDriver();
30+
const { databaseDriver } = useStudioContext();
3131
const isCreateScript = value.name.old === "";
3232

3333
const onAddColumn = useCallback(() => {
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import { Button } from "@/components/ui/button";
22
import { Input } from "@/components/ui/input";
3+
import { useStudioContext } from "@/context/driver-provider";
34
import { useSchema } from "@/context/schema-provider";
5+
import { DatabaseSchemaChange } from "@/drivers/base-driver";
46
import { LucideAlertCircle, LucideLoader, LucideSave } from "lucide-react";
57
import { useCallback, useMemo, useState } from "react";
6-
import { useDatabaseDriver } from "@/context/driver-provider";
7-
import { DatabaseSchemaChange } from "@/drivers/base-driver";
88

9-
export function SchemaDatabaseCreateForm({ schemaName, onClose }: { schemaName?: string; onClose: () => void; }) {
10-
const { databaseDriver } = useDatabaseDriver();
9+
export function SchemaDatabaseCreateForm({
10+
schemaName,
11+
onClose,
12+
}: {
13+
schemaName?: string;
14+
onClose: () => void;
15+
}) {
16+
const { databaseDriver } = useStudioContext();
1117
const { schema, refresh: refreshSchema } = useSchema();
1218
const [isExecuting, setIsExecuting] = useState(false);
1319
const [errorMessage, setErrorMessage] = useState("");
1420
const [value, setValue] = useState<DatabaseSchemaChange>({
1521
name: {
16-
new: '',
17-
old: ''
22+
new: "",
23+
old: "",
1824
},
19-
createScript: '',
20-
collate: ''
25+
createScript: "",
26+
collate: "",
2127
});
2228

2329
const previewScript = useMemo(() => {
@@ -27,68 +33,76 @@ export function SchemaDatabaseCreateForm({ schemaName, onClose }: { schemaName?:
2733
const onSave = useCallback(() => {
2834
{
2935
setIsExecuting(true);
30-
databaseDriver.transaction([previewScript]).then(() => {
31-
refreshSchema();
32-
onClose();
33-
}).catch((err) => setErrorMessage((err as Error).message)).finally(() => {
34-
setIsExecuting(false);
35-
})
36+
databaseDriver
37+
.transaction([previewScript])
38+
.then(() => {
39+
refreshSchema();
40+
onClose();
41+
})
42+
.catch((err) => setErrorMessage((err as Error).message))
43+
.finally(() => {
44+
setIsExecuting(false);
45+
});
3646
}
37-
}, [databaseDriver, onClose, previewScript, refreshSchema])
47+
}, [databaseDriver, onClose, previewScript, refreshSchema]);
3848

39-
const schemaNames = Object.keys(schema).filter(s => s !== schemaName).map(s => s);
40-
const schemaNameExists = schemaNames.includes(value.name.new || '');
49+
const schemaNames = Object.keys(schema)
50+
.filter((s) => s !== schemaName)
51+
.map((s) => s);
52+
const schemaNameExists = schemaNames.includes(value.name.new || "");
4153

4254
return (
43-
<div className="flex h-full flex-col overflow-hidden relative">
55+
<div className="relative flex h-full flex-col overflow-hidden">
4456
{errorMessage && (
45-
<div className="text-sm text-red-500 font-mono flex gap-4 justify-end items-end">
46-
<LucideAlertCircle className="w-12 h-12" />
57+
<div className="flex items-end justify-end gap-4 font-mono text-sm text-red-500">
58+
<LucideAlertCircle className="h-12 w-12" />
4759
<p>{errorMessage}</p>
4860
</div>
4961
)}
50-
<div className="flex gap-2 shrink-0 grow-0 py-4 px-1 border-neutral-200 dark:border-neutral-800">
62+
<div className="flex shrink-0 grow-0 gap-2 border-neutral-200 px-1 py-4 dark:border-neutral-800">
5163
<div className="w-full">
52-
<div className="text-xs font-medium mb-1">Schema Name</div>
64+
<div className="mb-1 text-xs font-medium">Schema Name</div>
5365
<Input
5466
placeholder="Schema Name"
55-
value={value.name.new || value.name.old || ''}
67+
value={value.name.new || value.name.old || ""}
5668
onChange={(e) => {
5769
setValue({
5870
...value,
5971
name: {
6072
...value.name,
61-
new: e.currentTarget.value
62-
}
63-
})
73+
new: e.currentTarget.value,
74+
},
75+
});
6476
}}
6577
disabled={!!schemaName}
66-
className={`w-full ${schemaNameExists ? 'border-red-600' : ''}`}
78+
className={`w-full ${schemaNameExists ? "border-red-600" : ""}`}
6779
/>
68-
{
69-
schemaNameExists && <small className="text-xs text-red-500">The schema name `{value.name.new}` already exists.</small>
70-
}
80+
{schemaNameExists && (
81+
<small className="text-xs text-red-500">
82+
The schema name `{value.name.new}` already exists.
83+
</small>
84+
)}
7185
</div>
7286
</div>
73-
<div className="w-full flex flex-col pt-3">
74-
<div className="grow-0 shrink-0">
75-
<div className="p-1 flex gap-2 justify-end">
87+
<div className="flex w-full flex-col pt-3">
88+
<div className="shrink-0 grow-0">
89+
<div className="flex justify-end gap-2 p-1">
7690
<Button
7791
variant="ghost"
7892
disabled={!!schemaNameExists}
7993
size={"sm"}
8094
onClick={onSave}
8195
>
8296
{isExecuting ? (
83-
<LucideLoader className="w-4 h-4 mr-2 animate-spin" />
97+
<LucideLoader className="mr-2 h-4 w-4 animate-spin" />
8498
) : (
85-
<LucideSave className="w-4 h-4 mr-2" />
99+
<LucideSave className="mr-2 h-4 w-4" />
86100
)}
87101
Save
88102
</Button>
89103
</div>
90104
</div>
91105
</div>
92106
</div>
93-
)
94-
}
107+
);
108+
}

src/components/gui/schema-editor/schema-editor-column-list.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button } from "@/components/ui/button";
22
import { Checkbox } from "@/components/ui/checkbox";
3-
import { useDatabaseDriver } from "@/context/driver-provider";
3+
import { useStudioContext } from "@/context/driver-provider";
44
import {
55
DatabaseTableColumn,
66
DatabaseTableColumnChange,
@@ -104,7 +104,7 @@ function ColumnItemType({
104104
onChange: (type: string) => void;
105105
disabled?: boolean;
106106
}) {
107-
const { databaseDriver } = useDatabaseDriver();
107+
const { databaseDriver } = useStudioContext();
108108

109109
if (
110110
databaseDriver.columnTypeSelector.type === "dropdown" &&

src/components/gui/schema-editor/schema-save-dialog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
AlertDialogTitle,
77
} from "@/components/ui/alert-dialog";
88
import { Button } from "@/components/ui/button";
9-
import { useDatabaseDriver } from "@/context/driver-provider";
9+
import { useStudioContext } from "@/context/driver-provider";
1010
import { useSchema } from "@/context/schema-provider";
1111
import { DatabaseTableSchemaChange } from "@/drivers/base-driver";
1212
import {
@@ -31,7 +31,7 @@ export default function SchemaSaveDialog({
3131
onClose: () => void;
3232
fetchTable: (schemeName: string, tableName: string) => Promise<void>;
3333
}) {
34-
const { databaseDriver } = useDatabaseDriver();
34+
const { databaseDriver } = useStudioContext();
3535
const { refresh: refreshSchema } = useSchema();
3636
const [isExecuting, setIsExecuting] = useState(false);
3737
const [errorMessage, setErrorMessage] = useState("");

0 commit comments

Comments
 (0)