Skip to content

Commit

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

Signed-off-by: Lu Yu <[email protected]>

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

---------

Signed-off-by: Lu Yu <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
BionIT and opensearch-changeset-bot[bot] authored Jun 5, 2024
1 parent c6820db commit b2ff7de
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 b2ff7de

Please sign in to comment.