Skip to content

Commit

Permalink
chore: Revert "remove circular dependence + correctly derive values" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
keita-determined authored Jun 27, 2024
1 parent bd633f1 commit b778712
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions webui/react/src/pages/WorkspaceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ const WorkspaceDetails: React.FC = () => {
const loadableUsers = useObservable(userStore.getUsers());
const users = loadableUsers.getOrElse([]);
const { tab, workspaceId: workspaceID } = useParams<Params>();
const [groups, setGroups] = useState<V1GroupSearchResult[]>([]);
const [groups, setGroups] = useState<V1GroupSearchResult[]>();
const [usersAssignedDirectly, setUsersAssignedDirectly] = useState<User[]>([]);
const [groupsAssignedDirectly, setGroupsAssignedDirectly] = useState<V1Group[]>([]);
const usersAssignedDirectlyIds = useMemo(() => {
return new Set(usersAssignedDirectly.map((user) => user.id));
}, [usersAssignedDirectly]);
const groupsAssignedDirectlyIds = useMemo(() => {
return new Set(groupsAssignedDirectly.map((group) => group.groupId).filter((id) => !!id));
}, [groupsAssignedDirectly]);
const [usersAssignedDirectlyIds, setUsersAssignedDirectlyIds] = useState<Set<number>>(
new Set<number>(),
);
const [groupsAssignedDirectlyIds, setGroupsAssignedDirectlyIds] = useState<Set<number>>(
new Set<number>(),
);
const [rolesAssignableToScope, setRolesAssignableToScope] = useState<V1Role[]>([]);
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
const [nameFilter, setNameFilter] = useState<string>();
Expand Down Expand Up @@ -103,13 +103,17 @@ const WorkspaceDetails: React.FC = () => {

const response = await getWorkspaceMembers({ nameFilter, workspaceId: id });
const activeUsers = response.usersAssignedDirectly.filter((u) => u.isActive);
setUsersAssignedDirectly((prev) => (_.isEqual(prev, activeUsers) ? prev : activeUsers));
setGroupsAssignedDirectly((prev) =>
_.isEqual(prev, response.groups) ? prev : response.groups,
);
setWorkspaceAssignments((prev) =>
_.isEqual(prev, response.assignments) ? prev : response.assignments,
);
const newGroupIds = new Set<number>();
setUsersAssignedDirectly(activeUsers);
setUsersAssignedDirectlyIds(new Set(activeUsers.map((user) => user.id)));
setGroupsAssignedDirectly(response.groups);
response.groups.forEach((group) => {
if (group.groupId) {
newGroupIds.add(group.groupId);
}
});
setGroupsAssignedDirectlyIds(newGroupIds);
setWorkspaceAssignments(response.assignments);
}, [id, nameFilter, rbacEnabled]);

const fetchRolesAssignableToScope = useCallback(async (): Promise<void> => {
Expand Down

0 comments on commit b778712

Please sign in to comment.