* Get previous status in cycle from current status (reverse cycling)
(currentStatus: string)
| 71 | * Get previous status in cycle from current status (reverse cycling) |
| 72 | */ |
| 73 | getPreviousStatus(currentStatus: string): string { |
| 74 | const cycleStatuses = this.getCycleStatuses(); |
| 75 | const currentIndex = this.findStatusIndex(cycleStatuses, currentStatus); |
| 76 | |
| 77 | if (cycleStatuses.length === 0) { |
| 78 | return this.getStatusConfig(currentStatus)?.value || this.defaultStatus; |
| 79 | } |
| 80 | |
| 81 | if (currentIndex !== -1) { |
| 82 | // Get previous status, cycling to last if at beginning |
| 83 | const prevIndex = (currentIndex - 1 + cycleStatuses.length) % cycleStatuses.length; |
| 84 | return cycleStatuses[prevIndex].value; |
| 85 | } |
| 86 | |
| 87 | const currentStatusConfig = this.getStatusConfig(currentStatus); |
| 88 | if (!currentStatusConfig) { |
| 89 | // Current status not found, return last cycleable status |
| 90 | return cycleStatuses[cycleStatuses.length - 1]?.value || this.defaultStatus; |
| 91 | } |
| 92 | |
| 93 | return ( |
| 94 | [...cycleStatuses] |
| 95 | .reverse() |
| 96 | .find((status) => status.order < currentStatusConfig.order)?.value || |
| 97 | cycleStatuses[cycleStatuses.length - 1].value |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get status configuration by value |
no test coverage detected