-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Summary of group permissions in the Project settings page (#3629)
Co-authored-by: kyle-ssg <[email protected]>
- Loading branch information
1 parent
8c25cd6
commit da12c93
Showing
8 changed files
with
308 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const userGroupPermissionService = service | ||
.enhanceEndpoints({ addTagTypes: ['UserGroupPermission'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
getUserGroupPermission: builder.query< | ||
Res['userGroupPermissions'], | ||
Req['getUserGroupPermission'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'UserGroupPermission' }], | ||
query: (query: Req['getUserGroupPermission']) => ({ | ||
url: `projects/${query.project_id}/user-group-permissions/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function getUserGroupPermission( | ||
store: any, | ||
data: Req['getUserGroupPermission'], | ||
options?: Parameters< | ||
typeof userGroupPermissionService.endpoints.getUserGroupPermission.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
userGroupPermissionService.endpoints.getUserGroupPermission.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useGetUserGroupPermissionQuery, | ||
// END OF EXPORTS | ||
} = userGroupPermissionService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetUserGroupPermissionQuery({ id: 2 }, {}) //get hook | ||
const [createUserGroupPermission, { isLoading, data, isSuccess }] = useCreateUserGroupPermissionMutation() //create hook | ||
userGroupPermissionService.endpoints.getUserGroupPermission.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
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,42 @@ | ||
import React, { FC } from 'react' | ||
import Tooltip from './Tooltip' | ||
import Utils from 'common/utils/utils' | ||
|
||
type PermissionsSummaryListType = { | ||
isAdmin: boolean | ||
permissions: string[] | null | undefined | ||
numberToTruncate?: number | ||
} | ||
|
||
const PermissionsSummaryList: FC<PermissionsSummaryListType> = ({ | ||
isAdmin, | ||
numberToTruncate = 3, | ||
permissions, | ||
}) => { | ||
const { items, truncatedItems } = Utils.getPermissionList( | ||
isAdmin, | ||
permissions, | ||
numberToTruncate, | ||
) | ||
|
||
return ( | ||
<div className='flex-row gap-1 align-items-center'> | ||
{items.map((value: string, i: number) => ( | ||
<div key={i} className='chip chip--xs'> | ||
{value} | ||
</div> | ||
))} | ||
{!!truncatedItems.length && ( | ||
<Tooltip | ||
title={ | ||
<span className='chip chip--xs'>+{truncatedItems.length}</span> | ||
} | ||
> | ||
{truncatedItems.join(', ')} | ||
</Tooltip> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default PermissionsSummaryList |
Oops, something went wrong.