Skip to content

Commit 075ec4b

Browse files
authored
Merge pull request #5638 from lyttam/BOAC-6748
BOAC-6748: prevents autosave from borking note edit form
2 parents 1271554 + 6ae0b3f commit 075ec4b

14 files changed

Lines changed: 64 additions & 50 deletions

boac/api/peer_advising_notes_controller.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ def update_peer_advising_note():
400400
)
401401
note_read = NoteRead.find_or_create(current_user.get_id(), [note_id])
402402
api_json = get_boac_note_as_compatible_json(note=note, note_read=note_read)
403+
student = data_loch.get_student_by_sid(note.sid)
404+
if student:
405+
api_json['student'] = {
406+
'firstName': student['first_name'],
407+
'lastName': student['last_name'],
408+
'sid': student['sid'],
409+
'uid': student['uid'],
410+
}
403411
return tolerant_jsonify(api_json)
404412

405413

src/api/notes.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function createDraftNote(sid: string) {
6060

6161
export function updateNote(
6262
noteId: number,
63+
isAutoSave: boolean,
6364
body?: string,
6465
cohortIds?: number[],
6566
contactType?: string | null,
@@ -95,7 +96,12 @@ export function updateNote(
9596
const apiPath: string = isPeerAdvisor(contextStore.currentUser) ? '/api/peer_advising/note/update' : '/api/notes/update'
9697
each(attachments, (attachment, index) => args[`attachment[${index}]`] = attachment)
9798
return utils.postMultipartFormData(apiPath, args).then(data => {
98-
const eventType = size(sids) > 1 ? 'notes-batch-published' : 'note-updated'
99+
let eventType = ''
100+
if (isAutoSave) {
101+
eventType = 'note-auto-saved'
102+
} else {
103+
eventType = size(sids) > 1 ? 'notes-batch-published' : 'note-updated'
104+
}
99105
contextStore.broadcast(eventType, data)
100106
$_track('update')
101107
$_refreshMyDraftNoteCount()

src/components/note/CreateNoteFooter.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
:disabled="isSaving || isUpdatingDraft"
2020
text="Cancel"
2121
variant="outlined"
22-
@click="exit"
22+
@click="exit(true)"
2323
/>
2424
<ProgressButton
2525
v-if="!['editTemplate', 'createPeerAdvisorNote', 'editPeerAdvisorNote'].includes(mode)"
@@ -145,7 +145,8 @@ const publish = () => {
145145
isPublishing.value = true
146146
updateNote('Publishing note...').then(() => {
147147
isPublishing.value = false
148-
props.exit('Note published')
148+
alertScreenReader('Note published')
149+
props.exit(false)
149150
})
150151
}
151152
@@ -168,7 +169,7 @@ const updateNote = (alert) => {
168169
const ifAuthenticated = () => {
169170
if (isValidNote) {
170171
props.showAlert(alert, 60)
171-
updateAdvisingNote().then(() => {
172+
updateAdvisingNote(false).then(() => {
172173
alertScreenReader(model.value.isDraft ? `Draft note ${action}` : `Note ${action}`)
173174
noteStore.setIsSaving(false)
174175
props.exit(false)

src/components/note/EditAdvisingNote.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</span>
4040
</transition>
4141
</div>
42-
<div v-if="!isPeerAdvisor(currentUser) && !model.peerAdvisingDepartmentId" class="mt-1">
42+
<div v-if="!isPeerAdvisor(currentUser) && !model.peerAdvisingDepartmentId && !isFetchingNote" class="mt-1">
4343
<label id="edit-note-subject-label" class="font-weight-bold" for="edit-note-subject">
4444
<span class="sr-only">Note </span>Subject
4545
</label>
@@ -298,7 +298,7 @@ const cancelConfirmed = () => {
298298
const editNoteButtonId = `edit-note-${props.noteId}-button`
299299
nextTick(() => {
300300
props.afterCancel()
301-
alertScreenReader('Note discarded.')
301+
alertScreenReader('Canceled edit note.')
302302
exit(true)
303303
putFocusNextTick(editNoteButtonId)
304304
})
@@ -330,6 +330,7 @@ const save = isDraft => {
330330
const trimmedSubject = trim(model.value.subject)
331331
updateNote(
332332
model.value.id,
333+
false,
333334
trim(model.value.body),
334335
[],
335336
model.value.contactType,

src/components/note/EditBatchNoteModal.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ const createTemplate = title => {
306306
// File upload might take time; alert will be overwritten when API call is done.
307307
showAlert('Creating template...', 60)
308308
// Save draft before creating template.
309-
updateAdvisingNote().then(() => {
309+
updateAdvisingNote(false).then(() => {
310310
createNoteTemplate(model.value.id, title).then(() => {
311311
showCreateTemplateModal.value = false
312312
showAlert(`Template '${title}' created.`)
@@ -398,10 +398,6 @@ const init = () => {
398398
if (props.noteId) {
399399
getNote(props.noteId).then(resolve)
400400
} else {
401-
contextStore.broadcast('begin-note-creation', {
402-
completeSidSet: [props.sid],
403-
subject: 'note-creation-is-starting'
404-
})
405401
createDraftNote(props.sid).then(resolve)
406402
}
407403
})

src/components/peer/note/PeerAdvisingNotesTable.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class="font-weight-bold note-student grid-cell"
2424
>
2525
<PeerAdvisorNoteStudentName
26+
:key="`student-name-${index}`"
2627
class="text-wrap"
2728
:note="note"
2829
:show-student-last-name-first="showStudentLastNameFirst"
@@ -370,7 +371,7 @@ const toggleShowHide = (note: Note) => {
370371

371372
<style scoped>
372373
.edit-advising-note-container {
373-
margin-top: -30px;
374+
margin-top: -16px;
374375
padding-right: 25px;
375376
}
376377
.note-action-button {

src/components/peer/note/PeerAdvisorNoteStudentName.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v-if="currentUser.isAdmin || isPeerAdvisorManager(currentUser)"
55
:id="`note-${note.id}-link-to-student`"
66
:class="{'demo-mode-blur': currentUser.inDemoMode}"
7-
:to="studentRoutePath(student.uid, currentUser.inDemoMode)"
7+
:to="studentRoutePath(note.student.uid, currentUser.inDemoMode)"
88
v-html="studentName"
99
/>
1010
<div
@@ -17,6 +17,7 @@
1717
</template>
1818

1919
<script setup lang="ts">
20+
import {computed} from 'vue'
2021
import type {PropType} from 'vue'
2122
import type {Note} from '@/lib/types'
2223
import {isPeerAdvisorManager} from '@/lib/boa-user'
@@ -35,7 +36,10 @@ const props = defineProps({
3536
})
3637
3738
const currentUser = useContextStore().currentUser
38-
const student = props.note.student
39-
const studentName = props.showStudentLastNameFirst ? lastNameFirst(student) : student ? `${student.firstName} ${student.lastName}` : `SID: ${props.note.sid}`
39+
40+
const studentName = computed(() => {
41+
const student = props.note.student
42+
return props.showStudentLastNameFirst ? lastNameFirst(student) : student ? `${student.firstName} ${student.lastName}` : `SID: ${props.note.sid}`
43+
})
4044
</script>
4145

src/components/peer/reports/PeerAdvisingHistoricalReport.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
>
8686
{{ peerAdvisor.name }}
8787
<span v-if="peerAdvisor.deletedAt" class="text-medium-emphasis">
88-
(deleted on <Date :id="`peer-advisor-${peerAdvisor.uid}-deleted-at`" :date="peerAdvisor.deletedAt" />)\
88+
(deleted on <Date :id="`peer-advisor-${peerAdvisor.uid}-deleted-at`" :date="peerAdvisor.deletedAt" />)
8989
</span>
9090
</td>
9191
<td

src/components/student/profile/academic-timeline/AcademicTimeline.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ onMounted(() => {
9494
9595
const onCreateOrUpdateNote = note => {
9696
return new Promise(resolve => {
97-
if (note.sid !== props.student.sid) {
98-
resolve()
99-
}
10097
const noteId = note.parentNoteId || note.id
10198
const existingNoteIndex = findIndex(messages.value, {'id': noteId})
10299
if (existingNoteIndex > -1) {

src/components/student/profile/academic-timeline/AcademicTimelineTable.vue

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ const noteStore = useNoteStore()
475475
476476
const allExpanded = ref(false)
477477
const config = contextStore.config
478-
const creatingNoteEvent = ref(undefined)
479478
const currentUser = contextStore.currentUser
480479
const defaultShowPerTab = ref(5)
481480
const editModeNoteId = ref(undefined)
@@ -536,11 +535,12 @@ onMounted(() => {
536535
'comment-added': onCommentAdded,
537536
'comment-deleted': onCommentDeleted,
538537
'comment-updated': onCommentUpdated,
539-
'note-creation-is-starting': onNoteCreateStartEvent,
540538
'note-created': afterNoteCreated,
541539
'note-updated': note => {
542-
editModeNoteId.value = null
543-
props.onNoteUpdated(note).then(refreshSearchIndex)
540+
if (note.sid === props.student.sid) {
541+
editModeNoteId.value = null
542+
props.onNoteUpdated(note).then(refreshSearchIndex)
543+
}
544544
},
545545
'notes-created': noteIdsBySid => {
546546
const noteId = noteIdsBySid[props.student.sid]
@@ -583,8 +583,9 @@ const afterEditAdvisingNote = (updatedNote, putFocusId) => {
583583
}
584584
585585
const afterNoteCreated = note => {
586-
creatingNoteEvent.value = null
587-
props.onNoteUpdated(note).then(refreshSearchIndex)
586+
if (note.sid === props.student.sid) {
587+
props.onNoteUpdated(note).then(refreshSearchIndex)
588+
}
588589
}
589590
590591
const afterNoteEditCancel = () => {
@@ -774,12 +775,6 @@ const onCommentUpdated = comment => {
774775
}
775776
}
776777
777-
const onNoteCreateStartEvent = event => {
778-
if (includes(event.completeSidSet, props.student.sid)) {
779-
creatingNoteEvent.value = event
780-
}
781-
}
782-
783778
const open = message => {
784779
if ((['eForm', 'note'].includes(message.type) && message.id === editModeNoteId.value)) {
785780
return false

0 commit comments

Comments
 (0)