/* eslint-disable */ // @ts-nocheck import type GroupRepresentation from "@keycloak/keycloak-admin-client/lib/defs/groupRepresentation"; import { GroupQuery, SubGroupQuery, } from "@keycloak/keycloak-admin-client/lib/resources/groups"; import { SearchInput, ToolbarItem } from "../../shared/@patternfly/react-core"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useLocation } from "react-router-dom"; import { ListEmptyState } from "../../shared/keycloak-ui-shared"; import { KeycloakDataTable } from "../../shared/keycloak-ui-shared"; import { useAccess } from "../context/access/Access"; import useToggle from "../utils/useToggle"; import { GroupsModal } from "./GroupsModal"; import { useSubGroups } from "./SubGroupsContext"; import { DeleteGroup } from "./components/DeleteGroup"; import { GroupToolbar } from "./components/GroupToolbar"; import { MoveDialog } from "./components/MoveDialog"; import { getLastId } from "./groupIdUtils"; import { useGroupResource } from "../context/group-resource/GroupResourceContext"; type GroupTableProps = { refresh: () => void; }; export const GroupTable = ({ refresh: viewRefresh }: GroupTableProps) => { const groups = useGroupResource(); const { t } = useTranslation(); const [selectedRows, setSelectedRows] = useState([]); const [rename, setRename] = useState(); const [isCreateModalOpen, toggleCreateOpen] = useToggle(); const [duplicateId, setDuplicateId] = useState(); const [showDelete, toggleShowDelete] = useToggle(); const [move, setMove] = useState(); const { currentGroup } = useSubGroups(); const [key, setKey] = useState(0); const refresh = () => setKey(key + 1); const [search, setSearch] = useState(); const location = useLocation(); const id = getLastId(location.pathname); const { hasAccess } = useAccess(); const isManager = hasAccess("manage-users") || currentGroup()?.access?.manage; const loader = async (first?: number, max?: number) => { let groupsData = undefined; if (id) { const args: SubGroupQuery = { search: search || "", first: first, max: max, parentId: id, }; groupsData = await groups.listSubGroups(args); } else { const args: GroupQuery = { search: search || "", first: first || undefined, max: max || undefined, }; groupsData = await groups.find(args); } return groupsData; }; return ( <> { refresh(); viewRefresh(); setSelectedRows([]); }} /> {rename && ( { refresh(); viewRefresh(); }} handleModalToggle={() => setRename(undefined)} /> )} {isCreateModalOpen && ( { setSelectedRows([]); refresh(); viewRefresh(); }} /> )} {duplicateId && ( { refresh(); viewRefresh(); }} handleModalToggle={() => setDuplicateId(undefined)} /> )} {move && ( { setMove(undefined); refresh(); viewRefresh(); }} onClose={() => setMove(undefined)} /> )} setSelectedRows([...rows])} canSelectAll loader={loader} ariaLabelKey="groups" isPaginated isSearching={!!search} toolbarItem={ <> { setSearch(value); if (value === "") { refresh(); } }} onSearch={refresh} onClear={() => { setSearch(""); refresh(); }} /> } actions={ !isManager ? [] : [ { title: t("edit"), onRowClick: async (group) => { setRename(group); return false; }, }, { title: t("moveTo"), onRowClick: async (group) => { setMove(group); return false; }, }, { title: t("createChildGroup"), onRowClick: async (group) => { setSelectedRows([group]); toggleCreateOpen(); return false; }, }, ...(!id ? [ { title: t("duplicate"), onRowClick: async (group: GroupRepresentation) => { setDuplicateId(group.id); return false; }, }, ] : []), { isSeparator: true, }, { title: t("delete"), onRowClick: async (group: GroupRepresentation) => { setSelectedRows([group]); toggleShowDelete(); return true; }, }, ] } columns={[ { name: "name", displayKey: "groupName", cellRenderer: (group) => groups.isOrgGroups() || group.access?.view ? ( // The org UI does not use access {group.name} ) : ( {group.name} ), }, ]} emptyState={ } /> ); };