From 328900578dd539c862e372f714440bf80a754ebe Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 15 Sep 2022 17:08:18 +0300 Subject: [PATCH 1/2] TCA-425 - Update backend projects to advance to next lesson without completion modal --- .../Challenges/projects/backend/Show.tsx | 53 ++++++++++--------- .../Challenges/projects/solution-form.tsx | 5 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/client/src/templates/Challenges/projects/backend/Show.tsx b/client/src/templates/Challenges/projects/backend/Show.tsx index f27009fc4523e4..5b56ab017cdb7b 100644 --- a/client/src/templates/Challenges/projects/backend/Show.tsx +++ b/client/src/templates/Challenges/projects/backend/Show.tsx @@ -21,8 +21,6 @@ import { import ChallengeDescription from '../../components/Challenge-Description'; import Hotkeys from '../../components/Hotkeys'; import ChallengeTitle from '../../components/challenge-title'; -import CompletionModal from '../../components/completion-modal'; -import HelpModal from '../../components/help-modal'; import Output from '../../components/output'; import TestSuite from '../../components/test-suite'; import { @@ -33,12 +31,12 @@ import { initConsole, initTests, isChallengeCompletedSelector, + testsRunningSelector, updateChallengeMeta, - updateSolutionFormValues + updateSolutionFormValues, + submitChallenge } from '../../redux'; -import { getGuideUrl } from '../../utils'; import SolutionForm from '../solution-form'; -import ProjectToolPanel from '../tool-panel'; import '../../components/test-frame.css'; @@ -48,16 +46,19 @@ const mapStateToProps = createSelector( challengeTestsSelector, isChallengeCompletedSelector, isSignedInSelector, + testsRunningSelector, ( output: string[], tests: Test[], isChallengeCompleted: boolean, - isSignedIn: boolean + isSignedIn: boolean, + testsRunningSelector: boolean ) => ({ tests, output, isChallengeCompleted, - isSignedIn + isSignedIn, + testsRunningSelector }) ); @@ -67,7 +68,8 @@ const mapDispatchToActions = { initConsole, initTests, updateChallengeMeta, - updateSolutionFormValues + updateSolutionFormValues, + submitChallenge }; // Types @@ -86,8 +88,10 @@ interface BackEndProps { pageContext: { challengeMeta: ChallengeMeta; }; + submitChallenge: () => void; t: TFunction; tests: Test[]; + testsRunning: boolean; title: string; updateChallengeMeta: (arg0: ChallengeMeta) => void; updateSolutionFormValues: () => void; @@ -175,9 +179,16 @@ class BackEnd extends Component { } handleSubmit(): void { - this.props.executeChallenge({ - showCompletionModal: false - }); + const { tests, submitChallenge } = this.props; + const isChallengeComplete = tests.every(test => test.pass && !test.err); + + if (isChallengeComplete) { + submitChallenge(); + } else { + this.props.executeChallenge({ + showCompletionModal: false + }); + } } render() { @@ -185,14 +196,11 @@ class BackEnd extends Component { data: { challengeNode: { challenge: { - fields: { blockName }, challengeType, - forumTopicId, title, description, instructions, translationPending, - certification, superBlock, block } @@ -205,9 +213,15 @@ class BackEnd extends Component { }, t, tests, + testsRunning, updateSolutionFormValues } = this.props; + const isChallengeComplete = tests.every(test => test.pass && !test.err); + const submitBtnLabel: string = !isChallengeComplete ? ( + `${t('buttons.run-test')}${testsRunning ? ' ...' : ''}` + ) : t('buttons.submit-and-go'); + const blockNameTitle = `${t( `intro:${superBlock}.blocks.${block}.title` )} - ${title}`; @@ -243,9 +257,7 @@ class BackEnd extends Component { // eslint-disable-next-line @typescript-eslint/unbound-method onSubmit={this.handleSubmit} updateSolutionForm={updateSolutionFormValues} - /> -
{ - - diff --git a/client/src/templates/Challenges/projects/solution-form.tsx b/client/src/templates/Challenges/projects/solution-form.tsx index 712081077fb0a0..0f7a5cc1afda9b 100644 --- a/client/src/templates/Challenges/projects/solution-form.tsx +++ b/client/src/templates/Challenges/projects/solution-form.tsx @@ -16,6 +16,7 @@ interface SubmitProps { } interface FormProps extends WithTranslation { + buttonLabel?: string; challengeType: number; description?: string; onSubmit: (arg0: SubmitProps) => void; @@ -46,7 +47,7 @@ export class SolutionForm extends Component { }; render(): JSX.Element { - const { challengeType, description, t } = this.props; + const { buttonLabel, challengeType, description, t } = this.props; // back end challenges and front end projects use a single form field const solutionField = [ @@ -57,7 +58,7 @@ export class SolutionForm extends Component { { name: 'githubLink', label: t('learn.github-link') } ]; - const buttonCopy = t('learn.submit-and-go'); + const buttonCopy: string = buttonLabel ?? t('learn.submit-and-go'); const options = { types: { From d22a7f234fba361214952691780b49b423eb1060 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 15 Sep 2022 17:14:12 +0300 Subject: [PATCH 2/2] lint --- client/src/templates/Challenges/projects/backend/Show.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/templates/Challenges/projects/backend/Show.tsx b/client/src/templates/Challenges/projects/backend/Show.tsx index 5b56ab017cdb7b..161a266442b699 100644 --- a/client/src/templates/Challenges/projects/backend/Show.tsx +++ b/client/src/templates/Challenges/projects/backend/Show.tsx @@ -218,9 +218,9 @@ class BackEnd extends Component { } = this.props; const isChallengeComplete = tests.every(test => test.pass && !test.err); - const submitBtnLabel: string = !isChallengeComplete ? ( - `${t('buttons.run-test')}${testsRunning ? ' ...' : ''}` - ) : t('buttons.submit-and-go'); + const submitBtnLabel: string = !isChallengeComplete + ? `${t('buttons.run-test')}${testsRunning ? ' ...' : ''}` + : t('buttons.submit-and-go'); const blockNameTitle = `${t( `intro:${superBlock}.blocks.${block}.title`