Use route functions for navigation in groups (#1474)

* Use route functions for navigation in groups

* pass testid to link
This commit is contained in:
Jon Koops 2021-11-09 18:53:06 +01:00 committed by GitHub
parent c31b357429
commit 386201595b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View file

@ -23,6 +23,7 @@ import { getLastId } from "./groupIdUtils";
import { GroupPickerDialog } from "../components/group/GroupPickerDialog"; 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";
export const GroupTable = () => { export const GroupTable = () => {
const { t } = useTranslation("groups"); const { t } = useTranslation("groups");
@ -60,7 +61,7 @@ export const GroupTable = () => {
} }
if (!groupsData) { if (!groupsData) {
history.push(`/${realm}/groups`); history.push(toGroups({ realm }));
} }
return groupsData || []; return groupsData || [];

View file

@ -1,5 +1,5 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { useHistory, useLocation } from "react-router-dom"; import { Link, useHistory, useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
DropdownItem, DropdownItem,
@ -23,6 +23,8 @@ import { getId, getLastId } from "./groupIdUtils";
import { Members } from "./Members"; import { Members } from "./Members";
import { GroupAttributes } from "./GroupAttributes"; import { GroupAttributes } from "./GroupAttributes";
import { GroupsModal } from "./GroupsModal"; import { GroupsModal } from "./GroupsModal";
import { toGroups } from "./routes/Groups";
import { toGroupsSearch } from "./routes/GroupsSearch";
import "./GroupsSection.css"; import "./GroupsSection.css";
@ -80,12 +82,13 @@ export default function GroupsSection() {
const SearchDropdown = ( const SearchDropdown = (
<DropdownItem <DropdownItem
data-testid="searchGroup"
key="searchGroup" key="searchGroup"
onClick={() => history.push(`/${realm}/groups/search`)} component={
> <Link data-testid="searchGroup" to={toGroupsSearch({ realm })}>
{t("searchGroup")} {t("searchGroup")}
</DropdownItem> </Link>
}
/>
); );
return ( return (
@ -120,12 +123,7 @@ export default function GroupsSection() {
key="deleteGroup" key="deleteGroup"
onClick={() => { onClick={() => {
deleteGroup({ id }); deleteGroup({ id });
history.push( history.push(toGroups({ realm }));
location.pathname.substr(
0,
location.pathname.lastIndexOf("/")
)
);
}} }}
> >
{t("deleteGroup")} {t("deleteGroup")}

View file

@ -15,6 +15,7 @@ import { useAlerts } from "../components/alert/Alerts";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
import { emptyFormatter } from "../util"; import { emptyFormatter } from "../util";
import { toAddUser } from "../user/routes/AddUser";
import _ from "lodash"; import _ from "lodash";
type MemberModalProps = { type MemberModalProps = {
@ -30,7 +31,7 @@ export const MemberModal = ({ groupId, onClose }: MemberModalProps) => {
const history = useHistory(); const history = useHistory();
const { realm } = useRealm(); const { realm } = useRealm();
const goToCreate = () => history.push(`/${realm}/users/add-user`); const goToCreate = () => history.push(toAddUser({ realm }));
const loader = async (first?: number, max?: number, search?: string) => { const loader = async (first?: number, max?: number, search?: string) => {
const members = await adminClient.groups.listMembers({ id: groupId }); const members = await adminClient.groups.listMembers({ id: groupId });