diff --git a/master/internal/config/config_test.go b/master/internal/config/config_test.go index edb54e7caac..9b50dd3235d 100644 --- a/master/internal/config/config_test.go +++ b/master/internal/config/config_test.go @@ -891,6 +891,12 @@ resource_manager: } func TestPickVariation(t *testing.T) { + userConfig := MediaAssetVariations{ + LightHorizontal: "light-horizontal", + LightVeritical: "light-vertical", + DarkHorizontal: "dark-horizontal", + DarkVeritical: "dark-vertical", + } tests := []struct { name string variations MediaAssetVariations @@ -899,136 +905,46 @@ func TestPickVariation(t *testing.T) { expected string }{ { - name: "Light Horizontal prioritized", - variations: MediaAssetVariations{ - LightHorizontal: "light-horizontal", - LightVeritical: "light-vertical", - DarkHorizontal: "dark-horizontal", - DarkVeritical: "dark-vertical", - }, + name: "Light Horizontal prioritized", + variations: userConfig, mode: "", orientation: "", expected: "light-horizontal", }, { - name: "Light Vertical when Light Horizontal is empty", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "light-vertical", - DarkHorizontal: "dark-horizontal", - DarkVeritical: "dark-vertical", - }, + name: "Light Horizontal prioritized", + variations: userConfig, mode: "", - orientation: "vertical", - expected: "light-vertical", - }, - { - name: "Dark Horizontal when mode is dark", - variations: MediaAssetVariations{ - LightHorizontal: "light-horizontal", - LightVeritical: "light-vertical", - DarkHorizontal: "dark-horizontal", - DarkVeritical: "dark-vertical", - }, - mode: "dark", - orientation: "", - expected: "dark-horizontal", - }, - { - name: "Dark Vertical when mode is dark and orientation is vertical", - variations: MediaAssetVariations{ - LightHorizontal: "light-horizontal", - LightVeritical: "light-vertical", - DarkHorizontal: "dark-horizontal", - DarkVeritical: "dark-vertical", - }, - mode: "dark", - orientation: "vertical", - expected: "dark-vertical", - }, - { - name: "Fallback to Light Horizontal if no matches", - variations: MediaAssetVariations{ - LightHorizontal: "light-horizontal", - LightVeritical: "", - DarkHorizontal: "", - DarkVeritical: "", - }, - mode: "dark", - orientation: "vertical", + orientation: "horizontal", expected: "light-horizontal", }, { - name: "Fallback to Light Horizontal if no matches", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "light-vertical", - DarkHorizontal: "", - DarkVeritical: "", - }, + name: "Light Horizontal prioritized", + variations: userConfig, mode: "", - orientation: "", + orientation: "vertical", expected: "light-vertical", }, { - name: "Fallback to Light Horizontal if no matches", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "light-vertical", - DarkHorizontal: "", - DarkVeritical: "", - }, + name: "Light Horizontal prioritized", + variations: userConfig, mode: "light", orientation: "", - expected: "light-vertical", + expected: "light-horizontal", }, { - name: "Fallback to Light Horizontal if no matches", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "light-vertical", - DarkHorizontal: "", - DarkVeritical: "", - }, + name: "Light Horizontal prioritized", + variations: userConfig, mode: "dark", orientation: "", - expected: "light-vertical", + expected: "dark-horizontal", }, { - name: "Fallback to Light Horizontal if no matches", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "light-vertical", - DarkHorizontal: "", - DarkVeritical: "", - }, - mode: "light", + name: "Light Horizontal prioritized", + variations: userConfig, + mode: "dark", orientation: "vertical", - expected: "light-vertical", - }, - { - name: "Fallback to Light Horizontal if no matches", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "light-vertical", - DarkHorizontal: "", - DarkVeritical: "", - }, - mode: "light", - orientation: "", - expected: "light-vertical", - }, - { - name: "Empty variations fallback to empty string", - variations: MediaAssetVariations{ - LightHorizontal: "", - LightVeritical: "", - DarkHorizontal: "", - DarkVeritical: "", - }, - mode: "", - orientation: "", - expected: "", + expected: "dark-vertical", }, } diff --git a/master/internal/config/ui_config.go b/master/internal/config/ui_config.go index dbec3d8f4d9..b297bb63e19 100644 --- a/master/internal/config/ui_config.go +++ b/master/internal/config/ui_config.go @@ -22,50 +22,36 @@ func (m MediaAssetVariations) PickVariation(mode, orientation string) string { orientationHorizontal = "horizontal" orientationVertical = "vertical" ) - if mode == "" || mode == "light" { - if orientation == "" || orientation == orientationHorizontal { - if m.LightHorizontal != "" { - return m.LightHorizontal - } + switch mode { + case "dark": + switch orientation { + case orientationVertical: + return m.DarkVeritical + default: + return m.DarkHorizontal } - if orientation == "" || orientation == orientationVertical { - if m.LightVeritical != "" { - return m.LightVeritical - } - if m.LightHorizontal != "" { - return m.LightHorizontal - } + default: + switch orientation { + case orientationVertical: + return m.LightVeritical + default: + return m.LightHorizontal } } - - if mode == "dark" { - if orientation == "" || orientation == orientationHorizontal { - if m.DarkHorizontal != "" { - return m.DarkHorizontal - } - } - if orientation == "" || orientation == orientationVertical { - if m.DarkVeritical != "" { - return m.DarkVeritical - } - if m.DarkHorizontal != "" { - return m.DarkHorizontal - } - } - } - - return m.LightHorizontal } // UICustomizationConfig holds the configuration for customizing the UI. type UICustomizationConfig struct { // LogoPath is the path to variation of custom logo to use in the web UI. - LogoPath MediaAssetVariations `json:"logo_path"` + LogoPath *MediaAssetVariations `json:"logo_path"` } // Validate checks if the paths in UICustomizationConfig are valid filesystem paths and reachable. func (u UICustomizationConfig) Validate() []error { var errs []error + if u.LogoPath == nil { + return errs + } paths := map[string]string{ "LightHorizontal": u.LogoPath.LightHorizontal, @@ -76,6 +62,7 @@ func (u UICustomizationConfig) Validate() []error { for name, path := range paths { if path == "" { + errs = append(errs, errors.New(name+" path is not set")) continue } license.RequireLicense("UI Customization") @@ -95,7 +82,5 @@ func (u UICustomizationConfig) Validate() []error { // HasCustomLogo returns whether the UI customization has a custom logo. func (u UICustomizationConfig) HasCustomLogo() bool { - // If one exists, we're good - return u.LogoPath.LightHorizontal != "" || u.LogoPath.LightVeritical != "" || - u.LogoPath.DarkHorizontal != "" || u.LogoPath.DarkVeritical != "" + return u.LogoPath != nil }