feat(preferences): update checkbox schema and UI handling

This commit updates the preference handling to align with the documentation for preferences. The `PreferenceSchema` now mandates a `label` property for all preferences of type `checkbox`. In the `SettingsView`, the rendering logic has been adjusted to use the `title` as an optional section header, enabling the grouping of related checkboxes. The `label` is now used for the text directly next to the checkbox input.
This commit is contained in:
ByteAtATime 2025-06-25 21:28:10 -07:00
parent 1bdb0f534e
commit e9dbcf3a57
No known key found for this signature in database
2 changed files with 97 additions and 74 deletions

View file

@ -117,11 +117,10 @@ const LogMessageSchema = z.object({
export const SidecarMessageSchema = z.union([BatchUpdateSchema, CommandSchema, LogMessageSchema]);
export type SidecarMessage = z.infer<typeof SidecarMessageSchema>;
export const PreferenceSchema = z.object({
const BasePreferenceSchema = z.object({
name: z.string(),
title: z.string().optional(),
description: z.string().optional(),
type: z.enum(['textfield', 'password', 'checkbox', 'dropdown', 'appPicker', 'file', 'directory']),
required: z.boolean().optional(),
default: z.union([z.string(), z.boolean()]).optional(),
data: z
@ -133,6 +132,16 @@ export const PreferenceSchema = z.object({
)
.optional()
});
export const PreferenceSchema = z.discriminatedUnion('type', [
BasePreferenceSchema.extend({
type: z.literal('checkbox'),
label: z.string()
}),
BasePreferenceSchema.extend({
type: z.enum(['textfield', 'password', 'dropdown', 'appPicker', 'file', 'directory'])
})
]);
export type Preference = z.infer<typeof PreferenceSchema>;
export const PluginInfoSchema = z.object({