-
Notifications
You must be signed in to change notification settings - Fork 917
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
[BUG] Allow user Theme Selection retain theme selection #7787
base: main
Are you sure you want to change the base?
Conversation
❌ Empty Changelog SectionThe Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section. |
@@ -62,7 +63,8 @@ export class UiSettingsClient implements IUiSettingsClient { | |||
this.cache['theme:enableUserControl']?.userValue ?? | |||
this.cache['theme:enableUserControl']?.value | |||
) { | |||
this.cache = defaultsDeep(this.cache, this.getBrowserStoredSettings()); | |||
this.browserStoredSettings = this.getBrowserStoredSettings(); | |||
this.cache = defaultsDeep({}, this.defaults, this.cache, this.browserStoredSettings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't the order of precedence left to right, so this doesn't really change any behavior, right?
it feels like we can just remove this if we're not utilizing it because there shouldn't be a case where there's a browser setting but not an advanced setting, right? Or if an admin doesn't explicitly save something, is there no userValue from advanced settings?
} | ||
|
||
const type = this.cache[key].type; | ||
const userValue = this.cache[key].userValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wouldn't name variable userValue as its really the value from advanced settings, not related to the user
const defaultValue = defaultOverride !== undefined ? defaultOverride : this.cache[key].value; | ||
|
||
let value; | ||
if (this.cache['theme:enableUserControl']?.userValue ?? this.cache['theme:enableUserControl']?.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
know this is a wip, but seems like this should be consumer logic
value = browserValue ?? userValue ?? defaultValue; | ||
} else { | ||
value = userValue ?? defaultValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can null be a valid value? if so, don't think we should use ??
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7787 +/- ##
==========================================
+ Coverage 63.80% 63.83% +0.03%
==========================================
Files 3656 3659 +3
Lines 81205 81326 +121
Branches 12950 12987 +37
==========================================
+ Hits 51809 51915 +106
- Misses 26215 26225 +10
- Partials 3181 3186 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
102d371
to
67cadf3
Compare
❌ Empty Changelog SectionThe Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section. |
Issue Resolve: opensearch-project#7689 Signed-off-by: Anan Zhuang <[email protected]>
59183f0
to
d2a5fc8
Compare
/** | ||
* Gets the value for a specific uiSetting, considering browser-stored settings and advanced settings. | ||
* This method returns an object containing the resolved value and individual setting values. | ||
* | ||
* @param key - The key of the uiSetting to retrieve | ||
* @param defaultOverride - An optional default value to use if the setting is not declared | ||
* @returns An object containing the resolved value and additional setting information | ||
* @throws Error if the setting is not declared and no defaultOverride is provided | ||
*/ | ||
getWithBrowserSettings<T = any>( | ||
key: string, | ||
defaultOverride?: T | ||
): { | ||
advancedSettingValue: T | undefined; | ||
browserValue: T | undefined; | ||
defaultValue: T; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callout: I think this is fine for now to avoid increasing scope - i think in the future, we should consider making get() aware of all contexts, and having experiences like advanced settings explicitly call another method or a variant to exclude browser settings in resolution
two suggestions:
- should we call this getValues() or something more generic where this can provide all levels of values for this setting (not just browser as it also returns default value today)?
- should this include a resolvedValue or a value that handles what the current active value is so consumers don't have to resolve this themselves?
const resolveValue = (val: any): T => this.resolveValue(val, type); | ||
|
||
const resolvedAdvancedValue = | ||
advancedSettingValue !== undefined ? resolveValue(advancedSettingValue) : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could create a helper function to handle this undefined case and inline these with return
|
||
const oldVal = declared ? this.cache[key].userValue : undefined; | ||
const userControl = | ||
this.cache['theme:enableUserControl']?.userValue ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui_settings_client shouldn't be aware of a theme specific setting right?
also, could other settings be null? if so, this probably should be checking that these aren't defined.
const currentDarkMode = enableUserControl | ||
? result.browserValue ?? result.advancedSettingValue ?? result.defaultValue | ||
: result.advancedSettingValue ?? result.defaultValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think consumers should be resolving values - think this should come from uisettingsclient
Description
Add
browserStoredSettings
andgetWithBrowserSettings
method to allow the retrieval and resolution of values from the cache and browser settings separately. When user control is enabled, we update the browserStoredSettings without interrupting the cache (advance settings user values).Issues Resolved
#7689
Screenshot
2024-08-21_10-09-24.mp4
Changelog
Check List
yarn test:jest
yarn test:jest_integration