From 8f8cc420780c826b23b921b1374cd60ffb61fd83 Mon Sep 17 00:00:00 2001 From: Peter Macdonald Date: Wed, 5 Oct 2022 22:35:25 +0200 Subject: [PATCH] Updated useEffect to fix #13730 Signed-off-by: Peter Macdonald --- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index 3261295716..d0c3108976 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -88,37 +88,36 @@ export const RepoUrlPicker = ( [uiSchema], ); + const { owner, organization } = state; + useEffect(() => { onChange(serializeRepoPickerUrl(state)); }, [state, onChange]); /* we deal with calling the repo setting here instead of in each components for ease */ useEffect(() => { - if (allowedOrganizations.length > 0 && !state.organization) { + if (allowedOrganizations.length > 0 && !organization) { setState(prevState => ({ ...prevState, organization: allowedOrganizations[0], })); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [setState, allowedOrganizations, state.organization]); + }, [setState, allowedOrganizations, organization]); useEffect(() => { - if (allowedOwners.length > 0 && !state.owner) { + if (allowedOwners.length > 0 && !owner) { setState(prevState => ({ ...prevState, owner: allowedOwners[0], })); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [setState, allowedOwners, state.owner]); + }, [setState, allowedOwners, owner]); useEffect(() => { - if (allowedRepos.length > 0 && !state.repoName) { + if (allowedRepos.length > 0) { setState(prevState => ({ ...prevState, repoName: allowedRepos[0] })); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [setState, allowedRepos, state.repoName]); + }, [setState, allowedRepos]); const updateLocalState = useCallback( (newState: RepoUrlPickerState) => { @@ -138,7 +137,7 @@ export const RepoUrlPicker = ( return; } - const [host, owner, repoName] = [ + const [encodedHost, encodedOwner, encodedRepoName] = [ state.host, state.owner, state.repoName, @@ -148,7 +147,7 @@ export const RepoUrlPicker = ( // so lets grab them using the scmAuthApi and pass through // any additional scopes from the ui:options const { token } = await scmAuthApi.getCredentials({ - url: `https://${host}/${owner}/${repoName}`, + url: `https://${encodedHost}/${encodedOwner}/${encodedRepoName}`, additionalScope: { repoWrite: true, customScopes: requestUserCredentials.additionalScopes,