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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

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 the default index UI setting first if deleting an index pattern in a specific workspace.
  2. Remove index patterns first when uninstalling sample data.
  3. Disable the behavior of updating the default index pattern UI setting 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

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.

Project coverage is 60.90%. Comparing base (1c744d6) to head (f537c6f).

Files with missing lines Patch % Lines
...me/server/services/sample_data/routes/uninstall.ts 83.33% 1 Missing and 1 partial ⚠️
...ed_objects/workspace_ui_settings_client_wrapper.ts 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8842      +/-   ##
==========================================
+ Coverage   60.87%   60.90%   +0.02%     
==========================================
  Files        3802     3802              
  Lines       91074    91105      +31     
  Branches    14376    14384       +8     
==========================================
+ Hits        55445    55487      +42     
+ Misses      32086    32074      -12     
- Partials     3543     3544       +1     
Flag Coverage Δ
Linux_1 29.03% <94.11%> (+0.01%) ⬆️
Linux_2 56.38% <ø> (ø)
Linux_3 37.90% <ø> (ø)
Linux_4 29.04% <87.50%> (+0.04%) ⬆️
Windows_1 29.05% <94.11%> (+0.01%) ⬆️
Windows_2 56.34% <ø> (ø)
Windows_3 37.90% <ø> (ø)
Windows_4 29.04% <87.50%> (+0.04%) ⬆️

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 ready for review November 22, 2024 06:28
@@ -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
Member

Choose a reason for hiding this comment

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

Do we still need to check the feature flag? I am thinking line 51 will throw permission error if user happens to delete the default index pattern.

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?

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?

Comment on lines 66 to 69
if (
!isWorkspaceEnabled() &&
!uiSettings.isDefault('defaultIndex') &&
uiSettings.get('defaultIndex') === sampleDataDefaultIndex
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 comment here, workspace_ui_settings_client_wrapper will handle default index pattern reset?

Comment on lines 175 to 180
const defaultIndexPatternWorkspaces = workspaceObjects.saved_objects.filter(
({ attributes }) => attributes?.uiSettings?.[DEFAULT_INDEX_PATTERN_UI_SETTINGS_ID] === id
);
try {
await this.getWorkspaceTypeEnabledClient(wrapperOptions.request).bulkUpdate(
defaultIndexPatternWorkspaces.map((savedObject) => ({
Copy link
Collaborator

@Hailong-am Hailong-am Nov 29, 2024

Choose a reason for hiding this comment

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

can we check defaultIndexPatternWorkspaces is not empty first?

also will bulkUpdate an empty list throw errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bulkUpdate won't throw errors for empty list. But you're right, we can add a empty check logic for it.

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.

3 participants