Skip to content

Commit

Permalink
feat: remove useless 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 Oct 7, 2023
1 parent 73d595c commit 05fda74
Showing 1 changed file with 8 additions and 57 deletions.
65 changes: 8 additions & 57 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import { BehaviorSubject, combineLatest } from 'rxjs';
import { i18n } from '@osd/i18n';
import { debounce } from 'lodash';
import {
CoreSetup,
CoreStart,
Plugin,
AppMountParameters,
AppNavLinkStatus,
} from '../../../core/public';
import { CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { WORKSPACE_APP_ID, PATHS, WORKSPACE_ID_QUERYSTRING_NAME } from '../common/constants';
import { HashURL } from './components/utils/hash_url';

Expand All @@ -28,12 +22,7 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {
return this.getWorkpsaceIdFromURL() || '';
}

const currentWorkspaceIdResp = await this.core?.workspaces.client.getCurrentWorkspaceId();
if (currentWorkspaceIdResp?.success && currentWorkspaceIdResp?.result) {
return currentWorkspaceIdResp.result;
}

return '';
return (await this.core?.workspaces.currentWorkspaceId$.getValue()) || '';
}
private getPatchedUrl = (
url: string,
Expand Down Expand Up @@ -78,7 +67,7 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {
);
}
private shouldPatchUrl(): boolean {
const currentWorkspaceId = this.core?.workspaces.client.currentWorkspaceId$.getValue();
const currentWorkspaceId = this.core?.workspaces.currentWorkspaceId$.getValue();
const workspaceIdFromURL = this.getWorkpsaceIdFromURL();
if (!currentWorkspaceId && !workspaceIdFromURL) {
return false;
Expand All @@ -94,7 +83,7 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {
const startService = await this.core?.getStartServices();
if (startService) {
combineLatest([
this.core?.workspaces.client.currentWorkspaceId$,
this.core?.workspaces.currentWorkspaceId$,
startService[0].application.currentAppId$,
]).subscribe(async ([]) => {
if (this.shouldPatchUrl()) {
Expand All @@ -106,24 +95,16 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {
}
public async setup(core: CoreSetup) {
this.core = core;
this.core?.workspaces.setFormatUrlWithWorkspaceId((url, id, options) =>
this.getPatchedUrl(url, id, options)
);
/**
* Retrive workspace id from url
*/
const workspaceId = this.getWorkpsaceIdFromURL();

if (workspaceId) {
const result = await core.workspaces.client.enterWorkspace(workspaceId);
if (!result.success) {
core.fatalErrors.add(
result.error ||
i18n.translate('workspace.error.setup', {
defaultMessage: 'Workspace init failed',
})
);
}
/**
* Enter a workspace
*/
this.core.workspaces.currentWorkspaceId$.next(workspaceId);
}

/**
Expand All @@ -142,45 +123,15 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {
}, 500)
);

core.application.register({
id: WORKSPACE_APP_ID,
title: i18n.translate('workspace.settings.title', {
defaultMessage: 'Workspace',
}),
// order: 6010,
navLinkStatus: AppNavLinkStatus.hidden,
// updater$: this.appUpdater,
async mount(params: AppMountParameters) {
const { renderApp } = await import('./application');
const [coreStart] = await core.getStartServices();
const services = {
...coreStart,
};

return renderApp(params, services);
},
});

return {};
}

private async _changeSavedObjectCurrentWorkspace() {
const startServices = await this.core?.getStartServices();
if (startServices) {
const coreStart = startServices[0];
coreStart.workspaces.client.currentWorkspaceId$.subscribe((currentWorkspaceId) => {
coreStart.savedObjects.client.setCurrentWorkspace(currentWorkspaceId);
});
}
}

public start(core: CoreStart) {
core.chrome.setCustomNavLink({
title: i18n.translate('workspace.nav.title', { defaultMessage: 'Workspace Overview' }),
baseUrl: core.http.basePath.get(),
href: core.application.getUrlForApp(WORKSPACE_APP_ID, { path: PATHS.update }),
});
this._changeSavedObjectCurrentWorkspace();
return {};
}
}

0 comments on commit 05fda74

Please sign in to comment.