Skip to content

Commit

Permalink
feat: some modify
Browse files Browse the repository at this point in the history
  • Loading branch information
SuZhou-Joe committed Aug 27, 2023
1 parent 04814a3 commit 53dfc5c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps>
workspaceClient.init();
const featureFlagResp = await workspaceClient.getFeatureFlag();
if (featureFlagResp.success) {
core.workspaces.workspaceEnabled$.next(featureFlagResp.result);
core.workspaces.workspaceEnabled$.next(featureFlagResp.result.enabled);
} else {
core.workspaces.workspaceEnabled$.next(false);
}
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/workspace/public/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,12 @@ export class WorkspaceClient {
return result;
}

public async getFeatureFlag(): Promise<IResponse<boolean>> {
const result = await this.safeFetch(this.getPath(['is_workspace_enabled']), {
public async getFeatureFlag(): Promise<
IResponse<{
enabled: boolean;
}>
> {
const result = await this.safeFetch(this.getPath(['settings']), {
method: 'get',
});

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
logger: this.logger,
client: this.client as IWorkspaceDBImpl,
enabled$: this.enabled$,
config$: this.config$,
});

core.savedObjects.setClientFactoryProvider((repositoryFactory) => () =>
Expand Down Expand Up @@ -218,6 +219,5 @@ export class WorkspacePlugin implements Plugin<{}, {}> {

public stop() {
this.enabled$.unsubscribe();
clearTimeout(this.loopRequestTimer);
}
}
14 changes: 11 additions & 3 deletions src/plugins/workspace/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { schema } from '@osd/config-schema';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { ensureRawRequest } from '../../../../core/server';

import {
Expand All @@ -14,6 +15,7 @@ import {
WorkspacePermissionMode,
} from '../../../../core/server';
import { IWorkspaceDBImpl, WorkspaceRoutePermissionItem } from '../types';
import { ConfigSchema } from '../../config';

const WORKSPACES_API_BASE_URL = '/api/workspaces';

Expand Down Expand Up @@ -84,11 +86,13 @@ export function registerRoutes({
logger,
http,
enabled$,
config$,
}: {
client: IWorkspaceDBImpl;
logger: Logger;
http: CoreSetup['http'];
enabled$: BehaviorSubject<boolean>;
config$: Observable<ConfigSchema>;
}) {
const router = http.createRouter();
router.post(
Expand Down Expand Up @@ -261,14 +265,18 @@ export function registerRoutes({

router.get(
{
path: `${WORKSPACES_API_BASE_URL}/is_workspace_enabled`,
path: `${WORKSPACES_API_BASE_URL}/settings`,
validate: {},
},
router.handleLegacyErrors(async (context, req, res) => {
const config = await config$.pipe(first()).toPromise();
return res.ok({
body: {
success: true,
result: enabled$.getValue(),
result: {
...config,
enabled: enabled$.getValue(),
},
},
});
})
Expand Down

0 comments on commit 53dfc5c

Please sign in to comment.