From 2f99397ca4284b436abbe5afa6945d3dc0121a56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janis=20Daniel=20Da=CC=88hne?=
 <janis.daehne2@student.uni-halle.de>
Date: Mon, 11 Nov 2019 19:18:23 +0100
Subject: [PATCH] - fixed issue where in the tutor view the feedback editor is
 cleared   - for more information see #139 - fixed some typos

---
 .../aceEditors/simpleAceEditor.tsx            |  5 ++++
 .../feedbackPanel/feedbackEditorView.tsx      | 27 +++++++++++++++----
 src/constants.ts                              |  3 ++-
 .../tutorViewSite/tutorViewSiteActions.ts     |  8 +++---
 src/types/submissions.ts                      |  2 +-
 5 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/components/codeEditors/aceEditors/simpleAceEditor.tsx b/src/components/codeEditors/aceEditors/simpleAceEditor.tsx
index 191d2eac..5df15950 100644
--- a/src/components/codeEditors/aceEditors/simpleAceEditor.tsx
+++ b/src/components/codeEditors/aceEditors/simpleAceEditor.tsx
@@ -238,12 +238,17 @@ class SimpleAceEditor extends React.Component<Props, any> {
 
     const editorTabs = AceEditorsStorageHelper.getEditor(this.props.id)
 
+    //can happen if we cleared all AceEditorsStorageHelper
+    if (!editorTabs) return
+
     const wrapperTab = editorTabs.find(p => p.tab.id === this.props.editorTab.id)
     if (!wrapperTab) {
       Logger.error('could not find editor tab!')
       return
     }
 
+    if (!this.aceEditorWrapper.editor) return
+
     this.aceEditorWrapper.editor.$blockScrolling = Infinity
     const newVal = this.aceEditorWrapper.editor.getValue()
 
diff --git a/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx b/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx
index 54d725f2..6cd7efb5 100644
--- a/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx
+++ b/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx
@@ -4,7 +4,7 @@ import {bindActionCreators, Dispatch} from "redux";
 import {returntypeof} from 'react-redux-typescript';
 import {RootState} from '../../../../state/reducers'
 import SimpleCodeEditorWrapper from '../../../codeEditors/simpleCodeEditorWrapper'
-import {tutorFeedbackEditorDebounceInMs} from '../../../../constants'
+import {tutorFeedbackEditorDebounceInMs, tutorViewTutorFeedbackForStudentEditor} from '../../../../constants'
 import {setFeedbackForStudent} from '../../../../state/actions/tutorViewSite/sub/setAssessmentActions'
 import {EditorTab} from '../../../codeEditors/multiTabCodeEditorProps'
 import {KnownInternalTestTypes} from '../../../../types/testTypes'
@@ -14,6 +14,7 @@ import {
   aceTestProtocolLanguage,
   aceTextLanguage
 } from '../../../../helpers/editorHelper'
+import {AceEditorsStorageHelper} from '../../../codeEditors/aceEditors/aceEditorsStorageHelper'
 
 export interface MyProps {
   //readonly test: string
@@ -40,13 +41,15 @@ const dispatchProps = returntypeof(mapDispatchToProps);
 type Props = typeof stateProps & typeof dispatchProps;
 
 
-const tutorFeedbackEditor = 'tutorFeedbackEditor'
-
 class FeedbackEditorView extends React.Component<Props, any> {
   render(): JSX.Element {
 
+    //when we load (also when we click next/previous) submission we clear all AceEditorsStorageHelper
+    //when we load the tutor view with the initial submission we init the feedback editor with the initial feedback (empty)
+    //and we switch to that empty feedback (ace session)
+
     const tempEditorTab: EditorTab = {
-      id: 0,
+      id: 0, //this.props.assessment.userId
       content: (this.props.assessment !== null && this.props.assessment.feedbackForStudent !== null)
                ? this.props.assessment.feedbackForStudent
                : '',
@@ -58,11 +61,25 @@ class FeedbackEditorView extends React.Component<Props, any> {
       isContentVisibleForUser: true,
     }
 
+    const editorTabs = AceEditorsStorageHelper.getEditor(tutorViewTutorFeedbackForStudentEditor)
+
+    if (editorTabs && editorTabs.length === 1 && editorTabs[0].tab.id === -1) {
+      //this was set by the initial tutor view load with the default assessment
+      //because we mounted the feedback editor and then changed tabs...
+      AceEditorsStorageHelper.removeEditor(tutorViewTutorFeedbackForStudentEditor)
+      AceEditorsStorageHelper.addEditor(tutorViewTutorFeedbackForStudentEditor, tempEditorTab)
+
+    } else if (editorTabs === undefined) { //when we load another submission but the feedback editor is visible --> no mount --> no default session
+      //so create a default session (simple editor will re-use the this session if the associated tab has the same id)
+      //this allows us to clear all e.g. undo else we would undo and get the previous/next submission feedback
+      AceEditorsStorageHelper.addEditor(tutorViewTutorFeedbackForStudentEditor, tempEditorTab)
+    }
+
     return (
       <div className="fh" style={{overflow: 'hidden'}}>
 
         <SimpleCodeEditorWrapper
-          id={tutorFeedbackEditor}
+          id={tutorViewTutorFeedbackForStudentEditor}
           editorTab={tempEditorTab}
           onBlur={(content: string, editorTabId: number) => {
             this.props.setFeedbackForStudent(content)
diff --git a/src/constants.ts b/src/constants.ts
index 5be2f39c..cc214edb 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -13,7 +13,7 @@ import Logger from './helpers/logger'
  * y - breaking changes / new features
  * z - fixes, small changes
  */
-export const versionString = '2.5.8'
+export const versionString = '2.5.9'
 
 
 export const supportMail = 'yapex@informatik.uni-halle.de'
@@ -375,6 +375,7 @@ export const tutorViewEditorPanelViewEditorId = 'tutorViewEditorPanelViewEditorI
 export const tutorViewUserSolutionEditorPanelViewEditorId = 'tutorViewUserSolutionEditorPanelViewEditorId'
 export const tutorViewUserAfterSolutionEditorPanelViewEditorId = 'tutorViewUserAfterSolutionEditorPanelViewEditorId'
 export const tutorViewCodeTemplateEditorPanelViewEditorId = 'tutorViewCodeTemplateEditorPanelViewEditorId'
+export const tutorViewTutorFeedbackForStudentEditor = 'tutorViewTutorFeedbackEditor'
 
 
 /**
diff --git a/src/state/actions/tutorViewSite/tutorViewSiteActions.ts b/src/state/actions/tutorViewSite/tutorViewSiteActions.ts
index f29864ef..ca3e2899 100644
--- a/src/state/actions/tutorViewSite/tutorViewSiteActions.ts
+++ b/src/state/actions/tutorViewSite/tutorViewSiteActions.ts
@@ -361,7 +361,7 @@ function _loadTutorViewData(releaseId: number, userId: number, pLangId: number):
       const plang = pLangs.find(p => p.id === userSolution.pLangId)
 
       if (!plang) {
-        Logger.error('[tutorViewSiteActions] could not find plant for user solution')
+        Logger.error('[tutorViewSiteActions] could not find plang for user solution')
       }
 
       const tabs = userSolution.solutionFiles.map<AceStoredTabLike>(p => {
@@ -382,7 +382,7 @@ function _loadTutorViewData(releaseId: number, userId: number, pLangId: number):
       const plang = pLangs.find(p => p.id === tutorSolution.pLangId)
 
       if (!plang) {
-        Logger.error('[tutorViewSiteActions] could not find plant for tutor solution')
+        Logger.error('[tutorViewSiteActions] could not find plang for tutor solution')
       }
 
       const tabs = tutorSolution.solutionFiles.map<AceStoredTabLike>(p => {
@@ -407,7 +407,7 @@ function _loadTutorViewData(releaseId: number, userId: number, pLangId: number):
         const plang = pLangs.find(p => p.id === selectedCodeTemplate.pLangId)
 
         if (!plang) {
-          Logger.error('[tutorViewSiteActions] could not find plant for code template')
+          Logger.error('[tutorViewSiteActions] could not find plang for code template')
         }
 
         const tabs = selectedCodeTemplate.templateFiles.map<AceStoredTabLike>(p => {
@@ -458,7 +458,7 @@ function _loadTutorViewData(releaseId: number, userId: number, pLangId: number):
         const plang = pLangs.find(p => p.id === userAfterSolution.pLangId)
 
         if (!plang) {
-          Logger.error('[tutorViewSiteActions] could not find plant for user after solution')
+          Logger.error('[tutorViewSiteActions] could not find plang for user after solution')
         }
 
         const tabs = userAfterSolution.solutionFiles.map<AceStoredTabLike>(p => {
diff --git a/src/types/submissions.ts b/src/types/submissions.ts
index e3d5c760..12653acb 100644
--- a/src/types/submissions.ts
+++ b/src/types/submissions.ts
@@ -97,7 +97,7 @@ export interface AssessmentFullBase {
    * IF a user solved the exercise with different p langs then this does not count separate because
    * all restrictions are stored at the participation (e.g. time) and thus the p lang does not matter!
    *
-   * CAN be -1 on error
+   * CAN be -1 on error or on unset (heavy to compute...)
    */
   readonly participationCount: number
 
-- 
GitLab