update users empty state (#1037)

This commit is contained in:
Jenny 2021-08-25 10:48:11 -04:00 committed by GitHub
parent 0fbd196380
commit 09f4279372
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 95 deletions

View file

@ -4,6 +4,8 @@ import {
ButtonVariant, ButtonVariant,
Label, Label,
PageSection, PageSection,
Text,
TextContent,
ToolbarItem, ToolbarItem,
Tooltip, Tooltip,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
@ -25,7 +27,6 @@ import { useAdminClient, useFetch } from "../context/auth/AdminClient";
import { useRealm } from "../context/realm-context/RealmContext"; import { useRealm } from "../context/realm-context/RealmContext";
import { emptyFormatter } from "../util"; import { emptyFormatter } from "../util";
import { toUser } from "./routes/User"; import { toUser } from "./routes/User";
import { SearchUser } from "./SearchUser";
import "./user-section.css"; import "./user-section.css";
type BruteUser = UserRepresentation & { type BruteUser = UserRepresentation & {
@ -40,9 +41,7 @@ export const UsersSection = () => {
const history = useHistory(); const history = useHistory();
const { url } = useRouteMatch(); const { url } = useRouteMatch();
const [listUsers, setListUsers] = useState(false); const [listUsers, setListUsers] = useState(false);
const [initialSearch, setInitialSearch] = useState("");
const [selectedRows, setSelectedRows] = useState<UserRepresentation[]>([]); const [selectedRows, setSelectedRows] = useState<UserRepresentation[]>([]);
const [search, setSearch] = useState("");
const [key, setKey] = useState(""); const [key, setKey] = useState("");
const refresh = () => setKey(`${new Date().getTime()}`); const refresh = () => setKey(`${new Date().getTime()}`);
@ -53,16 +52,12 @@ export const UsersSection = () => {
type: "org.keycloak.storage.UserStorageProvider", type: "org.keycloak.storage.UserStorageProvider",
}; };
return Promise.all([ return adminClient.components.find(testParams);
adminClient.components.find(testParams),
adminClient.users.count(),
]);
}, },
(response) => { (response) => {
//should *only* list users when no user federation is configured and uses count > 100 //should *only* list users when no user federation is configured
setListUsers( setListUsers(!(response.length > 0));
!((response[0] && response[0].length > 0) || response[1] > 100) refresh();
);
}, },
[] []
); );
@ -83,15 +78,16 @@ export const UsersSection = () => {
first: first!, first: first!,
max: max!, max: max!,
}; };
const searchParam = search || initialSearch || "";
const searchParam = search || "";
if (searchParam) { if (searchParam) {
params.search = searchParam; params.search = searchParam;
setSearch(searchParam);
} }
if (!listUsers && !searchParam) { if (!listUsers && !searchParam) {
return []; return [];
} }
try { try {
const users = await adminClient.users.find({ ...params }); const users = await adminClient.users.find({ ...params });
const realm = await adminClient.realms.findOne({ realm: realmName }); const realm = await adminClient.realms.findOne({ realm: realmName });
@ -179,14 +175,6 @@ export const UsersSection = () => {
variant="light" variant="light"
className="pf-u-p-0" className="pf-u-p-0"
> >
{!listUsers && !initialSearch && (
<SearchUser
onSearch={(search) => {
setInitialSearch(search);
}}
/>
)}
{(listUsers || initialSearch) && (
<KeycloakDataTable <KeycloakDataTable
key={key} key={key}
loader={loader} loader={loader}
@ -196,15 +184,17 @@ export const UsersSection = () => {
canSelectAll canSelectAll
onSelect={(rows) => setSelectedRows([...rows])} onSelect={(rows) => setSelectedRows([...rows])}
emptyState={ emptyState={
!search ? ( !listUsers ? (
<TextContent className="kc-search-users-text">
<Text>{t("searchForUserDescription")}</Text>
</TextContent>
) : (
<ListEmptyState <ListEmptyState
message={t("noUsersFound")} message={t("noUsersFound")}
instructions={t("emptyInstructions")} instructions={t("emptyInstructions")}
primaryActionText={t("createNewUser")} primaryActionText={t("createNewUser")}
onPrimaryAction={goToCreate} onPrimaryAction={goToCreate}
/> />
) : (
""
) )
} }
toolbarItem={ toolbarItem={
@ -261,7 +251,6 @@ export const UsersSection = () => {
}, },
]} ]}
/> />
)}
</PageSection> </PageSection>
</> </>
); );

View file

@ -3,6 +3,8 @@ export default {
title: "Users", title: "Users",
searchForUser: "Search user", searchForUser: "Search user",
startBySearchingAUser: "Start by searching for users", 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", createUser: "Create user",
createNewUser: "Create new user", createNewUser: "Create new user",
noUsersFound: "No users found", noUsersFound: "No users found",

View file

@ -83,3 +83,8 @@ div.pf-c-chip-group.kc-consents-chip-group
content: ""; content: "";
margin-left: var(--pf-global--spacer--sm); margin-left: var(--pf-global--spacer--sm);
} }
.kc-search-users-text {
margin-left: var(--pf-global--spacer--md);
color: var(--pf-global--Color--400);
}