Skip to content

Commit

Permalink
[BUG] fix default data source bug (#6908) (#6912)
Browse files Browse the repository at this point in the history
* fix default data source bug



* Changeset file for PR #6908 created/updated

---------



(cherry picked from commit b2ff7de)

Signed-off-by: Lu Yu <[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>
  • Loading branch information
3 people committed Jun 5, 2024
1 parent e128383 commit 987208c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/6908.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix not setting the default data source when creating data source bug ([#6908](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6908))
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ describe('DataSourceManagement: Utils.ts', () => {
await handleSetDefaultDatasource(savedObjects.client, uiSettings);
expect(uiSettings.set).toHaveBeenCalled();
});
test('should set default datasource when returned default datasource id is empty string', async () => {
mockUiSettingsCalls(uiSettings, 'get', '');
mockResponseForSavedObjectsCalls(savedObjects.client, 'find', getDataSourcesResponse);
await handleSetDefaultDatasource(savedObjects.client, uiSettings);
expect(uiSettings.set).toHaveBeenCalled();
});
test('should not set default datasource when it has default datasouce', async () => {
mockUiSettingsCalls(uiSettings, 'get', 'test');
mockResponseForSavedObjectsCalls(savedObjects.client, 'find', getDataSourcesResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function handleSetDefaultDatasource(
savedObjectsClient: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
if (getDefaultDataSourceId(uiSettings) === null) {
if (!getDefaultDataSourceId(uiSettings)) {
return await setFirstDataSourceAsDefault(savedObjectsClient, uiSettings, false);
}
}
Expand Down

0 comments on commit 987208c

Please sign in to comment.