feature(component-registration): allow SCM specification
This commit is contained in:
+29
-2
@@ -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,6 +87,30 @@ 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"
|
||||
variant="contained"
|
||||
|
||||
+5
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user