Skip to content

Commit

Permalink
unsubscribe update current workspace to saved object client when
Browse files Browse the repository at this point in the history
workspace plugin stopped

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
ruanyl committed Jul 14, 2023
1 parent d4feb6b commit 0928a77
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import {
import { WORKSPACE_APP_ID } from '../common/constants';
import { mountDropdownList } from './mount';
import { getWorkspaceIdFromUrl } from '../../../core/public/utils';
import type { Subscription } from 'rxjs';

Check failure on line 17 in src/plugins/workspace/public/plugin.ts

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

`rxjs` import should occur before import of `../../../core/public`

Check failure on line 17 in src/plugins/workspace/public/plugin.ts

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

`rxjs` import should occur before import of `../../../core/public`

export class WorkspacesPlugin implements Plugin<{}, {}> {
private coreSetup?: CoreSetup;
private coreStart?: CoreStart;
private currentWorkspaceSubscription?: Subscription;
private getWorkspaceIdFromURL(): string | null {
return getWorkspaceIdFromUrl(window.location.href);
}
Expand Down Expand Up @@ -86,9 +88,11 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {

private _changeSavedObjectCurrentWorkspace() {
if (this.coreStart) {
this.coreStart.workspaces.client.currentWorkspaceId$.subscribe((currentWorkspaceId) => {
this.coreStart?.savedObjects.client.setCurrentWorkspace(currentWorkspaceId);
});
return this.coreStart.workspaces.client.currentWorkspaceId$.subscribe(
(currentWorkspaceId) => {
this.coreStart?.savedObjects.client.setCurrentWorkspace(currentWorkspaceId);
}
);
}
}

Expand All @@ -105,7 +109,11 @@ export class WorkspacesPlugin implements Plugin<{}, {}> {
workspaces: core.workspaces,
chrome: core.chrome,
});
this._changeSavedObjectCurrentWorkspace();
this.currentWorkspaceSubscription = this._changeSavedObjectCurrentWorkspace();
return {};
}

public stop() {
this.currentWorkspaceSubscription?.unsubscribe();
}
}

0 comments on commit 0928a77

Please sign in to comment.