From d0c6bc4cc137e53680c36562e8e05317a7a066f5 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 27 Oct 2021 11:19:13 +0200 Subject: [PATCH] fix issue by introducing toolbar for fedrated user (#1417) * fix issue by introducing toolbar for fedrated user fixes: #1416 * code review --- src/user/UsersSection.tsx | 164 ++++++++++++++++++++++++-------------- 1 file changed, 102 insertions(+), 62 deletions(-) diff --git a/src/user/UsersSection.tsx b/src/user/UsersSection.tsx index fd6f071c59..37774a71f0 100644 --- a/src/user/UsersSection.tsx +++ b/src/user/UsersSection.tsx @@ -4,23 +4,29 @@ import { ButtonVariant, Dropdown, DropdownItem, + EmptyState, + InputGroup, KebabToggle, Label, PageSection, Text, TextContent, + TextInput, + Toolbar, + ToolbarContent, ToolbarItem, Tooltip, } from "@patternfly/react-core"; import { ExclamationCircleIcon, InfoCircleIcon, + SearchIcon, WarningTriangleIcon, } from "@patternfly/react-icons"; import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; -import { Link, useHistory, useRouteMatch } from "react-router-dom"; +import { Link, useHistory } from "react-router-dom"; import { useAlerts } from "../components/alert/Alerts"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; @@ -32,6 +38,7 @@ import { emptyFormatter } from "../util"; import { toUser } from "./routes/User"; import "./user-section.css"; import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; +import { toAddUser } from "./routes/AddUser"; type BruteUser = UserRepresentation & { brute?: Record; @@ -43,8 +50,8 @@ export const UsersSection = () => { const { addAlert, addError } = useAlerts(); const { realm: realmName } = useRealm(); const history = useHistory(); - const { url } = useRouteMatch(); const [listUsers, setListUsers] = useState(false); + const [searchUser, setSearchUser] = useState(); const [realm, setRealm] = useState(); const [kebabOpen, setKebabOpen] = useState(false); const [selectedRows, setSelectedRows] = useState([]); @@ -87,7 +94,7 @@ export const UsersSection = () => { max: max!, }; - const searchParam = search || ""; + const searchParam = search || searchUser || ""; if (searchParam) { params.search = searchParam; } @@ -186,7 +193,60 @@ export const UsersSection = () => { ); }; - const goToCreate = () => history.push(`${url}/add-user`); + const goToCreate = () => history.push(toAddUser({ realm: realmName })); + + const toolbar = ( + <> + + + + {!realm?.bruteForceProtected ? ( + + + + ) : ( + + setKebabOpen(open)} />} + isOpen={kebabOpen} + isPlain + dropdownItems={[ + { + toggleDeleteDialog(); + setKebabOpen(false); + }} + > + {t("deleteUser")} + , + + { + toggleUnlockUsersDialog(); + setKebabOpen(false); + }} + > + {t("unlockAllUsers")} + , + ]} + /> + + )} + + ); return ( <> @@ -208,9 +268,43 @@ export const UsersSection = () => { onSelect={(rows) => setSelectedRows([...rows])} emptyState={ !listUsers ? ( - - {t("searchForUserDescription")} - + <> + + + + + { + setSearchUser(value); + }} + onKeyDown={(e) => { + if (e.key === "Enter") { + refresh(); + } + }} + /> + + + + {toolbar} + + + + + {t("searchForUserDescription")} + + + ) : ( { /> ) } - toolbarItem={ - <> - - - - {!realm?.bruteForceProtected && ( - - - - )} - {realm?.bruteForceProtected && ( - - setKebabOpen(!kebabOpen)} /> - } - isOpen={kebabOpen} - isPlain - dropdownItems={[ - { - toggleDeleteDialog(); - setKebabOpen(false); - }} - > - {t("deleteUser")} - , - - { - toggleUnlockUsersDialog(); - setKebabOpen(false); - }} - > - {t("unlockAllUsers")} - , - ]} - /> - - )} - - } + toolbarItem={toolbar} actions={[ { title: t("common:delete"),