Use id instead of name to disable (#3959)

This commit is contained in:
Erik Jan de Wit 2022-12-08 06:24:59 -05:00 committed by GitHub
parent ca03f50093
commit b0ce0bb181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 9 deletions

View file

@ -119,7 +119,7 @@ export const Group = () => {
onClose={() => { onClose={() => {
setOpen(false); setOpen(false);
}} }}
filterGroups={selectedGroups.map(({ name }) => name!)} filterGroups={selectedGroups}
/> />
)} )}
<Button <Button

View file

@ -13,10 +13,12 @@ import type { ComponentProps } from "./components";
import { HelpItem } from "../help-enabler/HelpItem"; import { HelpItem } from "../help-enabler/HelpItem";
import { GroupPickerDialog } from "../group/GroupPickerDialog"; import { GroupPickerDialog } from "../group/GroupPickerDialog";
import { convertToName } from "./DynamicComponents"; import { convertToName } from "./DynamicComponents";
import GroupRepresentation from "libs/keycloak-admin-client/lib/defs/groupRepresentation";
export const GroupComponent = ({ name, label, helpText }: ComponentProps) => { export const GroupComponent = ({ name, label, helpText }: ComponentProps) => {
const { t } = useTranslation("dynamic"); const { t } = useTranslation("dynamic");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [groups, setGroups] = useState<GroupRepresentation[]>();
const { control } = useFormContext(); const { control } = useFormContext();
return ( return (
@ -36,10 +38,11 @@ export const GroupComponent = ({ name, label, helpText }: ComponentProps) => {
}} }}
onConfirm={(groups) => { onConfirm={(groups) => {
onChange(groups?.[0].path); onChange(groups?.[0].path);
setGroups(groups);
setOpen(false); setOpen(false);
}} }}
onClose={() => setOpen(false)} onClose={() => setOpen(false)}
filterGroups={value} filterGroups={groups}
/> />
)} )}

View file

@ -25,7 +25,7 @@ import { GroupPath } from "./GroupPath";
export type GroupPickerDialogProps = { export type GroupPickerDialogProps = {
id?: string; id?: string;
type: "selectOne" | "selectMany"; type: "selectOne" | "selectMany";
filterGroups?: string[]; filterGroups?: GroupRepresentation[];
text: { title: string; ok: string }; text: { title: string; ok: string };
canBrowse?: boolean; canBrowse?: boolean;
onConfirm: (groups: GroupRepresentation[] | undefined) => void; onConfirm: (groups: GroupRepresentation[] | undefined) => void;
@ -103,9 +103,9 @@ export const GroupPickerDialog = ({
const isRowDisabled = (row?: GroupRepresentation) => { const isRowDisabled = (row?: GroupRepresentation) => {
return [ return [
...joinedGroups.map((item) => item.name), ...joinedGroups.map((item) => item.id),
...(filterGroups || []), ...(filterGroups || []).map((group) => group.id),
].some((group) => group === row?.name); ].some((group) => group === row?.id);
}; };
const hasSubgroups = (group: GroupRepresentation) => const hasSubgroups = (group: GroupRepresentation) =>
@ -131,7 +131,7 @@ export const GroupPickerDialog = ({
<Modal <Modal
variant={ModalVariant.small} variant={ModalVariant.small}
title={t(text.title, { title={t(text.title, {
group1: filterGroups?.[0], group1: filterGroups?.[0]?.name,
group2: navigation.length ? currentGroup().name : t("root"), group2: navigation.length ? currentGroup().name : t("root"),
})} })}
isOpen isOpen

View file

@ -71,7 +71,7 @@ export const MoveDialog = ({ source, onClose, refresh }: MoveDialogProps) => {
return ( return (
<GroupPickerDialog <GroupPickerDialog
type="selectOne" type="selectOne"
filterGroups={[source.name!]} filterGroups={[source]}
text={{ text={{
title: "groups:moveToGroup", title: "groups:moveToGroup",
ok: "groups:moveHere", ok: "groups:moveHere",

View file

@ -168,7 +168,7 @@ export const UserForm = ({
setOpen(false); setOpen(false);
}} }}
onClose={() => setOpen(false)} onClose={() => setOpen(false)}
filterGroups={selectedGroups.map((group) => group.name!)} filterGroups={selectedGroups}
/> />
)} )}
{user?.id && ( {user?.id && (