From cc1cf38d696af5cbf4f840b1cf65f426e34afe57 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 6 Jul 2022 12:59:45 +0200 Subject: [PATCH] (bug) OIDC scopes are not shown in the configuration form select --- CHANGELOG.md | 1 + .../authentication-provider/openid-connect-form.tsx | 8 ++++++++ .../src/javascript/components/form/form-multi-select.tsx | 8 +++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9a837e7b..d5e41299a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## next deploy - Fix a bug: Gender, Address and Birthday are not mapped properly from SSO (#365) +- Fix a bug: OIDC scopes are not shown in the configuration form select ## v5.4.10 2022 July 05 diff --git a/app/frontend/src/javascript/components/authentication-provider/openid-connect-form.tsx b/app/frontend/src/javascript/components/authentication-provider/openid-connect-form.tsx index 23b71169b..0aa816334 100644 --- a/app/frontend/src/javascript/components/authentication-provider/openid-connect-form.tsx +++ b/app/frontend/src/javascript/components/authentication-provider/openid-connect-form.tsx @@ -29,6 +29,8 @@ export const OpenidConnectForm = (false); const [scopesAvailable, setScopesAvailable] = useState(null); + // this is a workaround for https://github.com/JedWatson/react-select/issues/1879 + const [selectKey, setSelectKey] = useState(0); // when we have detected a discovery endpoint, we mark it as available useEffect(() => { @@ -38,6 +40,11 @@ export const OpenidConnectForm = { + setSelectKey(selectKey + 1); + }, [scopesAvailable]); + // when the component is mounted, we try to discover the discovery endpoint for the current configuration (if any) useEffect(() => { checkForDiscoveryEndpoint({ target: { value: currentFormValues?.issuer } } as React.ChangeEvent); @@ -125,6 +132,7 @@ export const OpenidConnectForm = } loadOptions={loadScopes} + selectKey={selectKey.toString()} creatable control={control} /> exten onChange?: (values: Array) => void, placeholder?: string, creatable?: boolean, + selectKey?: string, } // we should provide either an array of options or a function that returns a promise, but not both @@ -35,7 +36,7 @@ type selectOption = { value: TOptionValue, label: string, select?: * This component is a wrapper around react-select to use with react-hook-form. * It is a multi-select component. */ -export const FormMultiSelect = ({ id, label, tooltip, className, control, placeholder, options, valuesDefault, error, rules, disabled, onChange, formState, warning, loadOptions, creatable }: FormSelectProps) => { +export const FormMultiSelect = ({ id, label, tooltip, className, control, placeholder, options, valuesDefault, error, rules, disabled, onChange, formState, warning, loadOptions, creatable, selectKey }: FormSelectProps) => { const { t } = useTranslation('shared'); const [isDisabled, setIsDisabled] = React.useState(false); @@ -52,7 +53,7 @@ export const FormMultiSelect = { if (typeof loadOptions === 'function') { loadOptions('', options => { - setAllOptions(options); + setTimeout(() => setAllOptions(options), 1); }); } }, [loadOptions]); @@ -73,7 +74,7 @@ export const FormMultiSelect = ): Array> => { - return allOptions.filter(c => value?.includes(c.value)); + return allOptions?.filter(c => value?.includes(c.value)); }; /** @@ -119,6 +120,7 @@ export const FormMultiSelect =