-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previous preparation of some elements is needed: - The `User` data type needs the following parameters that will be managed in the 'Is a member of' section: - `memberof_group` - `memberof_netgroup` - `memberof_role` - `memberof_hbacrule` - `memberof_sudorule` - `memberof_subid` - The `useGettingGroupsQuery` endpoint wrapper to make the API call - The `UserGroupNew` data type for replacing the deprecated `UserGroup` one - The `useUserMemberOfData` hook to retrieve and parse the data - The `normalizeString` helper function to normalize string LDAP values Signed-off-by: Carla Martinez <[email protected]>
- Loading branch information
Showing
5 changed files
with
123 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// RPC | ||
import React from "react"; | ||
import { BatchRPCResponse, useGettingGroupsQuery } from "src/services/rpc"; | ||
// Data types | ||
import { UserGroupNew } from "src/utils/datatypes/globalDataTypes"; | ||
// Utils | ||
import { API_VERSION_BACKUP, normalizeString } from "src/utils/utils"; | ||
|
||
type MemberOfData = { | ||
isLoading: boolean; | ||
isFetching: boolean; | ||
refetch: () => void; | ||
userGroupsFullList: UserGroupNew[]; | ||
}; | ||
|
||
const useUserMemberOfData = ({ firstUserIdx, lastUserIdx }): MemberOfData => { | ||
// [API call] User groups | ||
// TODO: Normalize data to prevent array of arrays | ||
const userGroupsQuery = useGettingGroupsQuery({ | ||
searchValue: "", | ||
sizeLimit: 0, | ||
apiVersion: API_VERSION_BACKUP, | ||
startIdx: firstUserIdx, | ||
stopIdx: lastUserIdx, | ||
}); | ||
|
||
const [userGroupsFullList, setUserGroupsFullList] = React.useState< | ||
UserGroupNew[] | ||
>([]); | ||
const userGroupsData = userGroupsQuery.data || {}; | ||
const isUserGroupsLoading = userGroupsQuery.isLoading; | ||
|
||
React.useEffect(() => { | ||
if (userGroupsData !== undefined && !userGroupsQuery.isFetching) { | ||
const dataParsed = userGroupsData as BatchRPCResponse; | ||
const count = dataParsed.result.count; | ||
const results = dataParsed.result.results; | ||
|
||
const userGroupsTempList: UserGroupNew[] = []; | ||
|
||
for (let i = 0; i < count; i++) { | ||
userGroupsTempList.push({ | ||
cn: normalizeString(results[i].result.cn), | ||
gidnumber: normalizeString(results[i].result.gidnumber), | ||
description: normalizeString(results[i].result.description), | ||
dn: results[i].result.dn, | ||
}); | ||
} | ||
setUserGroupsFullList(userGroupsTempList); | ||
} | ||
}, [userGroupsData, userGroupsQuery.isFetching]); | ||
|
||
// [API call] Refresh | ||
const refetch = () => { | ||
userGroupsQuery.refetch(); | ||
}; | ||
|
||
// Return data | ||
return { | ||
isFetching: userGroupsQuery.isFetching, | ||
isLoading: isUserGroupsLoading, | ||
refetch, | ||
userGroupsFullList, | ||
} as MemberOfData; | ||
}; | ||
|
||
export { useUserMemberOfData }; |
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