From 385e413df3334cc150e02aa57e43468edcc64310 Mon Sep 17 00:00:00 2001 From: Collin Beczak <88843144+CollinBeczak@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:16:45 -0600 Subject: [PATCH] update create challenge form's next button functionality (#2271) * update create challenge form's next button functionality * reverted a couple of changes, fixed edits code agreement checkbox validation, now coercing .env CHALLENGE_INSTRUCTIONS_MIN_LENGTH to number value in instructions schema * better value check for env value * fixed handling for instruction length .env value --------- Co-authored-by: Andrew Philbin <45773707+AndrewPhilbin@users.noreply.github.com> --- .../EditChallenge/EditChallenge.js | 7 +++---- .../AutomatedEditsCodeAgreementSchema.js | 2 +- .../Schemas/InstructionsSchema.js | 19 ++++++++++++++++++- .../EditChallenge/WorkflowSteps.js | 8 ++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/EditChallenge.js b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/EditChallenge.js index d96745ddd..829ae6270 100644 --- a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/EditChallenge.js +++ b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/EditChallenge.js @@ -289,13 +289,13 @@ export class EditChallenge extends Component { (this.validationPromise || Promise.resolve()) .then(() => { this.isFinishing ? this.finish() : nextStep(); - window.scrollTo(0, 0); + window.scrollTo(0, 0); return false; }) .catch((err) => { - console.log(err); + console.log(err); }); // Stay on current step if validation fails - + return false; }; @@ -967,7 +967,6 @@ export class EditChallenge extends Component { )} - {/* Note: Next button submits the form, so nextStep isn't used here */} { diff --git a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/AutomatedEditsCodeAgreementSchema.js b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/AutomatedEditsCodeAgreementSchema.js index 847757758..80e673272 100644 --- a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/AutomatedEditsCodeAgreementSchema.js +++ b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/AutomatedEditsCodeAgreementSchema.js @@ -14,7 +14,7 @@ export const jsSchema = (intl) => { title: intl.formatMessage(messages.automatedEditsCodeLabel), type: "boolean", default: false, - enum: [false, true], + enum: [true], agreementDescription: intl.formatMessage(messages.automatedEditsCodeDescription), checkboxLabel: messages.automatedEditsCodeUICheckboxLabel } diff --git a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/InstructionsSchema.js b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/InstructionsSchema.js index 82a82b2d4..9b6cd722e 100644 --- a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/InstructionsSchema.js +++ b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/Schemas/InstructionsSchema.js @@ -16,8 +16,25 @@ import messages from '../Messages' * * @author [Neil Rotstan](https://github.com/nrotstan) */ + +const validateMinLength = val => { + if(!val) { + // Handle undefined. null and empty string case and default to 150: + if(typeof val === 'string' && val.length === 0) return 0 + if(val === 0) return 0 + return 150 + } + // Handle 0 separately. Non-strict equals will be true for '0' string value: + if(val == 0) return 0 + + // Bitwise operator coerces to number value: + return val | 0 +} + export const jsSchema = (intl) => { - const instructionsMinLength = process.env.REACT_APP_CHALLENGE_INSTRUCTIONS_MIN_LENGTH || 150 + const minLengthEnvValue = process.env.REACT_APP_CHALLENGE_INSTRUCTIONS_MIN_LENGTH + const instructionsMinLength = validateMinLength(minLengthEnvValue) + const schemaFields = { "$schema": "http://json-schema.org/draft-07/schema#", type: "object", diff --git a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/WorkflowSteps.js b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/WorkflowSteps.js index c1b0349b4..87ef6ef75 100644 --- a/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/WorkflowSteps.js +++ b/src/components/AdminPane/Manage/ManageChallenges/EditChallenge/WorkflowSteps.js @@ -182,6 +182,10 @@ const newChallengeSteps = { next: 'AutomatedEditsCodeAgreement', previous: 'Description', }), + 'AutomatedEditsCodeAgreement': Object.assign({}, automatedEditsCodeAgreementStep, { + next: 'AdvancedOptions', + previous: 'Instructions' + }), 'AdvancedOptions': Object.assign({}, advancedOptionsStep, { next: [ 'Discoverability', @@ -236,10 +240,6 @@ const newChallengeSteps = { previous: 'AdvancedOptions', canFinish: true, }), - 'AutomatedEditsCodeAgreement': Object.assign({}, automatedEditsCodeAgreementStep, { - next: 'AdvancedOptions', - previous: 'Instructions' - }) } // String together workflow steps for editing an existing challenge