forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace]Add workspace id in basePath (opensearch-project#212)
* feat: enable workspace id in basePath Signed-off-by: SuZhou-Joe <[email protected]> * feat: add unit test Signed-off-by: SuZhou-Joe <[email protected]> * feat: remove useless test object id Signed-off-by: SuZhou-Joe <[email protected]> * feat: add unit test Signed-off-by: SuZhou-Joe <[email protected]> * feat: add unit test Signed-off-by: SuZhou-Joe <[email protected]> * feat: update snapshot Signed-off-by: SuZhou-Joe <[email protected]> * feat: move formatUrlWithWorkspaceId to core/public/utils Signed-off-by: SuZhou-Joe <[email protected]> * feat: remove useless variable Signed-off-by: SuZhou-Joe <[email protected]> * feat: remove useless variable Signed-off-by: SuZhou-Joe <[email protected]> * feat: optimization Signed-off-by: SuZhou-Joe <[email protected]> * feat: optimization Signed-off-by: SuZhou-Joe <[email protected]> * feat: optimization Signed-off-by: SuZhou-Joe <[email protected]> * feat: move workspace/utils to core Signed-off-by: SuZhou-Joe <[email protected]> * feat: move workspace/utils to core Signed-off-by: SuZhou-Joe <[email protected]> * feat: update comment Signed-off-by: SuZhou-Joe <[email protected]> * feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> * feat: update unit test Signed-off-by: SuZhou-Joe <[email protected]> * feat: optimization Signed-off-by: SuZhou-Joe <[email protected]> * feat: add space under license Signed-off-by: SuZhou-Joe <[email protected]> * fix: unit test Signed-off-by: SuZhou-Joe <[email protected]> --------- Signed-off-by: SuZhou-Joe <[email protected]> (cherry picked from commit 43e91fa)
- Loading branch information
1 parent
e36a7b6
commit 4db94fc
Showing
20 changed files
with
740 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { getWorkspaceIdFromUrl, formatUrlWithWorkspaceId } from './workspace'; | ||
import { httpServiceMock } from '../public/mocks'; | ||
|
||
describe('#getWorkspaceIdFromUrl', () => { | ||
it('return workspace when there is a match', () => { | ||
expect(getWorkspaceIdFromUrl('http://localhost/w/foo')).toEqual('foo'); | ||
}); | ||
|
||
it('return empty when there is not a match', () => { | ||
expect(getWorkspaceIdFromUrl('http://localhost/w2/foo')).toEqual(''); | ||
}); | ||
}); | ||
|
||
describe('#formatUrlWithWorkspaceId', () => { | ||
const basePathWithoutWorkspaceBasePath = httpServiceMock.createSetupContract().basePath; | ||
it('return url with workspace prefix when format with a id provided', () => { | ||
expect( | ||
formatUrlWithWorkspaceId('/app/dashboard', 'foo', basePathWithoutWorkspaceBasePath) | ||
).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) | ||
).toEqual('http://localhost/app/dashboard'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WORKSPACE_PATH_PREFIX } from './constants'; | ||
import { IBasePath } from '../public'; | ||
|
||
export const getWorkspaceIdFromUrl = (url: string): string => { | ||
const regexp = /\/w\/([^\/]*)/; | ||
const urlObject = new URL(url); | ||
const matchedResult = urlObject.pathname.match(regexp); | ||
if (matchedResult) { | ||
return matchedResult[1]; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
export const cleanWorkspaceId = (path: string) => { | ||
return path.replace(/^\/w\/([^\/]*)/, ''); | ||
}; | ||
|
||
export const formatUrlWithWorkspaceId = (url: string, workspaceId: string, basePath: IBasePath) => { | ||
const newUrl = new URL(url, window.location.href); | ||
/** | ||
* Patch workspace id into path | ||
*/ | ||
newUrl.pathname = basePath.remove(newUrl.pathname); | ||
|
||
if (workspaceId) { | ||
newUrl.pathname = `${WORKSPACE_PATH_PREFIX}/${workspaceId}${newUrl.pathname}`; | ||
} else { | ||
newUrl.pathname = cleanWorkspaceId(newUrl.pathname); | ||
} | ||
|
||
newUrl.pathname = basePath.prepend(newUrl.pathname, { | ||
withoutWorkspace: true, | ||
}); | ||
|
||
return newUrl.toString(); | ||
}; |
180 changes: 180 additions & 0 deletions
180
...public/components/workspace_fatal_error/__snapshots__/workspace_fatal_error.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.