From 17fe7b1092a7a9aec9ad15cb18dbca9849d4d7ae Mon Sep 17 00:00:00 2001 From: KennyG Date: Fri, 1 May 2026 09:39:33 -0400 Subject: [PATCH] Refactor clear behavior in settings. - Updated GraphQL schema to change `defaultPerformerGender` type to `GenderEnum` and added a new field `clearDefaultPerformerGender` for clearing the setting. - Modified `applyDefaultPerformerGenderInput` function to accept the new input structure, allowing for clearer handling of gender updates and clearing. - Enhanced the `SettingsInterfacePanel` to implement the new logic for saving default performer gender, improving user experience when setting or clearing the default gender. These changes streamline the configuration process and improve the clarity of gender handling in the application. --- graphql/schema/types/config.graphql | 7 ++--- internal/api/resolver_mutation_configure.go | 27 +++++++++---------- .../SettingsInterfacePanel.tsx | 16 ++++++++++- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/graphql/schema/types/config.graphql b/graphql/schema/types/config.graphql index 18ee52b8b..687dcd8b4 100644 --- a/graphql/schema/types/config.graphql +++ b/graphql/schema/types/config.graphql @@ -420,9 +420,10 @@ input ConfigInterfaceInput { "When true, disables all customizations (plugins, CSS, JavaScript, locales) for troubleshooting" disableCustomizations: Boolean - """Default gender to apply when creating a performer without explicit gender. - Send an empty string to clear the setting.""" - defaultPerformerGender: String + "Default gender to apply when creating a performer without explicit gender" + defaultPerformerGender: GenderEnum + "Clear the stored default performer gender" + clearDefaultPerformerGender: Boolean "Interface language" language: String diff --git a/internal/api/resolver_mutation_configure.go b/internal/api/resolver_mutation_configure.go index c679b26fd..d677ec262 100644 --- a/internal/api/resolver_mutation_configure.go +++ b/internal/api/resolver_mutation_configure.go @@ -9,7 +9,6 @@ import ( "path/filepath" "regexp" "strconv" - "strings" "github.com/stashapp/stash/internal/manager" "github.com/stashapp/stash/internal/manager/config" @@ -64,22 +63,22 @@ func (r *mutationResolver) setConfigString(key string, value *string) { } // applyDefaultPerformerGenderInput updates or clears DefaultPerformerGender. -// Omit the field entirely (nil) to leave the stored value unchanged; send "" to clear it. -func (r *mutationResolver) applyDefaultPerformerGenderInput(value *string) error { +// Omit both fields to leave the stored value unchanged. +func (r *mutationResolver) applyDefaultPerformerGenderInput(value *models.GenderEnum, clear *bool) error { + if clear != nil && *clear { + if value != nil { + return fmt.Errorf("cannot set and clear default performer gender in the same request") + } + config.GetInstance().SetString(config.DefaultPerformerGender, "") + return nil + } if value == nil { return nil } - c := config.GetInstance() - s := strings.TrimSpace(*value) - if s == "" { - c.SetString(config.DefaultPerformerGender, "") - return nil + if !value.IsValid() { + return fmt.Errorf("invalid default performer gender %q", *value) } - g := models.GenderEnum(s) - if !g.IsValid() { - return fmt.Errorf("invalid default performer gender %q", s) - } - c.SetString(config.DefaultPerformerGender, s) + config.GetInstance().SetString(config.DefaultPerformerGender, value.String()) return nil } @@ -549,7 +548,7 @@ func (r *mutationResolver) ConfigureInterface(ctx context.Context, input ConfigI r.setConfigBool(config.CustomLocalesEnabled, input.CustomLocalesEnabled) r.setConfigBool(config.DisableCustomizations, input.DisableCustomizations) - if err := r.applyDefaultPerformerGenderInput(input.DefaultPerformerGender); err != nil { + if err := r.applyDefaultPerformerGenderInput(input.DefaultPerformerGender, input.ClearDefaultPerformerGender); err != nil { return makeConfigInterfaceResult(), err } diff --git a/ui/v2.5/src/components/Settings/SettingsInterfacePanel/SettingsInterfacePanel.tsx b/ui/v2.5/src/components/Settings/SettingsInterfacePanel/SettingsInterfacePanel.tsx index 0c3ff26cb..dc8613c6c 100644 --- a/ui/v2.5/src/components/Settings/SettingsInterfacePanel/SettingsInterfacePanel.tsx +++ b/ui/v2.5/src/components/Settings/SettingsInterfacePanel/SettingsInterfacePanel.tsx @@ -152,6 +152,20 @@ export const SettingsInterfacePanel: React.FC = PatchComponent( }); } + function saveDefaultPerformerGender(v: string) { + saveInterface( + v === "" + ? { + clearDefaultPerformerGender: true, + defaultPerformerGender: null, + } + : { + clearDefaultPerformerGender: false, + defaultPerformerGender: v as GQL.GenderEnum, + } + ); + } + function validateLocaleString(v: string) { if (!v) return; try { @@ -531,7 +545,7 @@ export const SettingsInterfacePanel: React.FC = PatchComponent( headingID="config.ui.performer_list.options.default_gender.heading" subHeadingID="config.ui.performer_list.options.default_gender.description" value={iface.defaultPerformerGender ?? ""} - onChange={(v) => saveInterface({ defaultPerformerGender: v })} + onChange={(v) => saveDefaultPerformerGender(v)} > {genderList.map((gender) => (