Skip to content

TCA-425 - Update backend projects to advance to next lesson without c… #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions client/src/templates/Challenges/projects/backend/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';

Expand All @@ -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
})
);

Expand All @@ -67,7 +68,8 @@ const mapDispatchToActions = {
initConsole,
initTests,
updateChallengeMeta,
updateSolutionFormValues
updateSolutionFormValues,
submitChallenge
};

// Types
Expand All @@ -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;
Expand Down Expand Up @@ -175,24 +179,28 @@ class BackEnd extends Component<BackEndProps> {
}

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() {
const {
data: {
challengeNode: {
challenge: {
fields: { blockName },
challengeType,
forumTopicId,
title,
description,
instructions,
translationPending,
certification,
superBlock,
block
}
Expand All @@ -205,9 +213,15 @@ class BackEnd extends Component<BackEndProps> {
},
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}`;
Expand Down Expand Up @@ -243,9 +257,7 @@ class BackEnd extends Component<BackEndProps> {
// eslint-disable-next-line @typescript-eslint/unbound-method
onSubmit={this.handleSubmit}
updateSolutionForm={updateSolutionFormValues}
/>
<ProjectToolPanel
guideUrl={getGuideUrl({ forumTopicId, title })}
buttonLabel={submitBtnLabel}
/>
<br />
<Output
Expand All @@ -260,13 +272,6 @@ class BackEnd extends Component<BackEndProps> {
<TestSuite tests={tests} />
<Spacer />
</Col>
<CompletionModal
block={block}
blockName={blockName}
certification={certification}
superBlock={superBlock}
/>
<HelpModal challengeTitle={title} challengeBlock={blockName} />
</Row>
</Grid>
</LearnLayout>
Expand Down
5 changes: 3 additions & 2 deletions client/src/templates/Challenges/projects/solution-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface SubmitProps {
}

interface FormProps extends WithTranslation {
buttonLabel?: string;
challengeType: number;
description?: string;
onSubmit: (arg0: SubmitProps) => void;
Expand Down Expand Up @@ -46,7 +47,7 @@ export class SolutionForm extends Component<FormProps> {
};

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 = [
Expand All @@ -57,7 +58,7 @@ export class SolutionForm extends Component<FormProps> {
{ 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: {
Expand Down