Skip to content

Commit 4c96da2

Browse files
committed
Fix input validation in admin dash for nullable columns in the insert/alter-row form.
1 parent 0b09795 commit 4c96da2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ui/admin/src/components/tables/InsertAlterRow.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,12 @@ export function InsertAlterRowForm(props: {
116116
const form = createForm<FormRow>(() => ({
117117
defaultValues: props.row ?? buildDefault(props.schema),
118118
onSubmit: async ({ value }) => {
119-
console.debug("Submitting:", value);
119+
console.debug(`Submitting {original ? "update" : "insert"}:`, value);
120120
try {
121121
if (original) {
122-
const response = await updateRow(props.schema, value);
123-
console.debug("UpdateRowResponse:", response);
122+
await updateRow(props.schema, value);
124123
} else {
125-
const response = await insertRow(props.schema.name, value);
126-
console.debug("InsertRowResponse:", response);
124+
await insertRow(props.schema.name, value);
127125
}
128126

129127
props.rowsRefetch();
@@ -170,11 +168,21 @@ export function InsertAlterRowForm(props: {
170168
name={col.name}
171169
validators={{
172170
onChange: ({ value }: { value: string | undefined }) => {
171+
if (value !== undefined) {
172+
// TODO: Better input validation
173+
if (value === "" && col.data_type !== "Text") {
174+
return `Invalid value for: ${col.data_type}`;
175+
}
176+
return undefined;
177+
}
178+
173179
const defaultValue = getDefaultValue(col.options);
174180
if (defaultValue !== undefined) {
175181
return undefined;
176182
}
177-
return value !== undefined ? undefined : "Missing value";
183+
if (isNotNull(col.options)) {
184+
return `Missing value for ${col.name}`;
185+
}
178186
},
179187
}}
180188
children={formFieldBuilder(

0 commit comments

Comments
 (0)