Skip to content

Commit

Permalink
Add validation when load page (#8)
Browse files Browse the repository at this point in the history
* fix: validation & query

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: modify file name to reduce confusion

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add landing logic to retrive workspace id

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: make client more robust

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: use Subject

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Jul 19, 2023
1 parent 8124a2a commit e735275
Show file tree
Hide file tree
Showing 21 changed files with 340 additions and 152 deletions.
2 changes: 2 additions & 0 deletions src/core/public/core_app/core_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ import type { IUiSettingsClient } from '../ui_settings';
import type { InjectedMetadataSetup } from '../injected_metadata';
import { renderApp as renderErrorApp, setupUrlOverflowDetection } from './errors';
import { renderApp as renderStatusApp } from './status';
import { WorkspacesSetup } from '../workspace';

interface SetupDeps {
application: InternalApplicationSetup;
http: HttpSetup;
injectedMetadata: InjectedMetadataSetup;
notifications: NotificationsSetup;
workspaces: WorkspacesSetup;
}

interface StartDeps {
Expand Down
6 changes: 4 additions & 2 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ export class CoreSystem {
const http = this.http.setup({ injectedMetadata, fatalErrors: this.fatalErrorsSetup });
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
const notifications = this.notifications.setup({ uiSettings });
const workspaces = await this.workspaces.setup({ http });

const pluginDependencies = this.plugins.getOpaqueIds();
const context = this.context.setup({
pluginDependencies: new Map([...pluginDependencies]),
});
const application = this.application.setup({ context, http });
this.coreApp.setup({ application, http, injectedMetadata, notifications });
this.coreApp.setup({ application, http, injectedMetadata, notifications, workspaces });

const core: InternalCoreSetup = {
application,
Expand All @@ -179,6 +180,7 @@ export class CoreSystem {
injectedMetadata,
notifications,
uiSettings,
workspaces,
};

// Services that do not expose contracts at setup
Expand All @@ -202,7 +204,7 @@ export class CoreSystem {
const uiSettings = await this.uiSettings.start();
const docLinks = this.docLinks.start({ injectedMetadata });
const http = await this.http.start();
const workspaces = await this.workspaces.start({ http });
const workspaces = await this.workspaces.start();
const savedObjects = await this.savedObjects.start({ http });
const i18n = await this.i18n.start();
const fatalErrors = await this.fatalErrors.start();
Expand Down
30 changes: 30 additions & 0 deletions src/core/public/fatal_errors/fatal_errors_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import type { PublicMethodsOf } from '@osd/utility-types';
import { FatalErrorsService, FatalErrorsSetup } from './fatal_errors_service';
import { BehaviorSubject, Subject } from 'rxjs';
import { WorkspaceAttribute } from '../workspace';

const createSetupContractMock = () => {
const setupContract: jest.Mocked<FatalErrorsSetup> = {
Expand Down Expand Up @@ -58,3 +60,31 @@ export const fatalErrorsServiceMock = {
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
};

const currentWorkspaceId$ = new BehaviorSubject<string>('');
const workspaceList$ = new Subject<WorkspaceAttribute[]>();

const createWorkspacesSetupContractMock = () => ({
client: {
currentWorkspaceId$,
workspaceList$,
stop: jest.fn(),
enterWorkspace: jest.fn(),
exitWorkspace: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
list: jest.fn(),
getCurrentWorkspace: jest.fn(),
getCurrentWorkspaceId: jest.fn(),
get: jest.fn(),
update: jest.fn(),
},
formatUrlWithWorkspaceId: jest.fn(),
});

const createWorkspacesStartContractMock = createWorkspacesSetupContractMock;

export const workspacesServiceMock = {
createSetupContractMock: createWorkspacesStartContractMock,
createStartContract: createWorkspacesStartContractMock,
};
5 changes: 4 additions & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import {
HandlerParameters,
} from './context';
import { Branding } from '../types';
import { WorkspacesStart } from './workspace';
import { WorkspacesStart, WorkspacesSetup } from './workspace';

export { PackageInfo, EnvironmentMode } from '../server/types';
/** @interal */
Expand Down Expand Up @@ -241,6 +241,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
};
/** {@link StartServicesAccessor} */
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
/** {@link WorkspacesSetup} */
workspaces: WorkspacesSetup;
}

/**
Expand Down Expand Up @@ -354,4 +356,5 @@ export {
WorkspacesService,
WorkspaceAttribute,
WorkspaceFindOptions,
WORKSPACE_ID_QUERYSTRING_NAME,
} from './workspace';
1 change: 1 addition & 0 deletions src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function createPluginSetupContext<
getBranding: deps.injectedMetadata.getBranding,
},
getStartServices: () => plugin.startDependencies,
workspaces: deps.workspaces,
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import { applicationServiceMock } from '../application/application_service.mock'
import { i18nServiceMock } from '../i18n/i18n_service.mock';
import { overlayServiceMock } from '../overlays/overlay_service.mock';
import { chromeServiceMock } from '../chrome/chrome_service.mock';
import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.mock';
import {
fatalErrorsServiceMock,
workspacesServiceMock,
} from '../fatal_errors/fatal_errors_service.mock';
import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock';
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
import { httpServiceMock } from '../http/http_service.mock';
Expand Down Expand Up @@ -108,6 +111,7 @@ describe('PluginsService', () => {
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
notifications: notificationServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
workspaces: workspacesServiceMock.createSetupContractMock(),
};
mockSetupContext = {
...mockSetupDeps,
Expand All @@ -127,6 +131,7 @@ describe('PluginsService', () => {
uiSettings: uiSettingsServiceMock.createStartContract(),
savedObjects: savedObjectsServiceMock.createStartContract(),
fatalErrors: fatalErrorsServiceMock.createStartContract(),
workspaces: workspacesServiceMock.createStartContract(),
};
mockStartContext = {
...mockStartDeps,
Expand Down
8 changes: 8 additions & 0 deletions src/core/public/workspace/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const WORKSPACES_API_BASE_URL = '/api/workspaces';

export const WORKSPACE_ID_QUERYSTRING_NAME = '_workspace_id_';
5 changes: 3 additions & 2 deletions src/core/public/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
export { WorkspacesClientContract, WorkspacesClient } from './workspaces_client';
export { WorkspacesStart, WorkspacesService } from './workspaces_service';
export { WorkspaceAttribute, WorkspaceFindOptions } from '../../server/types';
export { WorkspacesStart, WorkspacesService, WorkspacesSetup } from './workspaces_service';
export type { WorkspaceAttribute, WorkspaceFindOptions } from '../../server/types';
export { WORKSPACE_ID_QUERYSTRING_NAME } from './consts';
Loading

0 comments on commit e735275

Please sign in to comment.