Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty strings in JSON form #467

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 37 additions & 23 deletions arroyo-console/src/routes/connections/JsonForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function StringWidget({
errors,
onChange,
readonly,
resetField,
}: {
path: string;
title: string;
Expand All @@ -56,7 +57,16 @@ function StringWidget({
errors: any;
onChange: (e: React.ChangeEvent<any>) => void;
readonly?: boolean;
resetField?: (field: string) => any;
}) {
const onChangeWrapper = (e: React.ChangeEvent<any>) => {
onChange(e);

if (resetField && e.target.value == '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be before the parent onchange? For the connection page, we rely on onchange to synchronize the current state for validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue that since we want to set the value to undefined, we need to do that after onChange sets it to the empty string.

resetField(path);
}
};

return (
<FormControl isRequired={required} isInvalid={errors[path]}>
<FormLabel>{title}</FormLabel>
Expand All @@ -66,15 +76,15 @@ function StringWidget({
type={password ? 'password' : 'text'}
placeholder={readonly ? undefined : placeholder}
value={value || ''}
onChange={e => onChange(e)}
onChange={onChangeWrapper}
readOnly={readonly}
/>
) : (
<Textarea
name={path}
placeholder={placeholder}
value={value || ''}
onChange={e => onChange(e)}
onChange={onChangeWrapper}
resize={'vertical'}
size={'md'}
readOnly={readonly}
Expand Down Expand Up @@ -659,7 +669,7 @@ export function FormInner({
// @ts-ignore
onChange({ target: { name: path, value: {} } });
}
}, [schema]);
}, []);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwylde This should make it add the empty object on only the first render


function traversePath(values: any, typeKey: string): any {
let value = values;
Expand Down Expand Up @@ -734,6 +744,7 @@ export function FormInner({
errors={errors}
onChange={onChange}
readonly={readonly}
resetField={resetField}
/>
);
}
Expand Down Expand Up @@ -811,7 +822,7 @@ export function FormInner({
<Box p={4}>
<FormInner
path={nextPath}
key={key}
key={value}
// @ts-ignore
schema={inSchema}
errors={errors}
Expand All @@ -827,25 +838,28 @@ export function FormInner({
);
} else if (property.properties != undefined) {
return (
<fieldset key={key} style={{ border: '1px solid #888', borderRadius: '8px' }}>
<legend
style={{ marginLeft: '8px', paddingLeft: '16px', paddingRight: '16px' }}
>
{property.title || key}
</legend>
<Box p={4}>
<FormInner
path={nextPath}
// @ts-ignore
schema={property}
errors={errors}
onChange={onChange}
values={values}
resetField={resetField}
readonly={readonly}
/>
</Box>
</fieldset>
<FormControl isInvalid={errors[nextPath]}>
<fieldset key={key} style={{ border: '1px solid #888', borderRadius: '8px' }}>
<legend
style={{ marginLeft: '8px', paddingLeft: '16px', paddingRight: '16px' }}
>
{property.title || key}
</legend>
<Box p={4}>
<FormInner
path={nextPath}
// @ts-ignore
schema={property}
errors={errors}
onChange={onChange}
values={values}
resetField={resetField}
readonly={readonly}
/>
</Box>
</fieldset>
<FormErrorMessage>{errors[nextPath] ?? ''}</FormErrorMessage>
</FormControl>
);
} else if (property.additionalProperties) {
return (
Expand Down
8 changes: 8 additions & 0 deletions connector-schemas/confluent/connection.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
]
}
},
"dependentRequired": {
"apiKey": [
"endpoint"
],
"apiSecret": [
"endpoint"
]
},
"sensitive": [
"apiSecret"
]
Expand Down