Skip to content

Commit

Permalink
fix save columns data empty space
Browse files Browse the repository at this point in the history
  • Loading branch information
roth-dev committed Jan 30, 2025
1 parent 4706116 commit 34c1f37
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions src/extensions/data-catalog/data-model-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SchemaNameSelect from "@/components/gui/schema-editor/schema-name-select";
import { Toolbar } from "@/components/gui/toolbar";
import { Toolbar, ToolbarFiller } from "@/components/gui/toolbar";
import { Button } from "@/components/ui/button";
import {
Dialog,
Expand All @@ -10,6 +10,7 @@ import {
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { useConfig } from "@/context/config-provider";
Expand Down Expand Up @@ -63,6 +64,34 @@ function DataCatalogTableColumnModal({
.finally(() => setSampleLoading(false));
}, [databaseDriver, columnName, schemaName, tableName]);

const onSaveUpdateColumn = useCallback(() => {
setLoading(true);

driver
.updateColumn(schemaName, tableName, columnName, {
definition,
samples:
samples && samples.trim()
? samples.split(",").map((s) => s.trim())
: [],
hideFromEzql: modelColumn?.hideFromEzql ?? false,
})
.then()
.finally(() => {
setLoading(false);
onClose();
});
}, [
driver,
modelColumn,
samples,
columnName,
onClose,
schemaName,
tableName,
definition,
]);

return (
<>
<DialogHeader>
Expand Down Expand Up @@ -113,24 +142,7 @@ function DataCatalogTableColumnModal({
</div>

<DialogFooter>
<Button
disabled={loading}
onClick={() => {
setLoading(true);

driver
.updateColumn(schemaName, tableName, columnName, {
definition,
samples: samples.split(",").map((s) => s.trim()),
hideFromEzql: modelColumn?.hideFromEzql ?? false,
})
.then()
.finally(() => {
setLoading(false);
onClose();
});
}}
>
<Button disabled={loading} onClick={onSaveUpdateColumn}>
{loading && <LucideLoader className="mr-1 h-4 w-4 animate-spin" />}
Save
</Button>
Expand Down Expand Up @@ -227,6 +239,7 @@ function DataCatalogTableAccordion({

export default function DataCatalogModelTab() {
const { currentSchemaName, schema } = useSchema();
const [search, setSearch] = useState("");
const [selectedSchema, setSelectedSchema] = useState(currentSchemaName);

const { extensions } = useConfig();
Expand All @@ -236,6 +249,10 @@ export default function DataCatalogModelTab() {

const driver = dataCatalogExtension?.driver;

const onChangeText = useCallback((value: string) => {
setSearch(value);
}, []);

const currentSchema = useMemo(() => {
if (!selectedSchema) return [];
const result = (schema[selectedSchema] || [])
Expand All @@ -259,6 +276,16 @@ export default function DataCatalogModelTab() {
value={selectedSchema}
onChange={setSelectedSchema}
/>
<ToolbarFiller />
<div>
<Input
value={search}
onChange={(e) => {
onChangeText(e.currentTarget.value);
}}
placeholder="Search tables, columns"
/>
</div>
</Toolbar>
</div>

Expand Down

0 comments on commit 34c1f37

Please sign in to comment.