-
Notifications
You must be signed in to change notification settings - Fork 893
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
[Workspace] introducing workspace level ui settings #6510
Merged
ruanyl
merged 6 commits into
opensearch-project:main
from
ruanyl:feature/introducing-workspace-ui-settings
Apr 23, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
31b68f8
feat: workspace level ui settings (#328)
ruanyl a609d21
add license header
ruanyl b028827
Merge branch 'main' into feature/introducing-workspace-ui-settings
ruanyl 937b2a2
Merge branch 'main' into feature/introducing-workspace-ui-settings
ruanyl 362983f
Merge branch 'main' into feature/introducing-workspace-ui-settings
ruanyl 3d3a940
fix linter
ruanyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
93 changes: 93 additions & 0 deletions
93
...ns/workspace/server/saved_objects/integration_tests/workspace_ui_settings_wrapper.test.ts
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,93 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IUiSettingsClient, WorkspaceAttribute } from 'src/core/server'; | ||
|
||
import * as osdTestServer from '../../../../../core/test_helpers/osd_server'; | ||
import { httpServerMock } from '../../../../../core/server/http/http_server.mocks'; | ||
Check failure on line 9 in src/plugins/workspace/server/saved_objects/integration_tests/workspace_ui_settings_wrapper.test.ts GitHub Actions / Build and Verify on Linux (ciGroup1)
|
||
|
||
describe('workspace ui settings saved object client wrapper', () => { | ||
let opensearchServer: osdTestServer.TestOpenSearchUtils; | ||
let osd: osdTestServer.TestOpenSearchDashboardsUtils; | ||
let globalUiSettingsClient: IUiSettingsClient; | ||
let testWorkspace: WorkspaceAttribute = { | ||
id: '', | ||
name: '', | ||
}; | ||
|
||
beforeAll(async () => { | ||
const servers = osdTestServer.createTestServers({ | ||
adjustTimeout: (t: number) => jest.setTimeout(t), | ||
settings: { | ||
osd: { | ||
workspace: { | ||
enabled: true, | ||
}, | ||
savedObjects: { | ||
permission: { | ||
enabled: true, | ||
}, | ||
}, | ||
migrations: { | ||
skip: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
opensearchServer = await servers.startOpenSearch(); | ||
osd = await servers.startOpenSearchDashboards(); | ||
|
||
const savedObjectsClient = osd.coreStart.savedObjects.getScopedClient( | ||
httpServerMock.createOpenSearchDashboardsRequest() | ||
); | ||
globalUiSettingsClient = osd.coreStart.uiSettings.asScopedToClient(savedObjectsClient); | ||
|
||
const res = await osdTestServer.request.post(osd.root, '/api/workspaces').send({ | ||
attributes: { name: 'test workspace' }, | ||
}); | ||
testWorkspace = res.body.result; | ||
}, 30000); | ||
|
||
afterAll(async () => { | ||
await opensearchServer.stop(); | ||
await osd.stop(); | ||
}, 30000); | ||
|
||
beforeEach(async () => { | ||
await globalUiSettingsClient.set('defaultIndex', 'global-index'); | ||
}); | ||
|
||
it('should get and update workspace ui settings when currently in a workspace', async () => { | ||
const workspaceScopedSavedObjectsClient = osd.coreStart.savedObjects.getScopedClient( | ||
httpServerMock.createOpenSearchDashboardsRequest({ | ||
opensearchDashboardsRequestState: { requestWorkspaceId: testWorkspace.id }, | ||
}) | ||
); | ||
const workspaceScopedUiSettingsClient = osd.coreStart.uiSettings.asScopedToClient( | ||
workspaceScopedSavedObjectsClient | ||
); | ||
|
||
expect(await globalUiSettingsClient.get('defaultIndex')).toBe('global-index'); | ||
|
||
// workspace defaultIndex is not set, it will use the global value | ||
expect(await workspaceScopedUiSettingsClient.get('defaultIndex')).toBe('global-index'); | ||
|
||
// update ui settings in a workspace | ||
await workspaceScopedUiSettingsClient.set('defaultIndex', 'workspace-index'); | ||
|
||
// global ui settings remain unchanged | ||
expect(await globalUiSettingsClient.get('defaultIndex')).toBe('global-index'); | ||
|
||
// workspace ui settings updated to the new value | ||
expect(await workspaceScopedUiSettingsClient.get('defaultIndex')).toBe('workspace-index'); | ||
}); | ||
|
||
it('should get and update global ui settings when currently not in a workspace', async () => { | ||
expect(await globalUiSettingsClient.get('defaultIndex')).toBe('global-index'); | ||
|
||
await globalUiSettingsClient.set('defaultIndex', 'global-index-new'); | ||
expect(await globalUiSettingsClient.get('defaultIndex')).toBe('global-index-new'); | ||
}); | ||
}); |
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
139 changes: 139 additions & 0 deletions
139
src/plugins/workspace/server/saved_objects/workspace_ui_settings_client_wrapper.test.ts
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,139 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { httpServerMock, savedObjectsClientMock, coreMock } from '../../../../core/server/mocks'; | ||
import { WorkspaceUiSettingsClientWrapper } from './workspace_ui_settings_client_wrapper'; | ||
import { WORKSPACE_TYPE } from '../../../../core/server'; | ||
|
||
import * as utils from '../../../../core/server/utils'; | ||
|
||
jest.mock('../../../../core/server/utils'); | ||
|
||
describe('WorkspaceUiSettingsClientWrapper', () => { | ||
const createWrappedClient = () => { | ||
const clientMock = savedObjectsClientMock.create(); | ||
const getClientMock = jest.fn().mockReturnValue(clientMock); | ||
const requestHandlerContext = coreMock.createRequestHandlerContext(); | ||
const requestMock = httpServerMock.createOpenSearchDashboardsRequest(); | ||
|
||
clientMock.get.mockImplementation(async (type, id) => { | ||
if (type === 'config') { | ||
return Promise.resolve({ | ||
id, | ||
references: [], | ||
type: 'config', | ||
attributes: { | ||
defaultIndex: 'default-index-global', | ||
}, | ||
}); | ||
} else if (type === WORKSPACE_TYPE) { | ||
return Promise.resolve({ | ||
id, | ||
references: [], | ||
type: WORKSPACE_TYPE, | ||
attributes: { | ||
uiSettings: { | ||
defaultIndex: 'default-index-workspace', | ||
}, | ||
}, | ||
}); | ||
} | ||
return Promise.reject(); | ||
}); | ||
|
||
const wrapper = new WorkspaceUiSettingsClientWrapper(); | ||
wrapper.setScopedClient(getClientMock); | ||
|
||
return { | ||
wrappedClient: wrapper.wrapperFactory({ | ||
client: clientMock, | ||
request: requestMock, | ||
typeRegistry: requestHandlerContext.savedObjects.typeRegistry, | ||
}), | ||
clientMock, | ||
}; | ||
}; | ||
|
||
it('should return workspace ui settings if in a workspace', async () => { | ||
// Currently in a workspace | ||
jest.spyOn(utils, 'getWorkspaceState').mockReturnValue({ requestWorkspaceId: 'workspace-id' }); | ||
|
||
const { wrappedClient } = createWrappedClient(); | ||
|
||
const result = await wrappedClient.get('config', '3.0.0'); | ||
expect(result).toEqual({ | ||
id: '3.0.0', | ||
references: [], | ||
type: 'config', | ||
attributes: { | ||
defaultIndex: 'default-index-workspace', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return global ui settings if NOT in a workspace', async () => { | ||
// Currently NOT in a workspace | ||
jest.spyOn(utils, 'getWorkspaceState').mockReturnValue({}); | ||
|
||
const { wrappedClient } = createWrappedClient(); | ||
|
||
const result = await wrappedClient.get('config', '3.0.0'); | ||
expect(result).toEqual({ | ||
id: '3.0.0', | ||
references: [], | ||
type: 'config', | ||
attributes: { | ||
defaultIndex: 'default-index-global', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should update workspace ui settings', async () => { | ||
// Currently in a workspace | ||
jest.spyOn(utils, 'getWorkspaceState').mockReturnValue({ requestWorkspaceId: 'workspace-id' }); | ||
|
||
const { wrappedClient, clientMock } = createWrappedClient(); | ||
|
||
clientMock.update.mockResolvedValue({ | ||
id: 'workspace-id', | ||
references: [], | ||
type: WORKSPACE_TYPE, | ||
attributes: { | ||
uiSettings: { | ||
defaultIndex: 'new-index-id', | ||
}, | ||
}, | ||
}); | ||
|
||
await wrappedClient.update('config', '3.0.0', { defaultIndex: 'new-index-id' }); | ||
|
||
expect(clientMock.update).toHaveBeenCalledWith( | ||
WORKSPACE_TYPE, | ||
'workspace-id', | ||
{ | ||
uiSettings: { defaultIndex: 'new-index-id' }, | ||
}, | ||
{} | ||
); | ||
}); | ||
|
||
it('should update global ui settings', async () => { | ||
// Currently NOT in a workspace | ||
jest.spyOn(utils, 'getWorkspaceState').mockReturnValue({}); | ||
|
||
const { wrappedClient, clientMock } = createWrappedClient(); | ||
|
||
await wrappedClient.update('config', '3.0.0', { defaultIndex: 'new-index-id' }); | ||
|
||
expect(clientMock.update).toHaveBeenCalledWith( | ||
'config', | ||
'3.0.0', | ||
{ | ||
defaultIndex: 'new-index-id', | ||
}, | ||
{} | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please resolve the license header issue as it suggested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated ;)