feat(client): add github to validation list (#40894)

This commit is contained in:
Shaun Hamilton
2021-02-04 06:44:35 +00:00
committed by GitHub
parent 30c923b73d
commit ea1c132868
3 changed files with 7 additions and 7 deletions

View File

@ -39,7 +39,7 @@ function FormFields(props) {
types = {} types = {}
} = options; } = options;
const nullOrWarning = (value, error, isURL) => { const nullOrWarning = (value, error, isURL, name) => {
let validationError; let validationError;
if (value && isURL) { if (value && isURL) {
try { try {
@ -49,7 +49,7 @@ function FormFields(props) {
} }
} }
const validationWarning = composeValidators( const validationWarning = composeValidators(
editorValidator, name === 'githubLink' ? null : editorValidator,
localhostValidator localhostValidator
)(value); )(value);
const message = error || validationError || validationWarning; const message = error || validationError || validationWarning;
@ -90,7 +90,7 @@ function FormFields(props) {
type={type} type={type}
value={value} value={value}
/> />
{nullOrWarning(value, !pristine && error, isURL)} {nullOrWarning(value, !pristine && error, isURL, name)}
</FormGroup> </FormGroup>
</Col> </Col>
); );

View File

@ -1,5 +1,5 @@
// Matches editor links for: Repl.it, Glitch, CodeSandbox // Matches editor links for: Repl.it, Glitch, CodeSandbox, GitHub
const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\//; const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/;
const localhostRegex = /localhost:/; const localhostRegex = /localhost:/;
export const editorValidator = value => export const editorValidator = value =>
@ -11,4 +11,4 @@ export const localhostValidator = value =>
: null; : null;
export const composeValidators = (...validators) => value => export const composeValidators = (...validators) => value =>
validators.reduce((error, validator) => error ?? validator(value), null); validators.reduce((error, validator) => error ?? validator?.(value), null);

View File

@ -20,7 +20,7 @@ export function formatUrlValues(values, options) {
let value = values[key]; let value = values[key];
const nullOrWarning = composeValidators( const nullOrWarning = composeValidators(
localhostValidator, localhostValidator,
editorValidator key === 'githubLink' ? null : editorValidator
)(value); )(value);
if (nullOrWarning) { if (nullOrWarning) {
validatedValues.invalidValues.push(nullOrWarning); validatedValues.invalidValues.push(nullOrWarning);