From 09f4279372dd797ae70bf81d0f2525b814f7908c Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Wed, 25 Aug 2021 10:48:11 -0400 Subject: [PATCH] update users empty state (#1037) --- src/user/UsersSection.tsx | 179 ++++++++++++++++++-------------------- src/user/messages.ts | 2 + src/user/user-section.css | 5 ++ 3 files changed, 91 insertions(+), 95 deletions(-) diff --git a/src/user/UsersSection.tsx b/src/user/UsersSection.tsx index 55f4167fc8..1f975b6b42 100644 --- a/src/user/UsersSection.tsx +++ b/src/user/UsersSection.tsx @@ -4,6 +4,8 @@ import { ButtonVariant, Label, PageSection, + Text, + TextContent, ToolbarItem, Tooltip, } from "@patternfly/react-core"; @@ -25,7 +27,6 @@ import { useAdminClient, useFetch } from "../context/auth/AdminClient"; import { useRealm } from "../context/realm-context/RealmContext"; import { emptyFormatter } from "../util"; import { toUser } from "./routes/User"; -import { SearchUser } from "./SearchUser"; import "./user-section.css"; type BruteUser = UserRepresentation & { @@ -40,9 +41,7 @@ export const UsersSection = () => { const history = useHistory(); const { url } = useRouteMatch(); const [listUsers, setListUsers] = useState(false); - const [initialSearch, setInitialSearch] = useState(""); const [selectedRows, setSelectedRows] = useState([]); - const [search, setSearch] = useState(""); const [key, setKey] = useState(""); const refresh = () => setKey(`${new Date().getTime()}`); @@ -53,16 +52,12 @@ export const UsersSection = () => { type: "org.keycloak.storage.UserStorageProvider", }; - return Promise.all([ - adminClient.components.find(testParams), - adminClient.users.count(), - ]); + return adminClient.components.find(testParams); }, (response) => { - //should *only* list users when no user federation is configured and uses count > 100 - setListUsers( - !((response[0] && response[0].length > 0) || response[1] > 100) - ); + //should *only* list users when no user federation is configured + setListUsers(!(response.length > 0)); + refresh(); }, [] ); @@ -83,15 +78,16 @@ export const UsersSection = () => { first: first!, max: max!, }; - const searchParam = search || initialSearch || ""; + + const searchParam = search || ""; if (searchParam) { params.search = searchParam; - setSearch(searchParam); } if (!listUsers && !searchParam) { return []; } + try { const users = await adminClient.users.find({ ...params }); const realm = await adminClient.realms.findOne({ realm: realmName }); @@ -179,89 +175,82 @@ export const UsersSection = () => { variant="light" className="pf-u-p-0" > - {!listUsers && !initialSearch && ( - { - setInitialSearch(search); - }} - /> - )} - {(listUsers || initialSearch) && ( - setSelectedRows([...rows])} - emptyState={ - !search ? ( - - ) : ( - "" - ) - } - toolbarItem={ - <> - - - - - - - - } - actions={[ - { - title: t("common:delete"), - onRowClick: (user) => { - setSelectedRows([user]); - toggleDeleteDialog(); - }, + setSelectedRows([...rows])} + emptyState={ + !listUsers ? ( + + {t("searchForUserDescription")} + + ) : ( + + ) + } + toolbarItem={ + <> + + + + + + + + } + actions={[ + { + title: t("common:delete"), + onRowClick: (user) => { + setSelectedRows([user]); + toggleDeleteDialog(); }, - ]} - columns={[ - { - name: "username", - displayKey: "users:username", - cellRenderer: UserDetailLink, - }, - { - name: "email", - displayKey: "users:email", - cellRenderer: ValidatedEmail, - }, - { - name: "lastName", - displayKey: "users:lastName", - cellFormatters: [emptyFormatter()], - }, - { - name: "firstName", - displayKey: "users:firstName", - cellFormatters: [emptyFormatter()], - }, - { - name: "status", - displayKey: "users:status", - cellRenderer: StatusRow, - }, - ]} - /> - )} + }, + ]} + columns={[ + { + name: "username", + displayKey: "users:username", + cellRenderer: UserDetailLink, + }, + { + name: "email", + displayKey: "users:email", + cellRenderer: ValidatedEmail, + }, + { + name: "lastName", + displayKey: "users:lastName", + cellFormatters: [emptyFormatter()], + }, + { + name: "firstName", + displayKey: "users:firstName", + cellFormatters: [emptyFormatter()], + }, + { + name: "status", + displayKey: "users:status", + cellRenderer: StatusRow, + }, + ]} + /> ); diff --git a/src/user/messages.ts b/src/user/messages.ts index 55ecb78c00..f2262d8590 100644 --- a/src/user/messages.ts +++ b/src/user/messages.ts @@ -3,6 +3,8 @@ export default { title: "Users", searchForUser: "Search user", startBySearchingAUser: "Start by searching for users", + searchForUserDescription: + "This realm has a federated provider. Viewing all users may cause the system to slow down. Please search for a user above.", createUser: "Create user", createNewUser: "Create new user", noUsersFound: "No users found", diff --git a/src/user/user-section.css b/src/user/user-section.css index 8c38d37c2b..fbe2871ba7 100644 --- a/src/user/user-section.css +++ b/src/user/user-section.css @@ -83,3 +83,8 @@ div.pf-c-chip-group.kc-consents-chip-group content: ""; margin-left: var(--pf-global--spacer--sm); } + +.kc-search-users-text { + margin-left: var(--pf-global--spacer--md); + color: var(--pf-global--Color--400); +}