fix(client): allow editor links for Py submissions (#41036)
* fix(client): allow editor links for Py submissions * add isEditorLinkAllowed to PropTypes
This commit is contained in:
@ -21,6 +21,7 @@ const propTypes = {
|
|||||||
initialValues: PropTypes.object,
|
initialValues: PropTypes.object,
|
||||||
options: PropTypes.shape({
|
options: PropTypes.shape({
|
||||||
ignored: PropTypes.arrayOf(PropTypes.string),
|
ignored: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
isEditorLinkAllowed: PropTypes.bool,
|
||||||
required: PropTypes.arrayOf(PropTypes.string),
|
required: PropTypes.arrayOf(PropTypes.string),
|
||||||
types: PropTypes.objectOf(PropTypes.string)
|
types: PropTypes.objectOf(PropTypes.string)
|
||||||
}),
|
}),
|
||||||
|
@ -24,6 +24,7 @@ const propTypes = {
|
|||||||
).isRequired,
|
).isRequired,
|
||||||
options: PropTypes.shape({
|
options: PropTypes.shape({
|
||||||
ignored: PropTypes.arrayOf(PropTypes.string),
|
ignored: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
isEditorLinkAllowed: PropTypes.bool,
|
||||||
placeholders: PropTypes.objectOf(PropTypes.string),
|
placeholders: PropTypes.objectOf(PropTypes.string),
|
||||||
required: PropTypes.arrayOf(PropTypes.string),
|
required: PropTypes.arrayOf(PropTypes.string),
|
||||||
types: PropTypes.objectOf(PropTypes.string)
|
types: PropTypes.objectOf(PropTypes.string)
|
||||||
@ -36,7 +37,8 @@ function FormFields(props) {
|
|||||||
ignored = [],
|
ignored = [],
|
||||||
placeholders = {},
|
placeholders = {},
|
||||||
required = [],
|
required = [],
|
||||||
types = {}
|
types = {},
|
||||||
|
isEditorLinkAllowed = false
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const nullOrWarning = (value, error, isURL, name) => {
|
const nullOrWarning = (value, error, isURL, name) => {
|
||||||
@ -49,7 +51,7 @@ function FormFields(props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const validationWarning = composeValidators(
|
const validationWarning = composeValidators(
|
||||||
name === 'githubLink' ? null : editorValidator,
|
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
|
||||||
localhostValidator
|
localhostValidator
|
||||||
)(value);
|
)(value);
|
||||||
const message = error || validationError || validationWarning;
|
const message = error || validationError || validationWarning;
|
||||||
|
@ -15,17 +15,18 @@ const normalizeOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function formatUrlValues(values, options) {
|
export function formatUrlValues(values, options) {
|
||||||
|
const { isEditorLinkAllowed, types } = options;
|
||||||
const validatedValues = { values: {}, errors: [], invalidValues: [] };
|
const validatedValues = { values: {}, errors: [], invalidValues: [] };
|
||||||
const urlValues = Object.keys(values).reduce((result, key) => {
|
const urlValues = Object.keys(values).reduce((result, key) => {
|
||||||
let value = values[key];
|
let value = values[key];
|
||||||
const nullOrWarning = composeValidators(
|
const nullOrWarning = composeValidators(
|
||||||
localhostValidator,
|
localhostValidator,
|
||||||
key === 'githubLink' ? null : editorValidator
|
key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator
|
||||||
)(value);
|
)(value);
|
||||||
if (nullOrWarning) {
|
if (nullOrWarning) {
|
||||||
validatedValues.invalidValues.push(nullOrWarning);
|
validatedValues.invalidValues.push(nullOrWarning);
|
||||||
}
|
}
|
||||||
if (value && options.types[key] === 'url') {
|
if (value && types[key] === 'url') {
|
||||||
try {
|
try {
|
||||||
value = normalizeUrl(value, normalizeOptions);
|
value = normalizeUrl(value, normalizeOptions);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -58,7 +58,8 @@ export class SolutionForm extends Component {
|
|||||||
solution: 'url',
|
solution: 'url',
|
||||||
githubLink: 'url'
|
githubLink: 'url'
|
||||||
},
|
},
|
||||||
required: ['solution']
|
required: ['solution'],
|
||||||
|
isEditorLinkAllowed: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const buttonCopy = isSubmitting
|
const buttonCopy = isSubmitting
|
||||||
@ -89,6 +90,7 @@ export class SolutionForm extends Component {
|
|||||||
|
|
||||||
case pythonProject:
|
case pythonProject:
|
||||||
formFields = solutionField;
|
formFields = solutionField;
|
||||||
|
options.isEditorLinkAllowed = true;
|
||||||
solutionLink =
|
solutionLink =
|
||||||
solutionLink +
|
solutionLink +
|
||||||
(description.includes('Colaboratory')
|
(description.includes('Colaboratory')
|
||||||
|
Reference in New Issue
Block a user