-
Notifications
You must be signed in to change notification settings - Fork 914
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
Feat (core): Make theme settings user-specific and user-configurable #5652
Feat (core): Make theme settings user-specific and user-configurable #5652
Conversation
Signed-off-by: Josh Romero <[email protected]>
Signed-off-by: Josh Romero <[email protected]>
Signed-off-by: Josh Romero <[email protected]>
Signed-off-by: Josh Romero <[email protected]>
Signed-off-by: Josh Romero <[email protected]>
1. Add optional `preferBrowserSetting` to UISettings that should be defined client-side 2. Make `theme:darkMode` and `theme:version` prefer browser settings 3. Update UISettings client-side client to check localstorage for settings that prefer browser settings 4. Refactor logos to be responsive to browser-defined theme mode 5. Add a new `startup` script that handles theme/dark mode (injected as blocking script to head) 6. Remove theme/mode-specific logic from injected Styles and Fonts (move logic to `startup` script instead, define all font-faces) 7. Only inject theme values necessary for loading/error screens via `startup` 8. Update branding metadata to pass the correct dark mode Signed-off-by: Josh Romero <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5652 +/- ##
==========================================
- Coverage 67.79% 67.69% -0.10%
==========================================
Files 3413 3414 +1
Lines 66755 66838 +83
Branches 10861 10872 +11
==========================================
- Hits 45254 45247 -7
- Misses 18857 18919 +62
- Partials 2644 2672 +28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Josh Romero <[email protected]>
For the failing tests:
This looks like a flaky test to me - has it failed on other PRs? I don't see how theming changes could make this value round incorrectly. And the CI test group 3 passed on the Windows run.
@AMoo-Miki Can you help me look at this? As far as I can tell the behavior of this PR is actually what we intend/want to happen, since merging #4702. So I think the test case itself is wrong, but it's puzzling that it has been passing in its current state. Just want your confirmation before updating the test case to match the behavior (where we always use the dark mode version of the logo since it's always on a dark background component) |
This is the result of visual diff. It is saying that too much has changed. The solution is to update the base image after validating that the visual changes are desired.
I too believe the test is wrong. The expanded header shows up with a dark background irrespective of the color scheme and because of that, we will always have a dark logo there.
A collapsed header uses the theme's background color which is why the next test passes. |
Ah, right - this is the part I forgot. Let me manually retest to make sure I didn't miss something here. |
Signed-off-by: Josh Romero <[email protected]>
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch-Dashboards/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.x
# Create a new branch
git switch --create backport/backport-5652-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 876224bd9018d5b1dc25f033734676d150f21fc4
# Push it to GitHub
git push --set-upstream origin backport/backport-5652-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.x Then, create a pull request where the |
…and user-configurable (opensearch-project#5652) Backport PR: opensearch-project#5652 From opensearch-project#5652 * feat (core): make theme UI settings client-side 1. Add optional `preferBrowserSetting` to UISettings that should be defined client-side 2. Make `theme:darkMode` and `theme:version` prefer browser settings 3. Update UISettings client-side client to check localstorage for settings that prefer browser settings 4. Refactor logos to be responsive to browser-defined theme mode 5. Add a new `startup` script that handles theme/dark mode (injected as blocking script to head) 6. Remove theme/mode-specific logic from injected Styles and Fonts (move logic to `startup` script instead, define all font-faces) 7. Only inject theme values necessary for loading/error screens via `startup` 8. Update branding metadata to pass the correct dark mode 9. Add a new control for admin Enable user control. This setting is enabled as default. When this setting is disabled, admin can disable any user control and we will have the exact previous behavior. --------- Signed-off-by: Josh Romero <[email protected]>
…and user-configurable (#5652) (#6681) Backport PR: #5652 From #5652 * feat (core): make theme UI settings client-side 1. Add optional `preferBrowserSetting` to UISettings that should be defined client-side 2. Make `theme:darkMode` and `theme:version` prefer browser settings 3. Update UISettings client-side client to check localstorage for settings that prefer browser settings 4. Refactor logos to be responsive to browser-defined theme mode 5. Add a new `startup` script that handles theme/dark mode (injected as blocking script to head) 6. Remove theme/mode-specific logic from injected Styles and Fonts (move logic to `startup` script instead, define all font-faces) 7. Only inject theme values necessary for loading/error screens via `startup` 8. Update branding metadata to pass the correct dark mode 9. Add a new control for admin Enable user control. This setting is enabled as default. When this setting is disabled, admin can disable any user control and we will have the exact previous behavior. --------- Signed-off-by: Josh Romero <[email protected]> Co-authored-by: Josh Romero <[email protected]>
do we have functional test automation for test coverage? |
…pecific and user-configurable (opensearch-project#5652) (opensearch-project#6681)" This reverts commit 815d2bd. Signed-off-by: Kawika Avilla <[email protected]>
…pecific and user-configurable (#5652) (#6681)" (#6736) This reverts commit 815d2bd. Signed-off-by: Kawika Avilla <[email protected]>
…pensearch-project#5652) * feat (core): make theme UI settings client-side 1. Add optional `preferBrowserSetting` to UISettings that should be defined client-side 2. Make `theme:darkMode` and `theme:version` prefer browser settings 3. Update UISettings client-side client to check localstorage for settings that prefer browser settings 4. Refactor logos to be responsive to browser-defined theme mode 5. Add a new `startup` script that handles theme/dark mode (injected as blocking script to head) 6. Remove theme/mode-specific logic from injected Styles and Fonts (move logic to `startup` script instead, define all font-faces) 7. Only inject theme values necessary for loading/error screens via `startup` 8. Update branding metadata to pass the correct dark mode 9. Add a new control for admin Enable user control. This setting is enabled as default. When this setting is disabled, admin can disable any user control and we will have the exact previous behavior. --------- Signed-off-by: Josh Romero <[email protected]>
Description
The purpose of this PR is to make theme settings (dark mode and theme version) settable by device, rather than cluster-wide. This allows different users (or users on different devices) to use different themes and light/dark mode. It also adds a new global nav element for global access to theming controls. These changes, however, can be toggled off in advanced settings if the previous behavior is desired/preferred.
This is an iterative step toward user-specific settings that can be saved/shared across devices, and it should unblock #4454.
The biggest change is that it's no longer possible for any server system or component to know the theme version or dark mode settings, because the source of truth for theme settings resides client-side (stored in localstorage).
Notes for reviewers:
core/server/rendering
to see how server-defined templates and styles are made theme/mode agnosticlegacy/ui/ui_render
. Unlike the existing script. This startup script is required to provide the theming info needed by the loading/error screen prior to starting the react app. Theme info not required by the loading page stays in the existing bootstrap script, which also pulls in some of the conditional theming logic that can no longer be done in the templates.ui_settings
service was updated (both server and client). We define a new propertypreferBrowserSetting
which indicates settings that have a local storage source of truth. Thepublic
client then reads and writes those settings appropriately. Note that this means even editing theme settings from the Advanced Setting page will no longer update the cluster setting - it will also just be considered device-specific.Issues Resolved
Fixes #4462
Screenshot
user-theme-demo.mov
Testing the changes
See video above, but some scenarios to verify:
Enable user control
setting is disabled, all theming behavior should work as previously (advanced settings controls enabled), with no user appearance menu.Enable user control
is enabledui_settings_client
will get the theme values that represent the state of those settings, not necessarily the settings value (for backwards compatibility). E.g. if user settings are enabled and set to "Use browser settings", consumers callinguiClient.get('theme:darkMode')
should get backtrue
if that was the browser setting at page load/application start.ui_settings_client
will always get server/saved object default values, which may not reflect app stateCheck List
yarn test:jest
yarn test:jest_integration