chore: fix autoselect of the workspace when there are a list provided

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-08-25 14:53:28 +02:00
parent cd19357e4c
commit 18ee24197e
2 changed files with 13 additions and 2 deletions
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import React, { useEffect } from 'react';
import FormControl from '@material-ui/core/FormControl';
import FormHelperText from '@material-ui/core/FormHelperText';
import Input from '@material-ui/core/Input';
@@ -32,6 +32,13 @@ export const BitbucketRepoPicker = (props: {
const ownerItems: SelectItem[] = allowedOwners
? allowedOwners?.map(i => ({ label: i, value: i }))
: [];
useEffect(() => {
if (host === 'bitbucket.org' && allowedOwners.length) {
onChange({ workspace: allowedOwners[0] });
}
}, [allowedOwners, host, onChange]);
return (
<>
{host === 'bitbucket.org' && (
@@ -90,9 +90,13 @@ export const RepoUrlPicker = (
/* we deal with calling the repo setting here instead of in each components for ease */
useEffect(() => {
if (allowedOwners.length > 0) {
setState(prevState => ({ ...prevState, owner: allowedOwners[0] }));
setState(prevState => ({
...prevState,
owner: allowedOwners[0],
}));
}
}, [setState, allowedOwners]);
useEffect(() => {
if (allowedRepos.length > 0) {
setState(prevState => ({ ...prevState, repoName: allowedRepos[0] }));