From b8d4792fa2fbdc52c8ec417bb5afd49b01a04998 Mon Sep 17 00:00:00 2001 From: Geoffrey Kwan Date: Tue, 24 Oct 2023 13:35:14 -0400 Subject: [PATCH] refactor(Export): Move common code into functions #1482 --- .../PeerChatComponentDataExportStrategy.ts | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts index b77568e6d55..0d8d1e191c8 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts @@ -51,41 +51,34 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat private generateComponentHeaderRow(component: any, columnNameToNumber: any): string[] { const headerRow = this.defaultColumnNames.map((columnName: string) => columnName); const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); - this.insertPromptColumnIfNecessary(headerRow, component); - this.insertPrePromptColumnIfNecessary(headerRow, component); - this.insertDynamicPromptColumnIfNecessary(headerRow, component); - this.insertPostPromptColumnIfNecessary(headerRow, component); - this.insertQuestionColumnsIfNecessary(headerRow, componentStates); - this.insertQuestionUsedColumnIfNecessary(headerRow, component); + this.insertPromptColumns(headerRow, component); + this.insertQuestionColumns(headerRow, component, componentStates); this.populateColumnNameMappings(headerRow, columnNameToNumber); return headerRow; } - private insertPromptColumnIfNecessary(headerRow: string[], component: any): void { + private insertPromptColumns(headerRow: string[], component: any): void { if (!this.hasDynamicPrompt(component)) { this.insertBeforeResponseColumn(headerRow, 'Prompt'); } - } - - private insertPrePromptColumnIfNecessary(headerRow: string[], component: any): void { if (this.hasPrePrompt(component)) { this.insertBeforeResponseColumn(headerRow, 'Pre Prompt'); } - } - - private insertDynamicPromptColumnIfNecessary(headerRow: string[], component: any): void { if (this.hasDynamicPrompt(component)) { this.insertBeforeResponseColumn(headerRow, 'Dynamic Prompt'); } - } - - private insertPostPromptColumnIfNecessary(headerRow: string[], component: any): void { if (this.hasPostPrompt(component)) { this.insertBeforeResponseColumn(headerRow, 'Post Prompt'); } } - private insertQuestionUsedColumnIfNecessary(headerRow: string[], component: any): void { + private insertQuestionColumns(headerRow: string[], component: any, componentStates: any[]): void { + const maxQuestions = this.getMaxQuestionBankCount(componentStates); + if (maxQuestions > 0) { + for (let q = 0; q < maxQuestions; q++) { + headerRow.splice(headerRow.indexOf('Response'), 0, `Question ${q + 1}`); + } + } if (this.isClickToAddEnabled(component)) { this.insertBeforeResponseColumn(headerRow, 'Question Used'); } @@ -115,15 +108,6 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat return component.questionBank?.clickToAddEnabled; } - private insertQuestionColumnsIfNecessary(headerRow: string[], componentStates: any[]): void { - const maxQuestions = this.getMaxQuestionBankCount(componentStates); - if (maxQuestions > 0) { - for (let q = 0; q < maxQuestions; q++) { - headerRow.splice(headerRow.indexOf('Response'), 0, `Question ${q + 1}`); - } - } - } - private getMaxQuestionBankCount(componentStates: any[]): number { let maxQuestionBankCount = 0; for (const componentState of componentStates) {