Avoid errors in Groups section. (#2414)

This commit is contained in:
Stan Silvert 2022-04-11 05:22:43 -04:00 committed by GitHub
parent 1d3efdc1b2
commit fcc514a12f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 74 deletions

View file

@ -24,6 +24,7 @@ import { GroupPickerDialog } from "../components/group/GroupPickerDialog";
import { useSubGroups } from "./SubGroupsContext"; import { useSubGroups } from "./SubGroupsContext";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { toGroups } from "./routes/Groups"; import { toGroups } from "./routes/Groups";
import { useAccess } from "../context/access/Access";
export const GroupTable = () => { export const GroupTable = () => {
const { t } = useTranslation("groups"); const { t } = useTranslation("groups");
@ -45,6 +46,9 @@ export const GroupTable = () => {
const location = useLocation(); const location = useLocation();
const id = getLastId(location.pathname); const id = getLastId(location.pathname);
const { hasAccess } = useAccess();
const isManager = hasAccess("manage-users", "query-clients");
const loader = async () => { const loader = async () => {
let groupsData = undefined; let groupsData = undefined;
if (id) { if (id) {
@ -85,7 +89,10 @@ export const GroupTable = () => {
refresh(); refresh();
}; };
const GroupNameCell = (group: GroupRepresentation) => ( const GroupNameCell = (group: GroupRepresentation) => {
if (!isManager) return <span>{group.name}</span>;
return (
<Link <Link
key={group.id} key={group.id}
to={`${location.pathname}/${group.id}`} to={`${location.pathname}/${group.id}`}
@ -96,6 +103,7 @@ export const GroupTable = () => {
{group.name} {group.name}
</Link> </Link>
); );
};
const handleModalToggle = () => { const handleModalToggle = () => {
setIsCreateModalOpen(!isCreateModalOpen); setIsCreateModalOpen(!isCreateModalOpen);
@ -120,6 +128,7 @@ export const GroupTable = () => {
ariaLabelKey="groups:groups" ariaLabelKey="groups:groups"
searchPlaceholderKey="groups:searchForGroups" searchPlaceholderKey="groups:searchForGroups"
toolbarItem={ toolbarItem={
isManager && (
<> <>
<ToolbarItem> <ToolbarItem>
<Button <Button
@ -155,8 +164,12 @@ export const GroupTable = () => {
/> />
</ToolbarItem> </ToolbarItem>
</> </>
)
} }
actions={[ actions={
!isManager
? []
: [
{ {
title: t("moveTo"), title: t("moveTo"),
onRowClick: async (group) => { onRowClick: async (group) => {
@ -172,7 +185,8 @@ export const GroupTable = () => {
return true; return true;
}, },
}, },
]} ]
}
columns={[ columns={[
{ {
name: "name", name: "name",

View file

@ -24,6 +24,7 @@ import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
import { GroupPath } from "../components/group/GroupPath"; import { GroupPath } from "../components/group/GroupPath";
import { useSubGroups } from "./SubGroupsContext"; import { useSubGroups } from "./SubGroupsContext";
import { ViewHeader } from "../components/view-header/ViewHeader"; import { ViewHeader } from "../components/view-header/ViewHeader";
import { useAccess } from "../context/access/Access";
type SearchGroup = GroupRepresentation & { type SearchGroup = GroupRepresentation & {
link?: string; link?: string;
@ -40,6 +41,9 @@ export default function SearchGroups() {
const [key, setKey] = useState(0); const [key, setKey] = useState(0);
const refresh = () => setKey(new Date().getTime()); const refresh = () => setKey(new Date().getTime());
const { hasAccess } = useAccess();
const isManager = hasAccess("manage-users", "query-clients");
const { setSubGroups } = useSubGroups(); const { setSubGroups } = useSubGroups();
useEffect( useEffect(
() => setSubGroups([{ name: t("searchGroups"), id: "search" }]), () => setSubGroups([{ name: t("searchGroups"), id: "search" }]),
@ -61,7 +65,10 @@ export default function SearchGroups() {
} }
}; };
const GroupNameCell = (group: SearchGroup) => ( const GroupNameCell = (group: SearchGroup) => {
if (!isManager) return <span>{group.name}</span>;
return (
<Link <Link
key={group.id} key={group.id}
to={`/${realm}/groups/search/${group.link}`} to={`/${realm}/groups/search/${group.link}`}
@ -72,6 +79,7 @@ export default function SearchGroups() {
{group.name} {group.name}
</Link> </Link>
); );
};
const flatten = ( const flatten = (
groups: GroupRepresentation[], groups: GroupRepresentation[],