Skip to content
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

Fix/UI settings overrides #6730

Closed

Conversation

joshuarrrr
Copy link
Member

Description

There are a couple different fixes here, which can be viewed separately by looking at the separate commits. But the root cause of #6704 was primarily the fact that the implementation of getOverridesOrDefault assumed the wrong object shape for the overrides property, when it tried to access a value property instead of just the value itself. Note that the existing unit test also had this same error.

Because the ui_render_mixin is an old legacy .js file, there's not much help from typescript, so I also added some enforcement to make sure we're always sending boolean values to the template.

Additionally, I realized that the validation for the theme:version setting was not correct, and needed updating to match our current themes.

Finally, as requested, I updated the new user theme controls to be deactivated by default.

No changelog necessary, as the previous PR this fixes has not yet been released.

Future work

@AMoo-Miki @manasvinibs - The past discussion and this TODO comment seem to indicate that we don't actually want to maintain support for these overrides long term. But even if we do, I don't think the schema definition for overrides makes much sense:

overrides: schema.object({}, { unknowns: 'allow' }),

We probably want users to be aware of if they specify invalid overrides and not silently ignore (which is what was happening with an incorrectly set value in @BionIT 's configuration.

Issues Resolved

Fixes #6704

Screenshot

Testing the changes

The linked issue only surfaced when deploying https://future.playground.opensearch.org/ , and only when not yet authenticated, because the configuration file specified overrides such as:

uiSettings:
  overrides:
    'theme:darkMode': false

To validate these fixes, test with authentication enabled, a non-authenticated user, and theme UI Settings overrides.

Changelog

  • skip

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented May 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.43%. Comparing base (48144c8) to head (13e3e05).
Report is 230 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6730   +/-   ##
=======================================
  Coverage   67.43%   67.43%           
=======================================
  Files        3443     3443           
  Lines       67806    67806           
  Branches    11031    11031           
=======================================
  Hits        45727    45727           
  Misses      19413    19413           
  Partials     2666     2666           
Flag Coverage Δ
Linux_1 33.09% <0.00%> (ø)
Linux_2 55.06% <100.00%> (ø)
Linux_3 45.21% <0.00%> (+0.01%) ⬆️
Linux_4 34.88% <0.00%> (ø)
Windows_1 33.11% <0.00%> (ø)
Windows_2 55.03% <100.00%> (ø)
Windows_3 45.21% <0.00%> (ø)
Windows_4 34.88% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes Josh!

@ashwin-pc
Copy link
Member

@joshuarrrr Dont we want a changelog entry for this change?

@joshuarrrr
Copy link
Member Author

@joshuarrrr Dont we want a changelog entry for this change?

Well... originally I was thinking no, in terms of fixing the new theme controls, which haven't yet been released. But now I'm remembering that this was actually a latent bug in the UI settings client, so I'll add a changelog entry.

Copy link
Collaborator

@AMoo-Miki AMoo-Miki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failures indicate substantial visual diff. Putting a hold so we don't accidentally merge before examining the diff.

@ananzh ananzh removed the v2.15.0 label Jun 5, 2024
@ananzh
Copy link
Member

ananzh commented Jun 5, 2024

Remove 2.15 label since the #5652 has not yet been released in 2.14.

@ananzh ananzh added the v2.15.0 label Jun 5, 2024
@ananzh
Copy link
Member

ananzh commented Jun 6, 2024

ciGroup9 Failure Research

Currently there are 9 failed tests. From debug, I found there are two issues.

Issue 1: default dark mode

From debug I found the change of default mode is caused by !! order. For await !!uiSettings.get('theme:darkMode’), the !! operator is applied before await, causing the following steps:

  1. uiSettings.get('theme:darkMode') returns a Promise.
  2. !! tries to coerce the Promise object to a boolean.
  3. Since any non-null object in JavaScript is truthy, !! converts the Promise to true.
  4. await then resolves the true value, but this doesn't make sense in the usual await context.

So if we move !! before await !!(await uiSettings.get('theme:darkMode'));, the operations are correctly ordered:

  1. await uiSettings.get('theme:darkMode') resolves the Promise and gets the actual boolean value (false in your case).
  2. !! then converts this resolved boolean value to true or false.

But why do we need !!? Do we see any cases that we will receive truthy or falsy value? If not, maybe go back to await uiSettings.get('theme:darkMode')?

Issue 2: can't find advancedSetting-saveButton

after resolve the first one, there are 4 failed tests left, all due to

Error: retry.try timeout: TimeoutError: Waiting for element to be located By(css selector, [data-test-subj="advancedSetting-saveButton"])
         │ Wait timed out after 10024ms

This is because when we set up like below:

await PageObjects.settings.toggleAdvancedSettingCheckbox('theme:enableUserControl');
await PageObjects.settings.toggleAdvancedSettingCheckbox('theme:darkMode');

The enableUserControl will block admin to set up darkMode.

Screenshot 2024-06-06 at 8 47 31 AM

This is a bit wired cuz this means admin now can't control admin's own mode. If this is expected, then we could test

it('admin's customized dark mode logo for opensearch overview header is applied', async () => {
        await PageObjects.common.navigateToApp('management/opensearch-dashboards/settings');
        await PageObjects.settings.toggleAdvancedSettingCheckbox('theme:darkMode');
        await PageObjects.common.navigateToApp('opensearch_dashboards_overview');
        await testSubjects.existOrFail('osdOverviewPageHeaderLogo');
        const actualLabel = await testSubjects.getAttribute(
          'osdOverviewPageHeaderLogo',
          'data-test-logo'
        );
        expect(actualLabel.toUpperCase()).to.equal(expectedMarkLogoDarkMode.toUpperCase());
      });

it('if enable user control, admin's customized dark mode logo for opensearch overview header is not applied', async () => {
        await PageObjects.common.navigateToApp('management/opensearch-dashboards/settings');
        await PageObjects.settings.toggleAdvancedSettingCheckbox('theme:enableUserControl');
        const button = await testSubjects.find('advancedSetting-editField-theme:darkMode');
        const isDisabled = await button.getAttribute('disabled') !== null;
        expect(isDisabled).equal(true);
        await PageObjects.common.navigateToApp('opensearch_dashboards_overview');
        await testSubjects.existOrFail('osdOverviewPageHeaderLogo');
        const actualLabel = await testSubjects.getAttribute(
          'osdOverviewPageHeaderLogo',
          'data-test-logo'
        );
        expect(actualLabel.toUpperCase()).to.equal(expectedMarkLogo.toUpperCase());
      });

@ananzh
Copy link
Member

ananzh commented Jun 6, 2024

Resolving ciGroup9 to run correct light mode will automatically resolve ciGroup3.

@ananzh ananzh added v2.16.0 and removed v2.15.0 labels Jun 6, 2024
@AMoo-Miki
Copy link
Collaborator

After talking to Ashwin, I would also like to understand why the original override mechanism is not working as expected because that bit is ancient code and we might need to make other changes accordingly.

@ananzh ananzh removed the v2.16.0 label Jul 25, 2024
ananzh pushed a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Aug 20, 2024
This PR is originally from opensearch-project#6730.
We simply update the tests.

Signed-off-by: Josh Romero <[email protected]>
@ananzh
Copy link
Member

ananzh commented Aug 22, 2024

Close this as tests are fixed in #7776

@ananzh ananzh closed this Aug 22, 2024
ananzh added a commit that referenced this pull request Aug 22, 2024
* Fix/UI settings overrides

This PR is originally from #6730.
We simply update the tests.

Signed-off-by: Josh Romero <[email protected]>

* fix more tests

Signed-off-by: Anan Zhuang <[email protected]>

---------

Signed-off-by: Josh Romero <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x distinguished-contributor Skip-Changelog PRs that are too trivial to warrant a changelog or release notes entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Startup fails with theme overrides
6 participants