fixed breadcrumb for search and seach box distance (#998)

Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Erik Jan de Wit 2021-08-16 14:35:39 +02:00 committed by GitHub
parent 7865a2b0b1
commit b5e2fb802c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 71 deletions

View file

@ -29,9 +29,11 @@ export const GroupBreadCrumbs = () => {
<BreadcrumbItem key="home"> <BreadcrumbItem key="home">
<Link to={`/${realm}/groups`}>{t("groups")}</Link> <Link to={`/${realm}/groups`}>{t("groups")}</Link>
</BreadcrumbItem> </BreadcrumbItem>
{subGroups.map((group, i) => ( {subGroups.map((group, i) => {
<BreadcrumbItem key={i} isActive={subGroups.length - 1 === i}> const isLastGroup = i === subGroups.length - 1;
{subGroups.length - 1 !== i && ( return (
<BreadcrumbItem key={group.id} isActive={isLastGroup}>
{!isLastGroup && (
<Link <Link
to={location.pathname.substr( to={location.pathname.substr(
0, 0,
@ -42,9 +44,13 @@ export const GroupBreadCrumbs = () => {
{group.name} {group.name}
</Link> </Link>
)} )}
{subGroups.length - 1 === i && <>{t("groups:groupDetails")}</>} {isLastGroup &&
(group.id === "search"
? group.name
: t("groups:groupDetails"))}
</BreadcrumbItem> </BreadcrumbItem>
))} );
})}
</Breadcrumb> </Breadcrumb>
)} )}
</> </>

View file

@ -6,13 +6,13 @@ import {
ButtonVariant, ButtonVariant,
Chip, Chip,
ChipGroup, ChipGroup,
Form,
InputGroup, InputGroup,
PageSection, PageSection,
PageSectionVariants, PageSectionVariants,
Text, Stack,
TextContent, StackItem,
TextInput, TextInput,
ToolbarItem,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { SearchIcon } from "@patternfly/react-icons"; import { SearchIcon } from "@patternfly/react-icons";
@ -23,6 +23,7 @@ import { useRealm } from "../context/realm-context/RealmContext";
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; 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";
type SearchGroup = GroupRepresentation & { type SearchGroup = GroupRepresentation & {
link?: string; link?: string;
@ -40,7 +41,10 @@ export const SearchGroups = () => {
const refresh = () => setKey(new Date().getTime()); const refresh = () => setKey(new Date().getTime());
const { setSubGroups } = useSubGroups(); const { setSubGroups } = useSubGroups();
useEffect(() => setSubGroups([{ name: t("searchGroups") }]), []); useEffect(
() => setSubGroups([{ name: t("searchGroups"), id: "search" }]),
[]
);
const deleteTerm = (id: string) => { const deleteTerm = (id: string) => {
const index = searchTerms.indexOf(id); const index = searchTerms.indexOf(id);
@ -50,21 +54,26 @@ export const SearchGroups = () => {
}; };
const addTerm = () => { const addTerm = () => {
if (searchTerm !== "") {
setSearchTerms([...searchTerms, searchTerm]); setSearchTerms([...searchTerms, searchTerm]);
setSearchTerm(""); setSearchTerm("");
refresh(); refresh();
}
}; };
const GroupNameCell = (group: SearchGroup) => { const GroupNameCell = (group: SearchGroup) => (
setSubGroups([{ name: t("searchGroups"), id: "search" }, group]);
return (
<> <>
<Link key={group.id} to={`/${realm}/groups/search/${group.link}`}> <Link
key={group.id}
to={`/${realm}/groups/search/${group.link}`}
onClick={() =>
setSubGroups([{ name: t("searchGroups"), id: "search" }, group])
}
>
{group.name} {group.name}
</Link> </Link>
</> </>
); );
};
const flatten = ( const flatten = (
groups: GroupRepresentation[], groups: GroupRepresentation[],
@ -106,17 +115,15 @@ export const SearchGroups = () => {
return ( return (
<> <>
<PageSection variant={PageSectionVariants.light}> <ViewHeader titleKey="groups:searchGroups" />
<TextContent className="pf-u-mr-sm"> <PageSection variant={PageSectionVariants.light} className="pf-u-p-0">
<Text component="h1">{t("searchForGroups")}</Text> <KeycloakDataTable
</TextContent> key={key}
<Form isSearching
className="pf-u-mt-sm keycloak__form" toolbarItem={
onSubmit={(e) => { <ToolbarItem>
e.preventDefault(); <Stack>
addTerm(); <StackItem className="pf-u-mb-sm">
}}
>
<InputGroup> <InputGroup>
<TextInput <TextInput
name="search" name="search"
@ -126,6 +133,11 @@ export const SearchGroups = () => {
placeholder={t("searchGroups")} placeholder={t("searchGroups")}
value={searchTerm} value={searchTerm}
onChange={(value) => setSearchTerm(value)} onChange={(value) => setSearchTerm(value)}
onKeyDown={(event) => {
if (event.key === "Enter") {
addTerm();
}
}}
/> />
<Button <Button
data-testid="search-button" data-testid="search-button"
@ -136,6 +148,8 @@ export const SearchGroups = () => {
<SearchIcon /> <SearchIcon />
</Button> </Button>
</InputGroup> </InputGroup>
</StackItem>
<StackItem>
<ChipGroup> <ChipGroup>
{searchTerms.map((term) => ( {searchTerms.map((term) => (
<Chip key={term} onClick={() => deleteTerm(term)}> <Chip key={term} onClick={() => deleteTerm(term)}>
@ -143,9 +157,10 @@ export const SearchGroups = () => {
</Chip> </Chip>
))} ))}
</ChipGroup> </ChipGroup>
</Form> </StackItem>
<KeycloakDataTable </Stack>
key={key} </ToolbarItem>
}
ariaLabelKey="groups:groups" ariaLabelKey="groups:groups"
isPaginated isPaginated
loader={loader} loader={loader}