Skip to content

Commit 15187cb

Browse files
committed
updates
1 parent e729dc7 commit 15187cb

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

components/xata/actions/common/common.mjs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export default {
3838
propDefinition: [
3939
app,
4040
"table",
41+
(c) => ({
42+
endpoint: c.endpoint,
43+
database: c.database,
44+
branch: c.branch,
45+
}),
4146
],
4247
reloadProps: true,
4348
},
@@ -53,24 +58,19 @@ export default {
5358
const description = "The keys and values of the data that will be recorded in the database.";
5459

5560
if (endpoint && database && branch && table) {
56-
try {
57-
const { columns } = await this.app.listColumns({
58-
endpoint,
59-
database,
60-
branch,
61-
table,
62-
});
63-
if (columns?.length) {
64-
let descriptionWithColumns = `${description} Available Columns:`;
65-
for (const column of columns) {
66-
descriptionWithColumns += ` \`${column.name}\``;
67-
}
68-
props.recordData.description = descriptionWithColumns;
69-
return {};
61+
const { columns } = await this.app.listColumns({
62+
endpoint,
63+
database,
64+
branch,
65+
table,
66+
});
67+
if (columns?.length) {
68+
let descriptionWithColumns = `${description} Available Columns:`;
69+
for (const column of columns) {
70+
descriptionWithColumns += ` \`${column.name}\``;
7071
}
71-
} catch (e) {
72-
props.recordData.description = description;
73-
// Columns not found. Occurs when the user hasn't finished entering the table name
72+
props.recordData.description = descriptionWithColumns;
73+
return {};
7474
}
7575
}
7676
props.recordData.description = description;
@@ -89,12 +89,18 @@ export default {
8989
return this.recordData;
9090
}
9191
for (const column of columns) {
92-
if (recordData[column.name] && (column.type === "int" || column.type === "float")) {
92+
if (!recordData[column.name] || typeof recordData[column.name] !== "string") {
93+
continue;
94+
}
95+
if ((column.type === "int" || column.type === "float")) {
9396
recordData[column.name] = +recordData[column.name];
9497
}
95-
if (recordData[column.name] && column.type === "bool") {
98+
if (column.type === "bool") {
9699
recordData[column.name] = !(recordData[column.name] === "false" || recordData[column.name === "0"]);
97100
}
101+
if (column.type === "multiple" || column.type === "vector") {
102+
recordData[column.name] = JSON.parse(recordData[column.name]);
103+
}
98104
}
99105
return recordData;
100106
},

components/xata/xata.app.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ export default {
2727
type: "string",
2828
label: "Table Name",
2929
description: "Name of the table",
30+
async options({
31+
endpoint, database, branch,
32+
}) {
33+
const { schema: { tables } } = await this.getBranchSchema({
34+
endpoint,
35+
database,
36+
branch,
37+
});
38+
return tables?.map(({ name }) => name ) || [];
39+
},
3040
},
3141
endpoint: {
3242
type: "string",
@@ -175,5 +185,13 @@ export default {
175185
...args,
176186
});
177187
},
188+
getBranchSchema({
189+
endpoint, database, branch, ...args
190+
}) {
191+
return this._makeRequest({
192+
url: `${endpoint}/db/${database}:${branch}`,
193+
...args,
194+
});
195+
},
178196
},
179197
};

0 commit comments

Comments
 (0)