Skip to content

Commit 9cfa385

Browse files
authored
Mission editing slang (#512)
* Removed previous button on first question, added divider * Yarn format * Changeded help description * fix import for firefox * max width for globals * symbols aligned * increase abstraction removed numberRange from textArea Reduced save frequency of solutionTemplate * manage questions give warning * UI change for deployment tab * fixed maxGrade and maxXP calculation * added local/global switch * adjust mcq options * split question template tab added suggested answer editing * swap answer and solutionTemplate internal change * add reading * add grading deployment * clone question shift question added * fixed symbol formating * changed manage questions ui * yarn format * added more overview options * add editing persist * Update ManageQuestionTab.tsx * small updates editor value now saved * temp remove editor functionalites * yarn format
1 parent ff0d227 commit 9cfa385

File tree

4 files changed

+36
-43
lines changed

4 files changed

+36
-43
lines changed

src/components/assessment/assessmentShape.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface IMCQQuestion extends IQuestion {
8282

8383
export interface IQuestion {
8484
answer: string | number | null;
85+
editorValue?: string | null;
8586
comment: string | null;
8687
content: string;
8788
id: number;

src/components/incubator/EditingWorkspace.tsx

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
214214
null,
215215
() => {
216216
const assessment = retrieveLocalAssessment()!;
217-
this.handleRefreshLibrary();
218217
this.setState({
219218
assessment,
220219
hasUnsavedChanges: false,
221220
showResetOverlay: false,
222221
originalMaxGrade: this.getMaxMarks('maxGrade'),
223222
originalMaxXp: this.getMaxMarks('maxXp')
224223
});
224+
this.handleRefreshLibrary();
225+
this.resetEditorValue();
225226
},
226227
{ minimal: false, intent: Intent.DANGER }
227228
)}
@@ -248,24 +249,16 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
248249
this.props.storedAssessmentId !== assessmentId ||
249250
this.props.storedQuestionId !== questionId
250251
) {
251-
const question = this.state.assessment!.questions[questionId];
252-
const editorValue =
253-
question.type === QuestionTypes.programming
254-
? (question as IProgrammingQuestion).solutionTemplate || ''
255-
: null;
252+
this.resetEditorValue(false);
256253
this.props.handleUpdateCurrentAssessmentId(assessmentId, questionId);
257-
this.handleRefreshLibrary();
258254
this.props.handleUpdateHasUnsavedChanges(false);
259-
if (editorValue && !this.state.editorPersist) {
260-
this.props.handleResetWorkspace({ editorValue });
261-
this.props.handleEditorValueChange(editorValue);
262-
}
263255
if (this.state.hasUnsavedChanges) {
264256
this.setState({
265257
assessment: retrieveLocalAssessment(),
266258
hasUnsavedChanges: false
267259
});
268260
}
261+
this.handleRefreshLibrary();
269262
}
270263
}
271264

@@ -291,22 +284,32 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
291284
this.props.handleClearContext(library);
292285
};
293286

294-
private resetEditorValue = () => {
295-
if (!this.state.editorPersist) {
287+
private resetEditorValue = (checkPersist: boolean = true) => {
288+
if (checkPersist || !this.state.editorPersist) {
296289
const question: IQuestion = this.state.assessment!.questions[this.formatedQuestionId()];
297-
const editorValue =
298-
question.type === QuestionTypes.programming
299-
? ((question as IProgrammingQuestion).solutionTemplate as string)
300-
: '//If you see this, this is a bug. Please report bug.';
290+
let editorValue: string;
291+
if (question.type === QuestionTypes.programming) {
292+
if (question.editorValue) {
293+
editorValue = question.editorValue;
294+
} else {
295+
editorValue = (question as IProgrammingQuestion).solutionTemplate as string;
296+
}
297+
} else {
298+
editorValue = '//If you see this, this is a bug. Please report bug.';
299+
}
300+
this.props.handleResetWorkspace({ editorValue });
301301
this.props.handleEditorValueChange(editorValue);
302302
}
303303
};
304304

305305
private handleSave = () => {
306+
const assessment = this.state.assessment!;
307+
assessment.questions[this.formatedQuestionId()].editorValue = this.props.editorValue;
306308
this.setState({
309+
assessment,
307310
hasUnsavedChanges: false
308311
});
309-
storeLocalAssessment(this.state.assessment!);
312+
storeLocalAssessment(assessment);
310313
// this.handleRefreshLibrary();
311314
this.handleSaveGradeAndXp();
312315
};
@@ -371,11 +374,11 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
371374
});
372375
};
373376

374-
private toggleEditorPersist = () => {
375-
this.setState({
376-
editorPersist: !this.state.editorPersist
377-
});
378-
};
377+
// private toggleEditorPersist = () => {
378+
// this.setState({
379+
// editorPersist: !this.state.editorPersist
380+
// });
381+
// };
379382

380383
/** Pre-condition: IAssessment has been loaded */
381384
private sideContentProps: (p: AssessmentWorkspaceProps, q: number) => SideContentProps = (
@@ -561,9 +564,9 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
561564
questionProgress: [questionId + 1, this.state.assessment!.questions.length],
562565
sourceChapter: this.state.assessment!.questions[questionId].library.chapter,
563566
editingMode: this.state.editingMode,
564-
toggleEditMode: this.toggleEditingMode,
565-
isEditorPersist: this.state.editorPersist,
566-
handleToggleEditorPersist: this.toggleEditorPersist
567+
toggleEditMode: this.toggleEditingMode
568+
// isEditorPersist: this.state.editorPersist,
569+
// handleToggleEditorPersist: this.toggleEditorPersist
567570
};
568571
};
569572
}

src/components/incubator/editingWorkspaceSideContent/ManageQuestionTab.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,6 @@ export class ManageQuestionTab extends React.Component<IProps, IState> {
8787
IconNames.CONFIRM,
8888
this.confirmSave(this.makeQuestion(mcqTemplate, index))
8989
)}
90-
<br />
91-
{index > 0
92-
? controlButton(
93-
'Shift Question Left',
94-
IconNames.CARET_LEFT,
95-
this.confirmSave(this.shiftQuestion(-1))
96-
)
97-
: undefined}
98-
{index < this.props.assessment.questions.length - 1
99-
? controlButton(
100-
'Shift Question Right',
101-
IconNames.CARET_RIGHT,
102-
this.confirmSave(this.shiftQuestion(1))
103-
)
104-
: undefined}
10590
</div>
10691
);
10792
};

src/components/workspace/ControlBar.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
147147
? controlButton('Reset', IconNames.REPEAT, this.props.onClickReset)
148148
: undefined;
149149
const editorPersistSwitch =
150-
this.props.handleToggleEditorPersist !== null
150+
this.props.handleToggleEditorPersist !== undefined
151151
? controlButton(
152152
'Editor Persistence ' + (this.props.isEditorPersist ? 'Enabled' : 'Disabled'),
153153
this.props.isEditorPersist ? IconNames.TICK : IconNames.CROSS,
@@ -205,7 +205,11 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
205205
' editing mode.'
206206
}
207207
>
208-
{controlButton('Switch editing mode', IconNames.REFRESH, this.props.toggleEditMode)}
208+
{controlButton(
209+
this.props.editingMode + ' editing mode',
210+
IconNames.REFRESH,
211+
this.props.toggleEditMode
212+
)}
209213
</Tooltip>
210214
) : (
211215
undefined

0 commit comments

Comments
 (0)