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

Fix: uncontrolled input in dashboard #895

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions openadapt/app/dashboard/app/settings/(api_keys)/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ type Props = {
export const Form = ({
settings,
}: Props) => {
const defaultSettings = {
PRIVATE_AI_API_KEY: '',
REPLICATE_API_TOKEN: '',
OPENAI_API_KEY: '',
ANTHROPIC_API_KEY: '',
GOOGLE_API_KEY: '',
};
Copy link
Member

Choose a reason for hiding this comment

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

This looks like the third place we are duplicating configuration setting names. Is there any way to populate this dynmamically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we populate this dynamically using config file but sometimes we might get undefined values which might be the reason for warning. So, I added these default values


const form = useForm({
initialValues: JSON.parse(JSON.stringify(settings)),
})
initialValues: { ...defaultSettings, ...settings },
});

useEffect(() => {
form.setValues(JSON.parse(JSON.stringify(settings)));
form.setInitialValues(JSON.parse(JSON.stringify(settings)));
// Only set values if settings are defined and different from initial values
if (settings && JSON.stringify(form.values) !== JSON.stringify(settings)) {
form.setValues({ ...defaultSettings, ...settings });
form.setInitialValues({ ...defaultSettings, ...settings });
}
}, [settings]);

function resetForm() {
Expand Down
10 changes: 5 additions & 5 deletions openadapt/app/dashboard/app/settings/record_and_replay/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ export const Form = ({
<form onSubmit={form.onSubmit(saveSettings(form))}>
<Grid>
<Grid.Col span={6}>
<Checkbox label="Record window data" {...form.getInputProps('RECORD_WINDOW_DATA')} checked={form.values.RECORD_WINDOW_DATA} />
Copy link
Member

Choose a reason for hiding this comment

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

Won't this prevent the checkboxes from being checked appropriately depending on the configuration values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...form.getInputProps('RECORD_WINDOW_DATA') this alone should've marked this checked but yes now that I tested it again without checked= property it is not being marked appropriately.

<Checkbox label="Record window data" {...form.getInputProps('RECORD_WINDOW_DATA')} />
</Grid.Col>
<Grid.Col span={6}>
<Checkbox label="Record active element state" {...form.getInputProps('RECORD_ACTIVE_ELEMENT_STATE')} checked={form.values.RECORD_ACTIVE_ELEMENT_STATE} />
<Checkbox label="Record active element state" {...form.getInputProps('RECORD_ACTIVE_ELEMENT_STATE')} />
</Grid.Col>
<Grid.Col span={6}>
<Checkbox label="Record video" {...form.getInputProps('RECORD_VIDEO')} checked={form.values.RECORD_VIDEO} />
<Checkbox label="Record video" {...form.getInputProps('RECORD_VIDEO')} />
</Grid.Col>
<Grid.Col span={6}>
<Checkbox label="Record images" {...form.getInputProps('RECORD_IMAGES')} checked={form.values.RECORD_IMAGES} />
<Checkbox label="Record images" {...form.getInputProps('RECORD_IMAGES')} />
</Grid.Col>
<Grid.Col span={6}>
<Checkbox label="Record browser (Chrome) events (see <insert link to relevant README section> to install extension)" {...form.getInputProps('RECORD_BROWSER_EVENTS')} checked={form.values.RECORD_BROWSER_EVENTS} />
<Checkbox label="Record browser (Chrome) events (see <insert link to relevant README section> to install extension)" {...form.getInputProps('RECORD_BROWSER_EVENTS')} />
</Grid.Col>
<Grid.Col span={6}>
<TextInput label="Video pixel format" placeholder="Video pixel format" {...form.getInputProps('VIDEO_PIXEL_FORMAT')} />
Expand Down
2 changes: 1 addition & 1 deletion openadapt/app/dashboard/app/settings/scrubbing/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Form = ({
<form onSubmit={form.onSubmit(_onSubmit)}>
<Grid>
<Grid.Col span={6}>
<Checkbox label="Scrubbing Enabled" {...form.getInputProps('SCRUB_ENABLED')} checked={form.values.SCRUB_ENABLED} />
<Checkbox label="Scrubbing Enabled" {...form.getInputProps('SCRUB_ENABLED')} />
</Grid.Col>
<Grid.Col span={6}>
<TextInput label="Scrubbing character" placeholder="Scrubbing character" {...form.getInputProps('SCRUB_CHAR')} />
Expand Down
Loading