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.
This commit is contained in:
KennyG 2026-05-01 09:39:33 -04:00
parent 849febc8d3
commit 17fe7b1092
3 changed files with 32 additions and 18 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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)}
>
<option value="">{intl.formatMessage({ id: "none" })}</option>
{genderList.map((gender) => (