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

[Workspace]Fix error toasts in sample data page #8842

Conversation

wanglam
Copy link
Contributor

@wanglam wanglam commented Nov 11, 2024

Description

This PR addresses the issue of error toasts appearing on the sample data page when installing or uninstalling sample data. The root cause was that the user did not have permission to update UI settings at the workspace level. The changes in this PR include:

  1. Remove saved objects first when uninstalling sample data.
  2. Disable the behavior of updating the default index pattern UI setting for non workspace admin when installing or uninstalling sample data inside a workspace.

Screenshot

No UI Changes

Testing the changes

  1. Clone the branch and run yarn osd bootstrap --single-version loose.
  2. Add the following configurations to config/opensearch_dashboards.yml:
    savedObjects.permission.enabled: true
    workspace.enabled: true
    uiSettings:
      overrides:
        'home:useNewHomePage': true
    
  3. Run yarn start --no-base-path.
  4. Log in with the admin user and create a new workspace named "test1".
  5. Visit the sample data page of the "test1" workspace.
  6. Click the "Add data" and "Remove" buttons on the sample data cards to ensure you can install and uninstall sample data without any issues.
  7. Create a new user with the "admin" backend_role in the "Internal users" page.
  8. Assign the "Read and write" access level to the new user inside the "test1" workspace.
  9. Open an incognito window and log in with the new user.
  10. Visit the sample data page of the "test1" workspace and click the "Add data" button. Verify that no error toasts appear.
  11. Switch back to the admin user tab, visit the same workspace, and set the "flights" sample data as the default index pattern in the index patterns page.
  12. Switch to the new user tab and click the "Remove" button on the "flights" sample data card. Verify that an error toast appears, similar to the provided screenshot.
image 13. Click the "Remove" buttons on other sample data cards and ensure no error toasts appear. 14. Switch to the admin user tab and set the new user as an "Admin" of the "test1" workspace. 15. Switch to the new user tab and click the "Remove" button on the "flights" sample data card. Verify that no error toasts appear. 16. Test with the workspace disabled (for regression testing): - Remove the newly added configurations. - Visit the home page and click the "Add sample data" button. - Click the "Add data" buttons. Sample data should be installed without error toasts. - Click the "Remove" buttons. Sample data should be uninstalled without error toasts.

Changelog

  • fix: [Workspace]Fix error toasts in sample data page

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

opensearch-changeset-bot bot added a commit to wanglam/OpenSearch-Dashboards that referenced this pull request Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.85%. Comparing base (fe616e7) to head (5a1fc83).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...me/server/services/sample_data/routes/uninstall.ts 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8842      +/-   ##
==========================================
+ Coverage   60.84%   60.85%   +0.01%     
==========================================
  Files        3808     3808              
  Lines       91193    91199       +6     
  Branches    14408    14409       +1     
==========================================
+ Hits        55485    55503      +18     
+ Misses      32165    32153      -12     
  Partials     3543     3543              
Flag Coverage Δ
Linux_1 29.03% <ø> (ø)
Linux_2 56.38% <ø> (ø)
Linux_3 37.90% <ø> (ø)
Linux_4 29.02% <85.71%> (+0.02%) ⬆️
Windows_1 29.04% <ø> (ø)
Windows_2 56.34% <ø> (ø)
Windows_3 37.90% <ø> (ø)
Windows_4 29.02% <85.71%> (+0.02%) ⬆️

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.

SuZhou-Joe
SuZhou-Joe previously approved these changes Nov 12, 2024
@wanglam wanglam marked this pull request as draft November 21, 2024 06:03
@wanglam wanglam marked this pull request as ready for review November 22, 2024 06:28
@wanglam wanglam requested a review from SuZhou-Joe November 22, 2024 10:05
@@ -41,11 +41,16 @@ export async function listSampleDataSets(dataSourceId) {
return await getServices().http.get(sampleDataUrl, { query });
}

const isWorkspaceEnabled = () => {
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking if it is workspaceEnabled or permissionControlEnabled.

@@ -144,6 +148,59 @@ export class WorkspaceUiSettingsClientWrapper {
return wrapperOptions.client.update(type, id, attributes, options);
};

const deleteUiSettingsWithWorkspace = async (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const deleteUiSettingsWithWorkspace = async (
const deleteWithDefaultIndexPatternCheck = async (

export async function installSampleDataSet(id, sampleDataDefaultIndex, dataSourceId) {
const query = buildQuery(dataSourceId);
await getServices().http.post(`${sampleDataUrl}/${id}`, { query });

if (getServices().uiSettings.isDefault('defaultIndex')) {
if (!isWorkspaceEnabled() && getServices().uiSettings.isDefault('defaultIndex')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add a unit test to cover this condition check?

src/plugins/home/public/application/sample_data_client.js Outdated Show resolved Hide resolved
SuZhou-Joe
SuZhou-Joe previously approved these changes Dec 2, 2024
@wanglam wanglam marked this pull request as draft December 4, 2024 03:44
@wanglam wanglam force-pushed the fix-default-index-setting-for-non-workspace-admin branch from 02ddf54 to c1b9545 Compare December 4, 2024 03:48
@wanglam wanglam marked this pull request as ready for review December 4, 2024 08:07
@Hailong-am Hailong-am merged commit af429b6 into opensearch-project:main Dec 6, 2024
69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 6, 2024
* Set default index pattern when workspace disabled

Signed-off-by: Lin Wang <[email protected]>

* Move saved objects first to avoid partial deleted

Signed-off-by: Lin Wang <[email protected]>

* Skip ui setting update for non workspace admin

Signed-off-by: Lin Wang <[email protected]>

* Add UT for sample_data_client

Signed-off-by: Lin Wang <[email protected]>

* Changeset file for PR #8842 created/updated

---------

Signed-off-by: Lin Wang <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit af429b6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ruanyl pushed a commit that referenced this pull request Dec 6, 2024
* Set default index pattern when workspace disabled



* Move saved objects first to avoid partial deleted



* Skip ui setting update for non workspace admin



* Add UT for sample_data_client



* Changeset file for PR #8842 created/updated

---------



(cherry picked from commit af429b6)

Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
silva-qa pushed a commit to silva-qa/OpenSearch-Dashboards that referenced this pull request Dec 12, 2024
)

* Set default index pattern when workspace disabled

Signed-off-by: Lin Wang <[email protected]>

* Move saved objects first to avoid partial deleted

Signed-off-by: Lin Wang <[email protected]>

* Skip ui setting update for non workspace admin

Signed-off-by: Lin Wang <[email protected]>

* Add UT for sample_data_client

Signed-off-by: Lin Wang <[email protected]>

* Changeset file for PR opensearch-project#8842 created/updated

---------

Signed-off-by: Lin Wang <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants