Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | 9x 9x 9x 73x 73x 52x 86x 60x 8x 96x 79x 306x 306x 11x 12x 14x 9x 9x 414x 262x 262x 260x 192x 111x | /**
* Workflow State Utilities
*
* Centralized utilities for managing and displaying EventWorkflowState.
* Single source of truth for workflow state logic across the application.
*
* Story 5.1a - Workflow State Machine Foundation
* Refactoring: Eliminates code duplication across EventCard, WorkflowProgressBar,
* and WorkflowProgressBarWithQuery components.
*/
import type { TFunction } from 'i18next';
/**
* Complete 8-step workflow state order for BATbern events.
* States progress linearly from CREATED through ARCHIVED.
* Updated for Story 5.7 - consolidated from 16 states to 9; then to 8 in V82
* (AGENDA_FINALIZED removed — AGENDA_PUBLISHED transitions directly to EVENT_LIVE).
*/
export const WORKFLOW_STATE_ORDER = [
'CREATED',
'TOPIC_SELECTION',
'SPEAKER_IDENTIFICATION',
'SLOT_ASSIGNMENT',
'AGENDA_PUBLISHED',
'EVENT_LIVE',
'EVENT_COMPLETED',
'ARCHIVED',
] as const;
/**
* Type representing valid workflow state values
*/
export type WorkflowStateType = (typeof WORKFLOW_STATE_ORDER)[number];
/**
* Early stage workflow states where topic selection is relevant
*/
const EARLY_STAGE_STATES: readonly string[] = ['CREATED', 'TOPIC_SELECTION'] as const;
/**
* Late stage workflow states where event is essentially complete
*/
const LATE_STAGE_STATES: readonly string[] = ['EVENT_LIVE', 'EVENT_COMPLETED', 'ARCHIVED'] as const;
/**
* Calculate workflow completion percentage from current state.
*
* @param workflowState - The current workflow state (e.g., 'SPEAKER_IDENTIFICATION')
* @returns Progress percentage (0-100), or 0 if state is invalid
*
* @example
* getWorkflowProgress('CREATED') // Returns 13 (step 1/8)
* getWorkflowProgress('ARCHIVED') // Returns 100 (step 8/8)
* getWorkflowProgress('INVALID') // Returns 0
*/
export function getWorkflowProgress(workflowState: string): number {
const currentIndex = WORKFLOW_STATE_ORDER.indexOf(workflowState as WorkflowStateType);
if (currentIndex === -1) return 0;
return Math.round(((currentIndex + 1) / WORKFLOW_STATE_ORDER.length) * 100);
}
/**
* Get the appropriate color for the workflow progress bar based on completion percentage.
*
* Color coding follows Material-UI conventions:
* - warning (yellow): < 30% - early stages, needs attention
* - primary (blue): 30-70% - progressing normally
* - success (green): > 70% - nearly complete or complete
*
* @param progress - Progress percentage (0-100)
* @returns Material-UI color variant
*
* @example
* getProgressColor(20) // Returns 'warning'
* getProgressColor(50) // Returns 'primary'
* getProgressColor(85) // Returns 'success'
*/
export function getProgressColor(progress: number): 'warning' | 'primary' | 'success' {
if (progress < 30) return 'warning';
if (progress < 70) return 'primary';
return 'success';
}
/**
* Generate the i18n translation key for a workflow state.
*
* Converts workflow state to lowercase_snake_case format expected by i18n.
*
* @param state - The workflow state (e.g., 'SPEAKER_OUTREACH')
* @returns i18n key path (e.g., 'workflow.states.speaker_outreach')
*
* @example
* getWorkflowStateI18nKey('CREATED') // Returns 'workflow.states.created'
* getWorkflowStateI18nKey('SPEAKER_OUTREACH') // Returns 'workflow.states.speaker_outreach'
*/
export function getWorkflowStateI18nKey(state: string): string {
return `workflow.states.${state.toLowerCase()}`;
}
/**
* Get the translated human-readable label for a workflow state.
*
* Uses the i18n translation function to return localized state name.
* Falls back to the raw state value if translation is missing.
*
* @param state - The workflow state
* @param t - i18n translation function
* @returns Translated state label (e.g., "Speaker Outreach", "Themenauswahl")
*
* @example
* getWorkflowStateLabel('SPEAKER_OUTREACH', t) // Returns "Speaker Outreach" (EN) or "Referenten-Kontaktaufnahme" (DE)
* getWorkflowStateLabel('CREATED', t) // Returns "Created" (EN) or "Erstellt" (DE)
*/
export function getWorkflowStateLabel(state: string, t: TFunction): string {
return t(getWorkflowStateI18nKey(state), state);
}
/**
* Get the step number for a workflow state (1-8).
*
* @param state - The workflow state
* @returns Step number (1-indexed), or 0 if state is invalid
*
* @example
* getWorkflowStepNumber('CREATED') // Returns 1
* getWorkflowStepNumber('ARCHIVED') // Returns 8
* getWorkflowStepNumber('INVALID') // Returns 0
*/
export function getWorkflowStepNumber(state: string): number {
const index = WORKFLOW_STATE_ORDER.indexOf(state as WorkflowStateType);
return index === -1 ? 0 : index + 1;
}
/**
* Check if the workflow state is in an early stage (CREATED or TOPIC_SELECTION).
*
* Early stages are when topic selection functionality is relevant and should be displayed.
*
* @param state - The workflow state to check
* @returns true if state is CREATED or TOPIC_SELECTION
*
* @example
* isEarlyStage('CREATED') // Returns true
* isEarlyStage('TOPIC_SELECTION') // Returns true
* isEarlyStage('SPEAKER_IDENTIFICATION') // Returns false
*/
export function isEarlyStage(state: string): boolean {
return EARLY_STAGE_STATES.includes(state);
}
/**
* Check if the workflow state is in a late stage (EVENT_LIVE, EVENT_COMPLETED, or ARCHIVED).
*
* Late stages indicate the event workflow is essentially complete.
*
* @param state - The workflow state to check
* @returns true if state is in late stage
*
* @example
* isLateStage('ARCHIVED') // Returns true
* isLateStage('EVENT_COMPLETED') // Returns true
* isLateStage('CREATED') // Returns false
*/
export function isLateStage(state: string): boolean {
return LATE_STAGE_STATES.includes(state);
}
/**
* Validate if a string is a valid workflow state.
*
* @param state - The state string to validate
* @returns true if state is one of the 8 valid workflow states
*
* @example
* isValidWorkflowState('CREATED') // Returns true
* isValidWorkflowState('SPEAKER_IDENTIFICATION') // Returns true
* isValidWorkflowState('INVALID_STATE') // Returns false
*/
export function isValidWorkflowState(state: string): boolean {
return WORKFLOW_STATE_ORDER.includes(state as WorkflowStateType);
}
/* ------------------------------------------------------------------------- *
* Epic 14 — workflow-state → tab-relevance map (lifecycle-aware event page)
* ------------------------------------------------------------------------- */
/**
* The 7 tabs of the redesigned organizer event-detail page.
* Two clusters: the "work" cluster (cockpit … wrapup) and the "config"
* cluster — a single `details` tab whose Info / Tasks / Settings sub-tabs hold
* what used to be the separate Details + Settings tabs (Story 14.F.2 merge).
* These ids are the stable `?tab=` keys and the `data-testid="event-tab-{id}"`
* suffixes consumed by EventPage.
*/
export type EventTabId =
| 'cockpit'
| 'speakers' // "Speakers & Agenda"
| 'registrations'
| 'communications'
| 'publishing'
| 'wrapup'
| 'details'; // config cluster — Info / Tasks / Settings sub-tabs
/**
* Per-tab relevance for a given workflow state.
* - `active` — fully interactive, normal emphasis
* - `dimmed` — visually de-emphasized (not yet the focus) but still usable
* - `locked` — dimmed + 🔒 + non-interactive (not yet applicable)
*/
export type TabRelevance = 'active' | 'dimmed' | 'locked';
/**
* A single row of the relevance table for one workflow state.
* `cockpitEmphasis` is an i18n key suffix describing the "what now" the
* Cockpit should foreground (consumed by Phase B; declared here so the map is
* the single source of truth).
*/
export interface WorkflowRelevance {
cockpitEmphasis: string;
focusTabs: EventTabId[];
dimmedTabs: EventTabId[];
lockedTabs: EventTabId[];
}
/**
* Tabs that are ALWAYS active in every workflow state — orientation +
* set-and-forget config. Checked first in {@link getTabRelevance} so a map
* authoring mistake can never dim or lock them (FR5).
*/
export const ALWAYS_ACTIVE_TABS: readonly EventTabId[] = ['cockpit', 'details'] as const;
/**
* The single declarative `workflowState → relevance` table (FR4, AR2).
*
* Exactly **8 rows** — one per shipped workflow state. There is **no
* `AGENDA_FINALIZED`** (removed in V82, AR1): the "finalize" emphasis the spec
* parked under that state (final newsletter / catering offer / print agenda)
* is attributed here to `AGENDA_PUBLISHED` and surfaced by the Cockpit as
* due-date-driven tasks, not a separate state.
*
* Invariants (enforced by getTabRelevance + unit tests):
* - `cockpit`, `details` never appear in any dimmed/locked list.
* - `wrapup` is locked for CREATED…AGENDA_PUBLISHED and active from EVENT_LIVE.
*/
export const WORKFLOW_RELEVANCE: Record<WorkflowStateType, WorkflowRelevance> = {
CREATED: {
cockpitEmphasis: 'created',
focusTabs: ['details'],
dimmedTabs: ['speakers', 'registrations', 'communications', 'publishing'],
lockedTabs: ['wrapup'],
},
TOPIC_SELECTION: {
cockpitEmphasis: 'topic',
focusTabs: ['details', 'speakers'],
dimmedTabs: ['registrations', 'communications', 'publishing'],
lockedTabs: ['wrapup'],
},
SPEAKER_IDENTIFICATION: {
cockpitEmphasis: 'speakers',
focusTabs: ['speakers', 'publishing'],
dimmedTabs: ['registrations', 'communications'],
lockedTabs: ['wrapup'],
},
SLOT_ASSIGNMENT: {
cockpitEmphasis: 'slots',
focusTabs: ['speakers', 'publishing'],
dimmedTabs: ['communications'],
lockedTabs: ['wrapup'],
},
AGENDA_PUBLISHED: {
// 8-state reconciliation: final newsletter / catering offer / print agenda
cockpitEmphasis: 'finalize',
focusTabs: ['communications', 'registrations'],
dimmedTabs: [],
lockedTabs: ['wrapup'],
},
EVENT_LIVE: {
cockpitEmphasis: 'live',
focusTabs: ['cockpit', 'wrapup'],
dimmedTabs: ['publishing'],
lockedTabs: [],
},
EVENT_COMPLETED: {
cockpitEmphasis: 'wrapup',
focusTabs: ['wrapup', 'communications'],
dimmedTabs: ['speakers', 'publishing'],
lockedTabs: [],
},
ARCHIVED: {
cockpitEmphasis: 'archived',
focusTabs: ['wrapup'],
dimmedTabs: ['speakers', 'registrations', 'communications', 'publishing'],
lockedTabs: [],
},
};
/**
* Resolve a single tab's relevance for a workflow state (FR4/FR5).
*
* Resolution order:
* 1. `cockpit`/`details`/`settings` are always `active` (hard rule).
* 2. An unknown/invalid state defaults to `active` — never throw, never hide a
* tab (a brownfield/legacy state must not blank the page).
* 3. Otherwise the per-state map decides: locked > dimmed > active.
*
* @example
* getTabRelevance('CREATED', 'wrapup') // 'locked'
* getTabRelevance('EVENT_LIVE', 'wrapup') // 'active'
* getTabRelevance('CREATED', 'cockpit') // 'active'
* getTabRelevance('BOGUS', 'wrapup') // 'active' (safe default)
*/
export function getTabRelevance(state: string, tabId: EventTabId): TabRelevance {
if (ALWAYS_ACTIVE_TABS.includes(tabId)) return 'active';
const row = WORKFLOW_RELEVANCE[state as WorkflowStateType];
if (!row) return 'active';
if (row.lockedTabs.includes(tabId)) return 'locked';
if (row.dimmedTabs.includes(tabId)) return 'dimmed';
return 'active';
}
|