fixed search on only one resource (#38794) (#39115)

fixes: #38458


(cherry picked from commit 87dfdad4bf2a1a4c6b90456803da2c38f1a4a018)

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2025-04-23 10:04:38 +02:00 committed by GitHub
parent 2e1740b778
commit 61fbcae818
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 9 deletions

View File

@ -2,7 +2,6 @@ import GroupRepresentation from "@keycloak/keycloak-admin-client/lib/defs/groupR
import {
FormErrorText,
HelpItem,
SelectVariant,
useFetch,
} from "@keycloak/keycloak-ui-shared";
import { Button, FormGroup } from "@patternfly/react-core";
@ -16,7 +15,7 @@ import type { ComponentProps } from "../../components/dynamic/components";
import { GroupPickerDialog } from "../../components/group/GroupPickerDialog";
type GroupSelectProps = Omit<ComponentProps, "convertToName"> & {
variant?: `${SelectVariant}`;
variant?: "typeahead" | "typeaheadMulti";
isRequired?: boolean;
};
@ -30,6 +29,7 @@ export const GroupSelect = ({
defaultValue,
isDisabled = false,
isRequired,
variant = "typeaheadMulti",
}: GroupSelectProps) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
@ -58,6 +58,8 @@ export const GroupSelect = ({
[],
);
const selectOne = variant === "typeahead";
return (
<FormGroup
label={t(label!)}
@ -78,17 +80,22 @@ export const GroupSelect = ({
<>
{open && (
<GroupPickerDialog
type="selectMany"
type={selectOne ? "selectOne" : "selectMany"}
text={{
title: "addGroupsToGroupPolicy",
ok: "add",
}}
onConfirm={(selectGroup) => {
field.onChange([
...(field.value || []),
...convertGroups(selectGroup || []),
]);
setGroups([...groups, ...(selectGroup || [])]);
if (selectOne) {
field.onChange(convertGroups(selectGroup || []));
setGroups(selectGroup || []);
} else {
field.onChange([
...(field.value || []),
...convertGroups(selectGroup || []),
]);
setGroups([...groups, ...(selectGroup || [])]);
}
setOpen(false);
}}
onClose={() => {

View File

@ -95,8 +95,9 @@ export const ResourceType = ({
resourceType: normalizedResourceType,
})}
defaultValue={[]}
variant="typeaheadMulti"
variant={withEnforceAccessTo ? "typeaheadMulti" : "typeahead"}
isRequired={withEnforceAccessTo}
isRadio={!withEnforceAccessTo}
/>
)}
</>