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 APIs to support plugin state in request (opensearch-p…
…roject#6303) * feat: add APIs to support plugin state in request (#312) * feat: add APIs to support plugin state in request Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: add APIs to support plugin state in request Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: update CHANGELOG Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: update Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: use request app to store request workspace id Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: remove useless if Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
- Loading branch information
1 parent
b92387a
commit fc3fef2
Showing
4 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { httpServerMock } from '../mocks'; | ||
import { getWorkspaceState, updateWorkspaceState } from './workspace'; | ||
|
||
describe('updateWorkspaceState', () => { | ||
it('update with payload', () => { | ||
const requestMock = httpServerMock.createOpenSearchDashboardsRequest(); | ||
updateWorkspaceState(requestMock, { | ||
requestWorkspaceId: 'foo', | ||
}); | ||
expect(getWorkspaceState(requestMock)).toEqual({ | ||
requestWorkspaceId: 'foo', | ||
}); | ||
}); | ||
}); |
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,36 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { OpenSearchDashboardsRequest, ensureRawRequest } from '../http/router'; | ||
|
||
export interface WorkspaceState { | ||
requestWorkspaceId?: string; | ||
} | ||
|
||
/** | ||
* This function will be used as a proxy | ||
* because `ensureRequest` is only importable from core module. | ||
* | ||
* @param workspaceId string | ||
* @returns void | ||
*/ | ||
export const updateWorkspaceState = ( | ||
request: OpenSearchDashboardsRequest, | ||
payload: Partial<WorkspaceState> | ||
) => { | ||
const rawRequest = ensureRawRequest(request); | ||
|
||
rawRequest.app = { | ||
...rawRequest.app, | ||
...payload, | ||
}; | ||
}; | ||
|
||
export const getWorkspaceState = (request: OpenSearchDashboardsRequest): WorkspaceState => { | ||
const { requestWorkspaceId } = ensureRawRequest(request).app as WorkspaceState; | ||
return { | ||
requestWorkspaceId, | ||
}; | ||
}; |