Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary workspace menu register #204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/core/public/core_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ describe('#start()', () => {
it('calls workspaces#start()', async () => {
await startCore();
expect(MockWorkspacesService.start).toHaveBeenCalledTimes(1);
expect(MockWorkspacesService.start).toHaveBeenCalledWith({
application: expect.any(Object),
http: expect.any(Object),
});
});

it('calls coreApp#start()', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class CoreSystem {
targetDomElement: notificationsTargetDomElement,
});
const application = await this.application.start({ http, overlays });
const workspaces = this.workspaces.start({ application, http });
const workspaces = this.workspaces.start();
const chrome = await this.chrome.start({
application,
docLinks,
Expand Down
2 changes: 0 additions & 2 deletions src/core/public/workspace/workspaces_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const createWorkspacesSetupContractMock = () => ({
currentWorkspace$,
initialized$,
workspaceEnabled$,
registerWorkspaceMenuRender: jest.fn(),
});

const createWorkspacesStartContractMock = () => ({
Expand All @@ -30,7 +29,6 @@ const createWorkspacesStartContractMock = () => ({
currentWorkspace$,
initialized$,
workspaceEnabled$,
renderWorkspaceMenu: jest.fn(),
});

export type WorkspacesServiceContract = PublicMethodsOf<WorkspacesService>;
Expand Down
22 changes: 2 additions & 20 deletions src/core/public/workspace/workspaces_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { httpServiceMock } from '../http/http_service.mock';
import { applicationServiceMock } from '../application/application_service.mock';
import { WorkspacesService, WorkspacesSetup, WorkspacesStart } from './workspaces_service';
import { WorkspacesService, WorkspacesStart } from './workspaces_service';

describe('WorkspacesService', () => {
let workspaces: WorkspacesService;
let workspacesSetup: WorkspacesSetup;
let workspacesStart: WorkspacesStart;

beforeEach(() => {
workspaces = new WorkspacesService();
workspacesSetup = workspaces.setup();
workspacesStart = workspaces.start({
http: httpServiceMock.createStartContract(),
application: applicationServiceMock.createInternalStartContract(),
});
workspacesStart = workspaces.start();
});

afterEach(() => {
Expand All @@ -42,17 +35,6 @@ describe('WorkspacesService', () => {
expect(workspacesStart.workspaceList$.value.length).toBe(0);
});

it('should call menu render function', () => {
const renderFn = jest.fn();
workspacesSetup.registerWorkspaceMenuRender(renderFn);
workspacesStart.renderWorkspaceMenu();
expect(renderFn).toHaveBeenCalled();
});

it('should return null if NO menu render function was registered', () => {
expect(workspacesStart.renderWorkspaceMenu()).toBe(null);
});

it('the current workspace should also updated after changing current workspace id', () => {
expect(workspacesStart.currentWorkspace$.value).toBe(null);

Expand Down
51 changes: 4 additions & 47 deletions src/core/public/workspace/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ import { BehaviorSubject, combineLatest } from 'rxjs';
import { isEqual } from 'lodash';

import { CoreService, WorkspaceAttribute } from '../../types';
import { InternalApplicationStart } from '../application';
import { HttpStart } from '../http';

type WorkspaceMenuRenderFn = ({
basePath,
getUrlForApp,
observables,
}: {
getUrlForApp: InternalApplicationStart['getUrlForApp'];
basePath: HttpStart['basePath'];
observables: WorkspaceObservables;
}) => JSX.Element | null;

type WorkspaceObject = WorkspaceAttribute & { readonly?: boolean };

Expand All @@ -34,24 +22,15 @@ enum WORKSPACE_ERROR {
WORKSPACE_STALED = 'WORKSPACE_STALED',
}

/**
* @public
*/
export interface WorkspacesSetup extends WorkspaceObservables {
registerWorkspaceMenuRender: (render: WorkspaceMenuRenderFn) => void;
}

export interface WorkspacesStart extends WorkspaceObservables {
renderWorkspaceMenu: () => JSX.Element | null;
}
export type WorkspacesSetup = WorkspaceObservables;
export type WorkspacesStart = WorkspaceObservables;

export class WorkspacesService implements CoreService<WorkspacesSetup, WorkspacesStart> {
private currentWorkspaceId$ = new BehaviorSubject<string>('');
private workspaceList$ = new BehaviorSubject<WorkspaceObject[]>([]);
private currentWorkspace$ = new BehaviorSubject<WorkspaceObject | null>(null);
private initialized$ = new BehaviorSubject<boolean>(false);
private workspaceEnabled$ = new BehaviorSubject<boolean>(false);
private _renderWorkspaceMenu: WorkspaceMenuRenderFn | null = null;

constructor() {
combineLatest([this.initialized$, this.workspaceList$, this.currentWorkspaceId$]).subscribe(
Expand Down Expand Up @@ -89,38 +68,17 @@ export class WorkspacesService implements CoreService<WorkspacesSetup, Workspace
workspaceList$: this.workspaceList$,
initialized$: this.initialized$,
workspaceEnabled$: this.workspaceEnabled$,
registerWorkspaceMenuRender: (render: WorkspaceMenuRenderFn) =>
(this._renderWorkspaceMenu = render),
};
}

public start({
http,
application,
}: {
application: InternalApplicationStart;
http: HttpStart;
}): WorkspacesStart {
const observables = {
public start(): WorkspacesStart {
return {
currentWorkspaceId$: this.currentWorkspaceId$,
currentWorkspace$: this.currentWorkspace$,
workspaceList$: this.workspaceList$,
initialized$: this.initialized$,
workspaceEnabled$: this.workspaceEnabled$,
};
return {
...observables,
renderWorkspaceMenu: () => {
if (this._renderWorkspaceMenu) {
return this._renderWorkspaceMenu({
basePath: http.basePath,
getUrlForApp: application.getUrlForApp,
observables,
});
}
return null;
},
};
}

public async stop() {
Expand All @@ -129,6 +87,5 @@ export class WorkspacesService implements CoreService<WorkspacesSetup, Workspace
this.workspaceList$.unsubscribe();
this.workspaceEnabled$.unsubscribe();
this.initialized$.unsubscribe();
this._renderWorkspaceMenu = null;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading