Merge pull request #2544 from therealadum/master

Add SCM specification if not auto-detect
This commit is contained in:
Fredrik Adelöw
2020-09-21 23:20:13 +02:00
committed by GitHub
3 changed files with 41 additions and 7 deletions
@@ -41,7 +41,9 @@ describe('RegisterComponentForm', () => {
),
).toBeInTheDocument();
const submit = (await rendered.getByRole('button')) as HTMLButtonElement;
const submit = (await rendered.getByTestId(
'registerComponentFormSubmit',
)) as HTMLButtonElement;
expect(submit.disabled).toBeTruthy();
});
@@ -54,7 +56,9 @@ describe('RegisterComponentForm', () => {
target: { value: 'https://example.com/blob/master/component.yaml' },
});
});
const submit = (await rendered.getByRole('button')) as HTMLButtonElement;
const submit = (await rendered.getByTestId(
'registerComponentFormSubmit',
)) as HTMLButtonElement;
expect(submit.disabled).toBeFalsy();
});
@@ -21,10 +21,13 @@ import {
FormHelperText,
LinearProgress,
TextField,
Select,
MenuItem,
InputLabel,
} from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import React, { FC } from 'react';
import { useForm } from 'react-hook-form';
import { useForm, Controller } from 'react-hook-form';
import { ComponentIdValidators } from '../../util/validate';
const useStyles = makeStyles<BackstageTheme>(theme => ({
@@ -44,7 +47,7 @@ export type Props = {
};
const RegisterComponentForm: FC<Props> = ({ onSubmit, submitting }) => {
const { register, handleSubmit, errors, formState } = useForm({
const { control, register, handleSubmit, errors, formState } = useForm({
mode: 'onChange',
});
const classes = useStyles();
@@ -84,8 +87,33 @@ const RegisterComponentForm: FC<Props> = ({ onSubmit, submitting }) => {
</FormHelperText>
)}
</FormControl>
<FormControl variant="outlined">
<InputLabel id="scmLabel">SCM Detection</InputLabel>
<Controller
control={control}
name="scmType"
defaultValue="AUTO"
render={({ onChange, onBlur, value }) => (
<Select
labelId="scmLabel"
id="scmSelect"
label="scmLabel"
value={value}
onChange={onChange}
onBlur={onBlur}
>
<MenuItem value="AUTO">Auto-detect</MenuItem>
<MenuItem value="gitlab">GitLab</MenuItem>
<MenuItem value="bitbucket/api">Bitbucket</MenuItem>
<MenuItem value="azure/api">Azure</MenuItem>
</Select>
)}
/>
</FormControl>
<Button
id="registerComponentFormSubmit"
data-testid="registerComponentFormSubmit"
variant="contained"
color="primary"
type="submit"
@@ -82,7 +82,7 @@ export const RegisterComponentPage = ({
const handleSubmit = async (formData: Record<string, string>) => {
setFormState(FormStates.Submitting);
const { componentLocation: target } = formData;
const { scmType, componentLocation: target } = formData;
try {
const typeMapping = [
{ url: /https:\/\/gitlab\.com\/.*/, type: 'gitlab' },
@@ -91,8 +91,10 @@ export const RegisterComponentPage = ({
{ url: /.*/, type: 'github' },
];
const type = typeMapping.filter(item => item.url.test(target))[0].type;
const type =
scmType === 'AUTO'
? typeMapping.filter(item => item.url.test(target))[0].type
: scmType;
const data = await catalogApi.addLocation(type, target);
if (!isMounted()) return;