From c6beb26dc55fbfb33283f6f96a2a4f67ddd3c0a2 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Thu, 26 Oct 2023 13:36:58 -0700 Subject: [PATCH] refactor(NodeService): Clean up getPrevNodeId() for AT/CM modes --- src/assets/wise5/services/nodeService.ts | 31 ++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/assets/wise5/services/nodeService.ts b/src/assets/wise5/services/nodeService.ts index 477521006c7..a539f6ec9a4 100644 --- a/src/assets/wise5/services/nodeService.ts +++ b/src/assets/wise5/services/nodeService.ts @@ -88,33 +88,18 @@ export class NodeService { * Get the previous node in the project sequence * @param currentId (optional) */ - getPrevNodeId(currentId?) { + getPrevNodeId(currentId?: string): string { let prevNodeId = null; - let currentNodeId = null; - const mode = this.ConfigService.getMode(); - if (currentId) { - currentNodeId = currentId; - } else { - let currentNode = null; - currentNode = this.DataService.getCurrentNode(); - if (currentNode) { - currentNodeId = currentNode.id; - } - } + const currentNodeId = currentId ?? this.DataService.getCurrentNodeId(); if (currentNodeId) { - if (['classroomMonitor', 'author'].includes(mode)) { - let currentNodeOrder = this.ProjectService.getNodeOrderById(currentNodeId); + if (['author', 'classroomMonitor'].includes(this.ConfigService.getMode())) { + const currentNodeOrder = this.ProjectService.getNodeOrderById(currentNodeId); if (currentNodeOrder) { - let prevNodeOrder = currentNodeOrder - 1; - let prevId = this.ProjectService.getNodeIdByOrder(prevNodeOrder); + const prevId = this.ProjectService.getNodeIdByOrder(currentNodeOrder - 1); if (prevId) { - if (this.ProjectService.isApplicationNode(prevId)) { - // node is a step, so set it as the next node - prevNodeId = prevId; - } else if (this.ProjectService.isGroupNode(prevId)) { - // node is an activity, so get next nodeId - prevNodeId = this.getPrevNodeId(prevId); - } + prevNodeId = this.ProjectService.isApplicationNode(prevId) + ? prevId + : this.getPrevNodeId(prevId); } } } else {