Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Mar 11, 2024
1 parent 56d4113 commit 1bd71cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/plugins/workspace/public/workspace_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('#WorkspaceClient', () => {
success: true,
});
await workspaceClient.enterWorkspace('foo');
expect(await workspaceClient.getCurrentWorkspaceId()).toEqual({
expect(workspaceClient.getCurrentWorkspaceId()).toEqual({
success: true,
result: 'foo',
});
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/workspace/public/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import {
HttpFetchError,
HttpFetchOptions,
Expand Down Expand Up @@ -145,12 +146,14 @@ export class WorkspaceClient {
/**
* A bypass layer to get current workspace id
*/
public async getCurrentWorkspaceId(): Promise<IResponse<WorkspaceAttribute['id']>> {
public getCurrentWorkspaceId(): IResponse<WorkspaceAttribute['id']> {
const currentWorkspaceId = this.workspaces.currentWorkspaceId$.getValue();
if (!currentWorkspaceId) {
return {

Check warning on line 152 in src/plugins/workspace/public/workspace_client.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/workspace_client.ts#L152

Added line #L152 was not covered by tests
success: false,
error: 'You are not in any workspace yet.',
error: i18n.translate('workspace.error.notInWorkspace', {
defaultMessage: 'You are not in any workspace yet.',
}),
};
}

Expand All @@ -164,7 +167,7 @@ export class WorkspaceClient {
* Do a find in the latest workspace list with current workspace id
*/
public async getCurrentWorkspace(): Promise<IResponse<WorkspaceAttribute>> {
const currentWorkspaceIdResp = await this.getCurrentWorkspaceId();
const currentWorkspaceIdResp = this.getCurrentWorkspaceId();
if (currentWorkspaceIdResp.success) {
const currentWorkspaceResp = await this.get(currentWorkspaceIdResp.result);
return currentWorkspaceResp;
Expand Down

0 comments on commit 1bd71cc

Please sign in to comment.