Skip to content

Commit

Permalink
add updateWorkspaceState
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao committed Jul 8, 2024
1 parent 23d1471 commit a1dc92b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/plugins/workspace/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ export const checkAndSetDefaultDataSources = async (
if (dataSources?.length > 0) {
if (!isNeededCheck) {
// Create# Will set first data source as default data source.
uiSettingsClient.set(DEFAULT_DATA_SOURCE_UI_SETTINGS_ID, dataSources[0]);
await uiSettingsClient.set(DEFAULT_DATA_SOURCE_UI_SETTINGS_ID, dataSources[0]);
} else {
// Update will check if default DS still exists.
const defaultDSId = (await uiSettingsClient.get(DEFAULT_DATA_SOURCE_UI_SETTINGS_ID)) ?? '';
const isDefaultDSExist = dataSources.indexOf(defaultDSId) > -1;
if (!isDefaultDSExist) {
uiSettingsClient.set(DEFAULT_DATA_SOURCE_UI_SETTINGS_ID, dataSources[0]);
await uiSettingsClient.set(DEFAULT_DATA_SOURCE_UI_SETTINGS_ID, dataSources[0]);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/workspace/server/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
WorkspaceAttribute,
SavedObjectsServiceStart,
UiSettingsServiceStart,
WORKSPACE_TYPE,
} from '../../../core/server';
import { WORKSPACE_TYPE } from '../../../core/server';
import { updateWorkspaceState } from '../../../core/server/utils';
import {
IWorkspaceClientImpl,
WorkspaceFindOptions,
Expand Down Expand Up @@ -125,9 +126,13 @@ export class WorkspaceClient implements IWorkspaceClientImpl {
}
);
if (dataSources && this.uiSettings && client) {
// This is for setting in workspace environment, otherwise uiSettings can't set workspace level value.
updateWorkspaceState(requestDetail.request, {
requestWorkspaceId: id,
});
// Set first data source as default after creating workspace
const uiSettingsClient = this.uiSettings.asScopedToClient(client);
checkAndSetDefaultDataSources(uiSettingsClient, dataSources, false);
await checkAndSetDefaultDataSources(uiSettingsClient, dataSources, false);
}

return {
Expand Down

0 comments on commit a1dc92b

Please sign in to comment.