-
Notifications
You must be signed in to change notification settings - Fork 898
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
base: main
Are you sure you want to change the base?
[Workspace]Fix error toasts in sample data page #8842
Conversation
Signed-off-by: Lin Wang <[email protected]>
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This reverts commit b92b333. Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
@@ -41,11 +41,16 @@ export async function listSampleDataSets(dataSourceId) { | |||
return await getServices().http.get(sampleDataUrl, { query }); | |||
} | |||
|
|||
const isWorkspaceEnabled = () => { |
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 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 ( |
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.
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')) { |
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.
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.
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 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')) { |
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 we add a unit test to cover this condition check?
if ( | ||
!isWorkspaceEnabled() && | ||
!uiSettings.isDefault('defaultIndex') && | ||
uiSettings.get('defaultIndex') === sampleDataDefaultIndex |
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 we add a comment here, workspace_ui_settings_client_wrapper will handle default index pattern reset?
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) => ({ |
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 we check defaultIndexPatternWorkspaces is not empty first?
also will bulkUpdate an empty list throw errors?
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.
The bulkUpdate
won't throw errors for empty list. But you're right, we can add a empty check logic for it.
Signed-off-by: Lin Wang <[email protected]>
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:
Screenshot
No UI Changes
Testing the changes
yarn osd bootstrap --single-version loose
.config/opensearch_dashboards.yml
:yarn start --no-base-path
.Changelog
Check List
yarn test:jest
yarn test:jest_integration