Skip to content
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

[Is a member of][User groups] Sync with API data #264

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
430 changes: 430 additions & 0 deletions src/components/MemberOf/MemberOfTableNew.tsx

Large diffs are not rendered by default.

629 changes: 629 additions & 0 deletions src/components/MemberOf/MemberOfToolbarNew.tsx

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions src/hooks/useUserMemberOfData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RPC
import React from "react";
import { BatchRPCResponse, useGetUserGroupsQuery } 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 = (): MemberOfData => {
// [API call] User groups
// TODO: Normalize data to prevent array of arrays
const userGroupsQuery = useGetUserGroupsQuery({
searchValue: "",
sizeLimit: 0,
apiVersion: API_VERSION_BACKUP,
});

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 };
Loading
Loading