Skip to content

Commit

Permalink
feat: rename the workspaceBasePath to clientBasePath
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Mar 11, 2024
1 parent 50648b6 commit e290a13
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.

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.

2 changes: 1 addition & 1 deletion src/core/public/http/base_path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('BasePath', () => {
});
});

describe('workspaceBasePath', () => {
describe('clientBasePath', () => {
it('get path with workspace', () => {
expect(new BasePath('/foo/bar', '/foo/bar', '/workspace').get()).toEqual(
'/foo/bar/workspace'
Expand Down
4 changes: 2 additions & 2 deletions src/core/public/http/base_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export class BasePath {
constructor(
private readonly basePath: string = '',
public readonly serverBasePath: string = basePath,
private readonly workspaceBasePath: string = ''
private readonly clientBasePath: string = ''
) {}

public get = () => {
return `${this.basePath}${this.workspaceBasePath}`;
return `${this.basePath}${this.clientBasePath}`;
};

public getBasePath = () => {
Expand Down
10 changes: 5 additions & 5 deletions src/core/public/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type HttpSetupMock = jest.Mocked<HttpSetup> & {
anonymousPaths: jest.Mocked<HttpSetup['anonymousPaths']>;
};

const createServiceMock = ({ basePath = '', workspaceBasePath = '' } = {}): HttpSetupMock => ({
const createServiceMock = ({ basePath = '', clientBasePath = '' } = {}): HttpSetupMock => ({
fetch: jest.fn(),
get: jest.fn(),
head: jest.fn(),
Expand All @@ -48,7 +48,7 @@ const createServiceMock = ({ basePath = '', workspaceBasePath = '' } = {}): Http
patch: jest.fn(),
delete: jest.fn(),
options: jest.fn(),
basePath: new BasePath(basePath, undefined, workspaceBasePath),
basePath: new BasePath(basePath, undefined, clientBasePath),
anonymousPaths: {
register: jest.fn(),
isAnonymous: jest.fn(),
Expand All @@ -58,14 +58,14 @@ const createServiceMock = ({ basePath = '', workspaceBasePath = '' } = {}): Http
intercept: jest.fn(),
});

const createMock = ({ basePath = '', workspaceBasePath = '' } = {}) => {
const createMock = ({ basePath = '', clientBasePath = '' } = {}) => {
const mocked: jest.Mocked<PublicMethodsOf<HttpService>> = {
setup: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
};
mocked.setup.mockReturnValue(createServiceMock({ basePath, workspaceBasePath }));
mocked.start.mockReturnValue(createServiceMock({ basePath, workspaceBasePath }));
mocked.setup.mockReturnValue(createServiceMock({ basePath, clientBasePath }));
mocked.start.mockReturnValue(createServiceMock({ basePath, clientBasePath }));

Check warning on line 68 in src/core/public/http/http_service.mock.ts

View check run for this annotation

Codecov / codecov/patch

src/core/public/http/http_service.mock.ts#L67-L68

Added lines #L67 - L68 were not covered by tests
return mocked;
};

Expand Down
6 changes: 3 additions & 3 deletions src/core/public/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class HttpService implements CoreService<HttpSetup, HttpStart> {

public setup({ injectedMetadata, fatalErrors }: HttpDeps): HttpSetup {
const opensearchDashboardsVersion = injectedMetadata.getOpenSearchDashboardsVersion();
let workspaceBasePath = '';
let clientBasePath = '';
const plugins = injectedMetadata.getPlugins();
const findWorkspaceConfig = plugins.find((plugin) => plugin.id === 'workspace');

Check warning on line 57 in src/core/public/http/http_service.ts

View check run for this annotation

Codecov / codecov/patch

src/core/public/http/http_service.ts#L55-L57

Added lines #L55 - L57 were not covered by tests
// Only try to get workspace id from url when workspace feature is enabled
Expand All @@ -62,13 +62,13 @@ export class HttpService implements CoreService<HttpSetup, HttpStart> {
injectedMetadata.getBasePath()
);
if (workspaceId) {
workspaceBasePath = `${WORKSPACE_PATH_PREFIX}/${workspaceId}`;
clientBasePath = `${WORKSPACE_PATH_PREFIX}/${workspaceId}`;

Check warning on line 65 in src/core/public/http/http_service.ts

View check run for this annotation

Codecov / codecov/patch

src/core/public/http/http_service.ts#L65

Added line #L65 was not covered by tests
}
}
const basePath = new BasePath(
injectedMetadata.getBasePath(),
injectedMetadata.getServerBasePath(),
workspaceBasePath
clientBasePath
);
const fetchService = new Fetch({ basePath, opensearchDashboardsVersion });
const loadingCount = this.loadingCount.setup({ fatalErrors });
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ describe('#getWorkspaceIdFromUrl', () => {
});

describe('#formatUrlWithWorkspaceId', () => {
const basePathWithoutWorkspaceBasePath = httpServiceMock.createSetupContract().basePath;
const basePathWithoutClientBasePath = httpServiceMock.createSetupContract().basePath;
it('return url with workspace prefix when format with a id provided', () => {
expect(
formatUrlWithWorkspaceId('/app/dashboard', 'foo', basePathWithoutWorkspaceBasePath)
formatUrlWithWorkspaceId('/app/dashboard', 'foo', basePathWithoutClientBasePath)
).toEqual('http://localhost/w/foo/app/dashboard');
});

it('return url without workspace prefix when format without a id', () => {
expect(
formatUrlWithWorkspaceId('/w/foo/app/dashboard', '', basePathWithoutWorkspaceBasePath)
formatUrlWithWorkspaceId('/w/foo/app/dashboard', '', basePathWithoutClientBasePath)
).toEqual('http://localhost/app/dashboard');
});
});

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.

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.

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.

0 comments on commit e290a13

Please sign in to comment.