forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: update workspace settings page UI #237
Closed
Closed
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cc8fde5
track usnaved changes
yuye-aws 2522c24
implement overview section
yuye-aws 8056e25
refactor: add utils, types and constants under workspace creator folder
yuye-aws ea273dc
bug fix: permission errors count and display
yuye-aws 6b91c94
add test for utils
yuye-aws 1ae2330
refactor: move permission constants outside
yuye-aws 86e2087
remove unnecessary test cases
yuye-aws a2014f9
implement errors count with use memo
yuye-aws 178a3e0
resolve conflicts
yuye-aws c4f433b
fix permission panel bug
yuye-aws 3f9bb36
rename util function
yuye-aws 26b14c8
rename permission type
yuye-aws 2532c42
rename permission type
yuye-aws 5bc5d3d
move constants declaration to workspace plugin
yuye-aws ac8f9fe
reimplement permission unsaved changes
yuye-aws 7c49019
support feature config match for unsaved changes count
yuye-aws 6be3cb9
Merge branch 'workspace' of github.com:ruanyl/OpenSearch-Dashboards i…
yuye-aws 13d2f85
remove unused import
yuye-aws 85bb883
avoid any when type casting
yuye-aws 54a9492
fix yarn start error
yuye-aws eb4f2fe
fix import error
yuye-aws 00502b9
optimize code
yuye-aws 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
69 changes: 69 additions & 0 deletions
69
src/plugins/workspace/public/components/workspace_creator/types.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,69 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { App, WorkspacePermissionMode } from '../../../../../core/public'; | ||
|
||
export interface WorkspaceFeature extends Pick<App, 'dependencies'> { | ||
id: string; | ||
name: string; | ||
} | ||
|
||
export interface WorkspaceFeatureGroup { | ||
name: string; | ||
features: WorkspaceFeature[]; | ||
} | ||
export interface WorkspaceFormSubmitData { | ||
name: string; | ||
description?: string; | ||
features?: string[]; | ||
color?: string; | ||
icon?: string; | ||
defaultVISTheme?: string; | ||
permissions: WorkspacePermissionSetting[]; | ||
} | ||
|
||
export interface WorkspaceFormData extends WorkspaceFormSubmitData { | ||
id: string; | ||
reserved?: boolean; | ||
} | ||
|
||
export type WorkspaceFormErrors = Omit< | ||
{ [key in keyof WorkspaceFormData]?: string }, | ||
'permissions' | ||
> & { | ||
userPermissions?: string[]; | ||
groupPermissions?: string[]; | ||
}; | ||
|
||
export enum WorkspacePermissionItemType { | ||
User = 'user', | ||
Group = 'group', | ||
} | ||
|
||
export interface UserPermissionSetting { | ||
type: WorkspacePermissionItemType.User; | ||
userId: string; | ||
modes: WorkspacePermissionMode[]; | ||
} | ||
|
||
export interface GroupPermissionSetting { | ||
type: WorkspacePermissionItemType.Group; | ||
group: string; | ||
modes: WorkspacePermissionMode[]; | ||
} | ||
|
||
export type WorkspacePermissionSetting = UserPermissionSetting | GroupPermissionSetting; | ||
|
||
// when editing, attributes could be undefined in workspace form | ||
export type WorkspaceFormEditingData = Partial< | ||
Omit<WorkspaceFormSubmitData, 'permissions'> & { | ||
userPermissions: Array<Partial<UserPermissionSetting>>; | ||
groupPermissions: Array<Partial<GroupPermissionSetting>>; | ||
} | ||
>; | ||
|
||
export type UserOrGroupPermissionEditingData = Array< | ||
Partial<{ id: string; modes: WorkspacePermissionMode[] }> | ||
>; |
227 changes: 227 additions & 0 deletions
227
src/plugins/workspace/public/components/workspace_creator/utils.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,227 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
isValidWorkspacePermissionSetting, | ||
getErrorsCount, | ||
getUserAndGroupPermissions, | ||
getUnsavedChangesCount, | ||
getPermissionModeId, | ||
getPermissionErrors, | ||
} from './utils'; | ||
import { | ||
UserPermissionSetting, | ||
WorkspaceFormErrors, | ||
WorkspacePermissionItemType, | ||
WorkspacePermissionSetting, | ||
} from './types'; | ||
import { WorkspacePermissionMode, PermissionModeId } from '../../../../../core/public'; | ||
|
||
describe('isValidWorkspacePermissionSetting', () => { | ||
it('should return true with valid user permission setting', () => { | ||
expect( | ||
isValidWorkspacePermissionSetting({ | ||
type: WorkspacePermissionItemType.User, | ||
userId: 'test user id', | ||
modes: [WorkspacePermissionMode.Write, WorkspacePermissionMode.LibraryWrite], | ||
}) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return true with valid group permission setting', () => { | ||
expect( | ||
isValidWorkspacePermissionSetting({ | ||
type: WorkspacePermissionItemType.Group, | ||
group: 'test group id', | ||
modes: [WorkspacePermissionMode.Write, WorkspacePermissionMode.LibraryWrite], | ||
}) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return false with empty permission modes', () => { | ||
expect( | ||
isValidWorkspacePermissionSetting({ | ||
type: WorkspacePermissionItemType.User, | ||
userId: 'test user id', | ||
modes: [], | ||
}) | ||
).toBe(false); | ||
}); | ||
|
||
it('should return false with incorrect permission type (expect user)', () => { | ||
expect( | ||
isValidWorkspacePermissionSetting({ | ||
type: WorkspacePermissionItemType.Group, | ||
userId: 'test user id', | ||
modes: [], | ||
} as any) | ||
).toBe(false); | ||
}); | ||
|
||
it('should return false with incorrect permission type 2 (expect group)', () => { | ||
expect( | ||
isValidWorkspacePermissionSetting({ | ||
type: WorkspacePermissionItemType.User, | ||
group: 'test user id', | ||
modes: [], | ||
} as any) | ||
).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getErrorsCount', () => { | ||
it('should return error count in name, description and permissions', () => { | ||
const workspaceFormErrors: WorkspaceFormErrors = { | ||
name: 'test name error', | ||
description: 'test description error', | ||
userPermissions: ['test user permission error 1'], | ||
groupPermissions: ['test group permission error 1', 'test group permission error 2'], | ||
}; | ||
expect(getErrorsCount(workspaceFormErrors)).toBe(5); | ||
}); | ||
}); | ||
|
||
describe('getUserAndGroupPermissions', () => { | ||
it('should split user and group permissions from all permissions', () => { | ||
const permissions = [ | ||
{ modes: [] }, | ||
{ userId: 'test user id 1' }, | ||
{ group: 'test group id 1' }, | ||
{ type: WorkspacePermissionItemType.User, userId: 'test user id 2', modes: [] }, | ||
{ type: WorkspacePermissionItemType.Group, group: 'test group id 2', modes: [] }, | ||
{ type: WorkspacePermissionItemType.Group, group: 'test group id 3', modes: [] }, | ||
]; | ||
expect(getUserAndGroupPermissions(permissions)).toStrictEqual([ | ||
[{ id: 'test user id 2', modes: [] }], | ||
[ | ||
{ id: 'test group id 2', modes: [] }, | ||
{ id: 'test group id 3', modes: [] }, | ||
], | ||
]); | ||
}); | ||
}); | ||
|
||
describe('getUnsavedChangesCount', () => { | ||
it('should return number of unsaved changes in workspace metadata', () => { | ||
const initialFormData = { | ||
id: 'test workspace id', | ||
name: 'test workspace name', | ||
description: 'test workspace description', | ||
permissions: [], | ||
}; | ||
const currentFormData = { | ||
name: 'changed workspace name', | ||
description: 'changed workspace description', | ||
}; | ||
expect(getUnsavedChangesCount(initialFormData, currentFormData)).toBe(2); | ||
}); | ||
|
||
it('should return number of unsaved changes in workspace features', () => { | ||
const initialFormData = { | ||
id: 'test workspace id', | ||
name: 'test workspace name', | ||
permissions: [], | ||
features: ['feature 1', 'feature 2', 'feature 3'], | ||
}; | ||
const currentFormData = { | ||
name: 'test workspace name', | ||
features: ['feature 1', 'feature 2', 'feature 4'], | ||
}; | ||
// 1 deleted feature and 1 added feature | ||
expect(getUnsavedChangesCount(initialFormData, currentFormData)).toBe(2); | ||
}); | ||
|
||
it('should return number of unsaved changes in workspace permissions', () => { | ||
const initialFormData = { | ||
id: 'test workspace id', | ||
name: 'test workspace name', | ||
permissions: [ | ||
{ | ||
userId: 'test user id 1', | ||
type: WorkspacePermissionItemType.User, | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
{ | ||
group: 'test group id', | ||
type: WorkspacePermissionItemType.Group, | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
] as WorkspacePermissionSetting[], | ||
}; | ||
const currentFormData = { | ||
name: 'test workspace name', | ||
userPermissions: [ | ||
{ | ||
userId: 'test user id 1', | ||
type: WorkspacePermissionItemType.User, | ||
modes: [WorkspacePermissionMode.LibraryWrite, WorkspacePermissionMode.Write], | ||
}, | ||
] as UserPermissionSetting[], | ||
groupPermissions: [], | ||
}; | ||
// 1 deleted permission and 1 edited permission | ||
expect(getUnsavedChangesCount(initialFormData, currentFormData)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getPermissionModeId', () => { | ||
it('should return Read with empty permission', () => { | ||
expect(getPermissionModeId([])).toBe(PermissionModeId.Read); | ||
}); | ||
|
||
it('should return Read with [LibraryRead, Read]', () => { | ||
expect( | ||
getPermissionModeId([WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read]) | ||
).toBe(PermissionModeId.Read); | ||
}); | ||
|
||
it('should return ReadAndWrite with [LibraryWrite, Read],', () => { | ||
expect( | ||
getPermissionModeId([WorkspacePermissionMode.LibraryWrite, WorkspacePermissionMode.Read]) | ||
).toBe(PermissionModeId.ReadAndWrite); | ||
}); | ||
|
||
it('should return ReadAndWrite with [LibraryWrite, Read]', () => { | ||
expect( | ||
getPermissionModeId([WorkspacePermissionMode.LibraryWrite, WorkspacePermissionMode.Write]) | ||
).toBe(PermissionModeId.Admin); | ||
}); | ||
}); | ||
|
||
describe('getPermissionErrors', () => { | ||
it('should get permission errors for both users and groups', () => { | ||
const permissions = [ | ||
{}, | ||
{ type: WorkspacePermissionItemType.User }, | ||
{ | ||
type: WorkspacePermissionItemType.User, | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
{ | ||
type: WorkspacePermissionItemType.Group, | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
{ | ||
userId: 'test user id', | ||
type: WorkspacePermissionItemType.User, | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
{ | ||
group: 'test group id', | ||
type: WorkspacePermissionItemType.Group, | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
]; | ||
const expectedPermissionErrors = [ | ||
'Invalid type', | ||
'Invalid permission modes', | ||
'Invalid userId', | ||
'Invalid user group', | ||
]; | ||
expect(getPermissionErrors(permissions)).toEqual( | ||
expect.arrayContaining(expectedPermissionErrors) | ||
); | ||
}); | ||
}); |
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.
I'd rename it to
PermissionFieldData
, that becomesAnd in
getUserAndGroupPermissions
function, I will doThere 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.
How about declaring both variables in
PermissionFieldData
and create a new type for editing permission data:type PermissionEditingData = Array<Partial<PermissionFieldData>>;