-
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 original `UserGroup` data type has been replaced by the `UserGroupOld` one. All the files that use that type have been adapted - The new `UserGroup` type will contain the new data structure. - 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
15 changed files
with
160 additions
and
39 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
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,67 @@ | ||
// RPC | ||
import React from "react"; | ||
import { BatchRPCResponse, useGettingGroupsQuery } from "src/services/rpc"; | ||
// Data types | ||
import { UserGroup } from "src/utils/datatypes/globalDataTypes"; | ||
// Utils | ||
import { API_VERSION_BACKUP, normalizeString } from "src/utils/utils"; | ||
|
||
type MemberOfData = { | ||
isLoading: boolean; | ||
isFetching: boolean; | ||
refetch: () => void; | ||
userGroupsFullList: UserGroup[]; | ||
}; | ||
|
||
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< | ||
UserGroup[] | ||
>([]); | ||
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: UserGroup[] = []; | ||
|
||
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
Oops, something went wrong.