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:
Shaun Hamilton
2021-02-10 11:31:08 +00:00
committed by GitHub
parent 3bbf96e495
commit f157eda1af
4 changed files with 11 additions and 5 deletions

View File

@ -21,6 +21,7 @@ const propTypes = {
initialValues: PropTypes.object,
options: PropTypes.shape({
ignored: PropTypes.arrayOf(PropTypes.string),
isEditorLinkAllowed: PropTypes.bool,
required: PropTypes.arrayOf(PropTypes.string),
types: PropTypes.objectOf(PropTypes.string)
}),

View File

@ -24,6 +24,7 @@ const propTypes = {
).isRequired,
options: PropTypes.shape({
ignored: PropTypes.arrayOf(PropTypes.string),
isEditorLinkAllowed: PropTypes.bool,
placeholders: PropTypes.objectOf(PropTypes.string),
required: PropTypes.arrayOf(PropTypes.string),
types: PropTypes.objectOf(PropTypes.string)
@ -36,7 +37,8 @@ function FormFields(props) {
ignored = [],
placeholders = {},
required = [],
types = {}
types = {},
isEditorLinkAllowed = false
} = options;
const nullOrWarning = (value, error, isURL, name) => {
@ -49,7 +51,7 @@ function FormFields(props) {
}
}
const validationWarning = composeValidators(
name === 'githubLink' ? null : editorValidator,
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
localhostValidator
)(value);
const message = error || validationError || validationWarning;

View File

@ -15,17 +15,18 @@ const normalizeOptions = {
};
export function formatUrlValues(values, options) {
const { isEditorLinkAllowed, types } = options;
const validatedValues = { values: {}, errors: [], invalidValues: [] };
const urlValues = Object.keys(values).reduce((result, key) => {
let value = values[key];
const nullOrWarning = composeValidators(
localhostValidator,
key === 'githubLink' ? null : editorValidator
key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator
)(value);
if (nullOrWarning) {
validatedValues.invalidValues.push(nullOrWarning);
}
if (value && options.types[key] === 'url') {
if (value && types[key] === 'url') {
try {
value = normalizeUrl(value, normalizeOptions);
} catch (err) {

View File

@ -58,7 +58,8 @@ export class SolutionForm extends Component {
solution: 'url',
githubLink: 'url'
},
required: ['solution']
required: ['solution'],
isEditorLinkAllowed: false
};
const buttonCopy = isSubmitting
@ -89,6 +90,7 @@ export class SolutionForm extends Component {
case pythonProject:
formFields = solutionField;
options.isEditorLinkAllowed = true;
solutionLink =
solutionLink +
(description.includes('Colaboratory')