Skip to content

Commit

Permalink
'Refresh' button functionality (User groups)
Browse files Browse the repository at this point in the history
The 'Refresh' button should refetch the
data related to the user groups of a given
user. The solution has been implemented
taking the `refetch` functionality.

Signed-off-by: Carla Martinez <[email protected]>
  • Loading branch information
carma12 committed Mar 7, 2024
1 parent 598149e commit c3cc12f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/components/MemberOf/MemberOfUserGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function filterUserGroupsData<Type extends TypeWithCN>(

interface MemberOfUserGroupsProps {
user: Partial<User>;
isUserDataLoading: boolean;
onRefreshUserData: () => void;
}

const MemberOfUserGroups = (props: MemberOfUserGroupsProps) => {
Expand Down Expand Up @@ -85,6 +87,10 @@ const MemberOfUserGroups = (props: MemberOfUserGroupsProps) => {
}
}, [fullUserGroupsQuery]);

React.useEffect(() => {
fullUserGroupsQuery.refetch();
}, [props.user]);

const [groupsNamesSelected, setGroupsNamesSelected] = React.useState<
string[]
>([]);
Expand Down Expand Up @@ -121,6 +127,10 @@ const MemberOfUserGroups = (props: MemberOfUserGroupsProps) => {
};
const availableUserGroupsItems: AvailableItems[] = parseAvailableItems();

// Buttons functionality
// - Refresh
const isRefreshButtonEnabled = !props.isUserDataLoading;

// 'Add' function
// TODO: Adapt to work with real data
const onAddUserGroup = (items: AvailableItems[]) => {
Expand All @@ -145,7 +155,8 @@ const MemberOfUserGroups = (props: MemberOfUserGroupsProps) => {
<MemberOfToolbarUserGroups
searchText={searchValue}
onSearchTextChange={setSearchValue}
refreshButtonEnabled={true}
refreshButtonEnabled={isRefreshButtonEnabled}
onRefreshButtonClick={props.onRefreshUserData}
deleteButtonEnabled={someItemSelected}
onDeleteButtonClick={() => setShowDeleteModal(true)}
addButtonEnabled={true}
Expand Down
10 changes: 9 additions & 1 deletion src/pages/ActiveUsers/UserMemberOf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const UserMemberOf = (props: PropsToUserMemberOf) => {
}
}, [userData, userQuery.isFetching]);

const onRefreshUserData = () => {
userQuery.refetch();
};

// 'User groups' length to show in tab badge
const [userGroupsLength, setUserGroupLength] = React.useState(0);

Expand Down Expand Up @@ -454,7 +458,11 @@ const UserMemberOf = (props: PropsToUserMemberOf) => {
</TabTitleText>
}
>
<MemberOfUserGroups user={user} />
<MemberOfUserGroups
user={user}
isUserDataLoading={userQuery.isFetching}
onRefreshUserData={onRefreshUserData}
/>
</Tab>
<Tab
eventKey={1}
Expand Down

0 comments on commit c3cc12f

Please sign in to comment.