Added exact search checkbox (#3730)
This commit is contained in:
parent
8ffe800272
commit
5587314a70
3 changed files with 27 additions and 8 deletions
|
@ -22,6 +22,7 @@
|
||||||
"usersAdded_other": "{{count}} users added to the group",
|
"usersAdded_other": "{{count}} users added to the group",
|
||||||
"usersAddedError": "Could not add users to the group: {{error}}",
|
"usersAddedError": "Could not add users to the group: {{error}}",
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
|
"exactSearch": "Exact search",
|
||||||
"members": "Members",
|
"members": "Members",
|
||||||
"searchMembers": "Search members",
|
"searchMembers": "Search members",
|
||||||
"addMember": "Add member",
|
"addMember": "Add member",
|
||||||
|
|
|
@ -2,10 +2,12 @@ import { useState } from "react";
|
||||||
import { Link } from "react-router-dom-v5-compat";
|
import { Link } from "react-router-dom-v5-compat";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
|
Checkbox,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
DropdownItem,
|
DropdownItem,
|
||||||
DropdownPosition,
|
DropdownPosition,
|
||||||
DropdownSeparator,
|
DropdownSeparator,
|
||||||
|
InputGroup,
|
||||||
KebabToggle,
|
KebabToggle,
|
||||||
TreeView,
|
TreeView,
|
||||||
TreeViewDataItem,
|
TreeViewDataItem,
|
||||||
|
@ -109,6 +111,7 @@ export const GroupTree = ({ refresh: viewRefresh }: GroupTreeProps) => {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [max, setMax] = useState(20);
|
const [max, setMax] = useState(20);
|
||||||
const [first, setFirst] = useState(0);
|
const [first, setFirst] = useState(0);
|
||||||
|
const [exact, setExact] = useState(false);
|
||||||
|
|
||||||
const [key, setKey] = useState(0);
|
const [key, setKey] = useState(0);
|
||||||
const refresh = () => {
|
const refresh = () => {
|
||||||
|
@ -151,12 +154,13 @@ export const GroupTree = ({ refresh: viewRefresh }: GroupTreeProps) => {
|
||||||
{
|
{
|
||||||
first: `${first}`,
|
first: `${first}`,
|
||||||
max: `${max + 1}`,
|
max: `${max + 1}`,
|
||||||
|
exact: `${exact}`,
|
||||||
},
|
},
|
||||||
search === "" ? null : { search }
|
search === "" ? null : { search }
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
(groups) => setData(groups.map((g) => mapGroup(g, [], refresh))),
|
(groups) => setData(groups.map((g) => mapGroup(g, [], refresh))),
|
||||||
[key, first, max, search]
|
[key, first, max, search, exact]
|
||||||
);
|
);
|
||||||
|
|
||||||
return data ? (
|
return data ? (
|
||||||
|
@ -173,6 +177,18 @@ export const GroupTree = ({ refresh: viewRefresh }: GroupTreeProps) => {
|
||||||
inputGroupName="searchForGroups"
|
inputGroupName="searchForGroups"
|
||||||
inputGroupPlaceholder={t("groups:searchForGroups")}
|
inputGroupPlaceholder={t("groups:searchForGroups")}
|
||||||
inputGroupOnEnter={setSearch}
|
inputGroupOnEnter={setSearch}
|
||||||
|
toolbarItem={
|
||||||
|
<InputGroup className="pf-u-pt-sm">
|
||||||
|
<Checkbox
|
||||||
|
id="exact"
|
||||||
|
data-testid="exact-search"
|
||||||
|
name="exact"
|
||||||
|
isChecked={exact}
|
||||||
|
onChange={(value) => setExact(value)}
|
||||||
|
/>
|
||||||
|
<span className="pf-u-pl-sm">{t("exactSearch")}</span>
|
||||||
|
</InputGroup>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{data.length > 0 && (
|
{data.length > 0 && (
|
||||||
<TreeView data={data} allExpanded={search.length > 0} hasGuides />
|
<TreeView data={data} allExpanded={search.length > 0} hasGuides />
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
|
|
||||||
import org.eclipse.microprofile.openapi.annotations.Operation;
|
import org.eclipse.microprofile.openapi.annotations.Operation;
|
||||||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
|
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
|
||||||
import org.eclipse.microprofile.openapi.annotations.media.Content;
|
import org.eclipse.microprofile.openapi.annotations.media.Content;
|
||||||
|
@ -53,22 +54,23 @@ public class GroupsResource {
|
||||||
)}
|
)}
|
||||||
)
|
)
|
||||||
public final Stream<GroupRepresentation> listGroups(@QueryParam("search") @DefaultValue("") final String search, @QueryParam("first")
|
public final Stream<GroupRepresentation> listGroups(@QueryParam("search") @DefaultValue("") final String search, @QueryParam("first")
|
||||||
@DefaultValue("0") int first, @QueryParam("max") @DefaultValue("10") int max, @QueryParam("global") @DefaultValue("true") boolean global) {
|
@DefaultValue("0") int first, @QueryParam("max") @DefaultValue("10") int max, @QueryParam("global") @DefaultValue("true") boolean global,
|
||||||
|
@QueryParam("exact") @DefaultValue("false") boolean exact) {
|
||||||
this.auth.groups().requireList();
|
this.auth.groups().requireList();
|
||||||
final Stream<GroupModel> stream;
|
final Stream<GroupModel> stream;
|
||||||
if (!"".equals(search)) {
|
if (!"".equals(search)) {
|
||||||
if (global) {
|
if (global) {
|
||||||
stream = this.realm.searchForGroupByNameStream(search, first, max);
|
stream = session.groups().searchForGroupByNameStream(realm, search, exact, first, max);
|
||||||
} else {
|
} else {
|
||||||
stream = this.realm.getTopLevelGroupsStream().filter(g -> g.getName().contains(search)).skip(first).limit(max);
|
stream = this.realm.getTopLevelGroupsStream().filter(g -> g.getName().contains(search)).skip(first).limit(max);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stream = this.realm.getTopLevelGroupsStream(first, max);
|
stream = this.realm.getTopLevelGroupsStream(first, max);
|
||||||
}
|
}
|
||||||
return stream.map(g -> toGroupHierarchy(g, search));
|
return stream.map(g -> toGroupHierarchy(g, search, exact));
|
||||||
}
|
}
|
||||||
|
|
||||||
private GroupRepresentation toGroupHierarchy(GroupModel group, final String search) {
|
private GroupRepresentation toGroupHierarchy(GroupModel group, final String search, boolean exact) {
|
||||||
GroupRepresentation rep = toRepresentation(group, true);
|
GroupRepresentation rep = toRepresentation(group, true);
|
||||||
rep.setAccess(auth.groups().getAccess(group));
|
rep.setAccess(auth.groups().getAccess(group));
|
||||||
rep.setSubGroups(group.getSubGroupsStream().filter(g ->
|
rep.setSubGroups(group.getSubGroupsStream().filter(g ->
|
||||||
|
@ -76,9 +78,9 @@ public class GroupsResource {
|
||||||
g, search
|
g, search
|
||||||
)
|
)
|
||||||
).map(subGroup ->
|
).map(subGroup ->
|
||||||
ModelToRepresentation.toGroupHierarchy(
|
ModelToRepresentation.toGroupHierarchy(
|
||||||
subGroup, true, search
|
subGroup, true, search, exact
|
||||||
)
|
)
|
||||||
).collect(Collectors.toList()));
|
).collect(Collectors.toList()));
|
||||||
|
|
||||||
return rep;
|
return rep;
|
||||||
|
|
Loading…
Reference in a new issue