Fix/backend completion (#16699)

* chore(props): Sort props

* fix(backend): Fix backend completion flow

* fix(backend): Create and use backend form values selector
This commit is contained in:
Stuart Taylor
2018-02-16 15:24:37 +00:00
committed by Quincy Larson
parent 82ec375f19
commit 9f034f4f79
4 changed files with 21 additions and 12 deletions

View File

@ -2,6 +2,7 @@ import { Observable } from 'rx';
import { ofType } from 'redux-epic'; import { ofType } from 'redux-epic';
import { import {
backendFormValuesSelector,
challengeMetaSelector, challengeMetaSelector,
moveToNextChallenge, moveToNextChallenge,
submitChallengeComplete, submitChallengeComplete,
@ -97,7 +98,7 @@ function submitSimpleChallenge(type, state) {
); );
} }
function submitBackendChallenge(type, state, { solution }) { function submitBackendChallenge(type, state) {
const tests = testsSelector(state); const tests = testsSelector(state);
if ( if (
type === types.checkChallenge && type === types.checkChallenge &&
@ -114,9 +115,13 @@ function submitBackendChallenge(type, state, { solution }) {
}) })
); );
*/ */
return Observable.empty();
}
if (type === types.submitChallenge.toString()) {
const { id } = challengeSelector(state); const { id } = challengeSelector(state);
const { username } = userSelector(state); const { username } = userSelector(state);
const csrfToken = csrfSelector(state); const csrfToken = csrfSelector(state);
const { solution } = backendFormValuesSelector(state);
const challengeInfo = { id, solution }; const challengeInfo = { id, solution };
return postChallenge( return postChallenge(
'/backend-challenge-completed', '/backend-challenge-completed',

View File

@ -9,6 +9,7 @@ import {
} from 'berkeleys-redux-utils'; } from 'berkeleys-redux-utils';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import noop from 'lodash/noop'; import noop from 'lodash/noop';
import { getValues } from 'redux-form';
import modalEpic from './modal-epic'; import modalEpic from './modal-epic';
import completionEpic from './completion-epic.js'; import completionEpic from './completion-epic.js';
@ -202,10 +203,7 @@ export const isCodeLockedSelector = state => getNS(state).isCodeLocked;
export const isJSEnabledSelector = state => getNS(state).isJSEnabled; export const isJSEnabledSelector = state => getNS(state).isJSEnabled;
export const chatRoomSelector = state => getNS(state).helpChatRoom; export const chatRoomSelector = state => getNS(state).helpChatRoom;
export const challengeModalSelector = export const challengeModalSelector =
state => ( state => getNS(state).isChallengeModalOpen;
getNS(state).isChallengeModalOpen &&
challengeSelector(state).type !== 'backend'
);
export const helpModalSelector = state => getNS(state).isHelpOpen; export const helpModalSelector = state => getNS(state).isHelpOpen;
export const guideURLSelector = state => export const guideURLSelector = state =>
@ -253,6 +251,9 @@ export const challengeTypeSelector = state =>
export const challengeTemplateSelector = state => export const challengeTemplateSelector = state =>
challengeSelector(state).template || null; challengeSelector(state).template || null;
export const backendFormValuesSelector = state =>
getValues(state.form.BackEndChallenge);
export default combineReducers( export default combineReducers(
handleActions( handleActions(
() => ({ () => ({

View File

@ -1,10 +1,13 @@
import { Observable } from 'rx'; import { Observable } from 'rx';
import { getValues } from 'redux-form';
import identity from 'lodash/identity'; import identity from 'lodash/identity';
import { fetchScript } from './fetch-and-cache.js'; import { fetchScript } from './fetch-and-cache.js';
import throwers from '../rechallenge/throwers'; import throwers from '../rechallenge/throwers';
import { challengeTemplateSelector, challengeRequiredSelector } from '../redux'; import {
backendFormValuesSelector,
challengeTemplateSelector,
challengeRequiredSelector
} from '../redux';
import { import {
applyTransformers, applyTransformers,
proxyLoggerTransformer proxyLoggerTransformer
@ -53,7 +56,7 @@ export function buildFromFiles(state, shouldProxyConsole) {
} }
export function buildBackendChallenge(state) { export function buildBackendChallenge(state) {
const { solution: url } = getValues(state.form.BackEndChallenge); const { solution: url } = backendFormValuesSelector(state);
return Observable.combineLatest( return Observable.combineLatest(
fetchScript(frameRunner), fetchScript(frameRunner),
fetchScript(jQuery) fetchScript(jQuery)

View File

@ -102,15 +102,15 @@ export class BackEnd extends PureComponent {
render() { render() {
const { const {
title,
description, description,
tests, executeChallenge,
output, output,
tests,
title,
// provided by redux-form // provided by redux-form
fields: { solution }, fields: { solution },
submitting,
handleSubmit, handleSubmit,
executeChallenge submitting
} = this.props; } = this.props;
const buttonCopy = submitting ? const buttonCopy = submitting ?