* Get next status in cycle from current status
(currentStatus: string)
| 27 | * Get next status in cycle from current status |
| 28 | */ |
| 29 | getNextStatus(currentStatus: string): string { |
| 30 | const currentStatusConfig = this.getStatusConfig(currentStatus); |
| 31 | const normalizedCurrentStatus = currentStatusConfig |
| 32 | ? this.normalizeStatusValue(currentStatusConfig.value) |
| 33 | : undefined; |
| 34 | const normalizedConfiguredNextStatus = currentStatusConfig?.nextStatus |
| 35 | ? this.normalizeStatusValue(currentStatusConfig.nextStatus) |
| 36 | : undefined; |
| 37 | const configuredNextStatus = |
| 38 | normalizedConfiguredNextStatus && |
| 39 | normalizedConfiguredNextStatus !== normalizedCurrentStatus |
| 40 | ? this.getStatusConfig(normalizedConfiguredNextStatus) |
| 41 | : undefined; |
| 42 | if (configuredNextStatus) { |
| 43 | return configuredNextStatus.value; |
| 44 | } |
| 45 | |
| 46 | const cycleStatuses = this.getCycleStatuses(); |
| 47 | const currentIndex = this.findStatusIndex(cycleStatuses, currentStatus); |
| 48 | |
| 49 | if (cycleStatuses.length === 0) { |
| 50 | return currentStatusConfig?.value || this.defaultStatus; |
| 51 | } |
| 52 | |
| 53 | if (currentIndex !== -1) { |
| 54 | // Get next status, cycling to first if at end |
| 55 | const nextIndex = (currentIndex + 1) % cycleStatuses.length; |
| 56 | return cycleStatuses[nextIndex].value; |
| 57 | } |
| 58 | |
| 59 | if (!currentStatusConfig) { |
| 60 | // Current status not found, return first cycleable status |
| 61 | return cycleStatuses[0]?.value || this.defaultStatus; |
| 62 | } |
| 63 | |
| 64 | return ( |
| 65 | cycleStatuses.find((status) => status.order > currentStatusConfig.order)?.value || |
| 66 | cycleStatuses[0].value |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get previous status in cycle from current status (reverse cycling) |
no test coverage detected