Skip to content

Mission editing slang #479

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 3 commits into from
Mar 15, 2019
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
11 changes: 3 additions & 8 deletions src/components/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export interface IDispatchProps {
handlePlaygroundExternalSelect: (external: ExternalLibraryName) => void;
}

const assessmentRenderFactory = (cat: string) => (routerProps: RouteComponentProps<any>) => (
<IncubatorContainer assessmentCategory={cat} />
);

const assessmentRegExp = ':assessmentId(-?\\d+)?/:questionId(\\d+)?';

class Application extends React.Component<IApplicationProps, {}> {
Expand All @@ -54,10 +50,7 @@ class Application extends React.Component<IApplicationProps, {}> {
<div className="Application__main">
<Switch>
<Route path="/academy" component={toAcademy(this.props)} />
<Route
path={`/incubator/${assessmentRegExp}`}
render={assessmentRenderFactory('Missions')}
/>
<Route path={`/incubator/${assessmentRegExp}`} render={toIncubator} />
<Route path="/playground" component={Playground} />
<Route path="/login" render={toLogin(this.props)} />
<Route exact={true} path="/" render={this.redirectToAcademy} />
Expand Down Expand Up @@ -97,6 +90,8 @@ const parsePlayground = (props: IApplicationProps) => {
}
};

const toIncubator = (routerProps: RouteComponentProps<any>) => <IncubatorContainer />;

const parsePrgrm = (props: RouteComponentProps<{}>) => {
const qsParsed = qs.parse(props.location.hash);
// legacy support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Application renders correctly 1`] = `
<div className=\\"Application__main\\">
<Switch>
<Route path=\\"/academy\\" component={[Function]} />
<Route path=\\"/incubator/:assessmentId(-?\\\\\\\\d+)?/:questionId(\\\\\\\\d+)?\\" render={[Function]} />
<Route path=\\"/incubator/:assessmentId(-?\\\\\\\\d+)?/:questionId(\\\\\\\\d+)?\\" render={[Function: toIncubator]} />
<Route path=\\"/playground\\" component={[Function: C]} />
<Route path=\\"/login\\" render={[Function]} />
<Route exact={true} path=\\"/\\" render={[Function]} />
Expand Down
1 change: 1 addition & 0 deletions src/components/incubator/EditingWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
handleReplOutputClear: this.props.handleReplOutputClear,
handleReplValueChange: this.props.handleReplValueChange,
hasChapterSelect: true,
hasEditorAutorunButton: false,
hasSaveButton: true,
hasShareButton: false,
isRunning: this.props.isRunning,
Expand Down
57 changes: 15 additions & 42 deletions src/components/incubator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NonIdealState, Spinner } from '@blueprintjs/core';
import * as React from 'react';
import { RouteComponentProps } from 'react-router';

Expand All @@ -10,7 +9,6 @@ import { AssessmentStatuses, IAssessmentOverview } from '../assessment/assessmen
import { OwnProps as AssessmentProps } from '../assessment/AssessmentWorkspace';
import ContentDisplay from '../commons/ContentDisplay';
import { EditingOverviewCard } from '../incubator/EditingOverviewCard';
// import { AnyAction } from 'redux';

const DEFAULT_QUESTION_ID: number = 0;

Expand All @@ -21,7 +19,6 @@ export interface IAssessmentWorkspaceParams {

export interface IAssessmentProps
extends IDispatchProps,
IOwnProps,
RouteComponentProps<IAssessmentWorkspaceParams>,
IStateProps {}

Expand All @@ -30,12 +27,7 @@ export interface IDispatchProps {
handleSubmitAssessment: (id: number) => void;
}

export interface IOwnProps {
assessmentCategory: string;
}

export interface IStateProps {
assessmentOverviews?: IAssessmentOverview[];
isStudent: boolean;
}

Expand Down Expand Up @@ -79,40 +71,21 @@ class Assessment extends React.Component<IAssessmentProps, State> {
}
}

// If there is an assessment to render, create a workspace. The assessment
// overviews must still be loaded for this, to send the due date.
// else if (assessmentId !== null && this.props.assessmentOverviews !== undefined) {
// const overview = this.props.assessmentOverviews.filter(a => a.id === assessmentId)[0]
// const assessmentProps: AssessmentProps = {
// assessmentId,
// questionId,
// notAttempted: overview.status === AssessmentStatuses.not_attempted,
// closeDate: overview.closeAt
// }
// return <AssessmentWorkspaceContainer {...assessmentProps} />
// }

// Otherwise, render a list of assessments to the user.
let display: JSX.Element;
if (this.props.assessmentOverviews === undefined) {
display = <NonIdealState description="Fetching assessment..." visual={<Spinner />} />;
} else {
/** Mission editing card */
const missionEditingCard = this.state.editingOverview ? (
<EditingOverviewCard
overview={this.state.editingOverview}
updateEditingOverview={this.updateEditingOverview}
listingPath="/incubator"
/>
) : null;

display = (
<>
<ImportFromFileComponent updateEditingOverview={this.updateEditingOverview} />
{missionEditingCard}
</>
);
}
/** Mission editing card */
const missionEditingCard = this.state.editingOverview ? (
<EditingOverviewCard
overview={this.state.editingOverview}
updateEditingOverview={this.updateEditingOverview}
listingPath="/incubator"
/>
) : null;

const display = (
<>
<ImportFromFileComponent updateEditingOverview={this.updateEditingOverview} />
{missionEditingCard}
</>
);

// Finally, render the ContentDisplay.
return (
Expand Down
19 changes: 4 additions & 15 deletions src/containers/incubator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@ import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux';
import { withRouter } from 'react-router';
import { bindActionCreators, Dispatch } from 'redux';

import {
fetchAssessmentOverviews,
submitAssessment,
updateAssessment
} from '../../actions/session';
import { IAssessmentOverview } from '../../components/assessment/assessmentShape';
import Assessment, { IDispatchProps, IOwnProps, IStateProps } from '../../components/incubator';
import { fetchAssessmentOverviews, submitAssessment } from '../../actions/session';
import Assessment, { IDispatchProps, IStateProps } from '../../components/incubator';
import { IState, Role } from '../../reducers/states';

const mapStateToProps: MapStateToProps<IStateProps, IOwnProps, IState> = (state, props) => {
const categoryFilter = (overview: IAssessmentOverview) =>
overview.category === props.assessmentCategory;
const mapStateToProps: MapStateToProps<IStateProps, {}, IState> = (state, props) => {
const stateProps: IStateProps = {
assessmentOverviews: state.session.assessmentOverviews
? state.session.assessmentOverviews.filter(categoryFilter)
: undefined,
isStudent: state.session.role ? state.session.role === Role.Student : true
};
return stateProps;
Expand All @@ -27,8 +17,7 @@ const mapDispatchToProps: MapDispatchToProps<IDispatchProps, {}> = (dispatch: Di
bindActionCreators(
{
handleAssessmentOverviewFetch: fetchAssessmentOverviews,
handleSubmitAssessment: submitAssessment,
newAssessment: updateAssessment
handleSubmitAssessment: submitAssessment
},
dispatch
);
Expand Down