From 57ff2bebe56ae5391c6eb82e73f8467455d52325 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Mon, 23 Oct 2023 18:36:23 -0700 Subject: [PATCH] refactor(Discussion): Extract common function to show/hide posts --- .../discussion-show-work.component.html | 4 +- .../discussion-show-work.component.ts | 41 ++++--------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.html b/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.html index 0bc605789df..0086ecf9a9a 100644 --- a/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.html +++ b/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.html @@ -5,8 +5,8 @@ [response]="componentState" [numReplies]="componentState.replies.length" [mode]="'grading'" - (deleteButtonClicked)="deleteButtonClicked($event)" - (undoDeleteButtonClicked)="undoDeleteButtonClicked($event)" + (deleteButtonClicked)="hidePost($event)" + (undoDeleteButtonClicked)="showPost($event)" [isDisabled]="true" class="post" > diff --git a/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.ts b/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.ts index 80fcd6b7cd5..d311c5f3e87 100644 --- a/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.ts +++ b/src/assets/wise5/components/discussion/discussion-show-work/discussion-show-work.component.ts @@ -107,37 +107,8 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective { * the class from seeing the post. * @param componentState the student component state the teacher wants to delete. */ - deleteButtonClicked(componentState: any): void { - const toWorkgroupId = componentState.workgroupId; - const userInfo = this.ConfigService.getUserInfoByWorkgroupId(toWorkgroupId); - const periodId = userInfo.periodId; - const teacherUserInfo = this.ConfigService.getMyUserInfo(); - const fromWorkgroupId = teacherUserInfo.workgroupId; - const runId = this.ConfigService.getRunId(); - const nodeId = this.nodeId; - const componentId = this.componentId; - const studentWorkId = componentState.id; - const data = { - action: 'Delete' - }; - const annotation = this.AnnotationService.createInappropriateFlagAnnotation( - runId, - periodId, - nodeId, - componentId, - fromWorkgroupId, - toWorkgroupId, - studentWorkId, - data - ); - this.AnnotationService.saveAnnotation(annotation).then(() => { - const componentStates = this.TeacherDiscussionService.getPostsAssociatedWithComponentIdsAndWorkgroupId( - this.getGradingComponentIds(), - this.workgroupId - ); - const annotations = this.getInappropriateFlagAnnotationsByComponentStates(componentStates); - this.setClassResponses(componentStates, annotations); - }); + protected hidePost(componentState: any): void { + this.flagPost(componentState, 'Delete'); } /** @@ -146,7 +117,11 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective { * This will make the post visible to the students. * @param componentState the student component state the teacher wants to show again. */ - undoDeleteButtonClicked(componentState: any): any { + protected showPost(componentState: any): void { + this.flagPost(componentState, 'Undo Delete'); + } + + private flagPost(componentState: any, action: 'Delete' | 'Undo Delete'): void { const toWorkgroupId = componentState.workgroupId; const userInfo = this.ConfigService.getUserInfoByWorkgroupId(toWorkgroupId); const periodId = userInfo.periodId; @@ -157,7 +132,7 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective { const componentId = this.componentId; const studentWorkId = componentState.id; const data = { - action: 'Undo Delete' + action: action }; const annotation = this.AnnotationService.createInappropriateFlagAnnotation( runId,