diff --git a/crates/core/src/call_view.rs b/crates/core/src/call_view.rs index 0304ee9..45320d1 100644 --- a/crates/core/src/call_view.rs +++ b/crates/core/src/call_view.rs @@ -18,6 +18,15 @@ pub struct CallListItem { /// Whole seconds from start to end; 0 while recording. pub duration_secs: i64, pub status: CallStatus, + /// What the status pill shows and whether the row needs the user's + /// attention — see [`ListState`]. Computed from `status` and + /// [`uploaded_here`] so the UI does not re-implement the rule. + pub list_state: ListState, + /// Whether this row needs the user to act on it (the dot in + /// `CallList.svelte` and the sidebar header's "N offen" count). Equal + /// to `list_state.needs_action()`, kept as its own field so the UI + /// does not need to know `ListState`'s variants to filter by it. + pub needs_action: bool, pub interrupted: bool, /// The name the user gave the call, if any. pub title: Option, @@ -35,12 +44,15 @@ impl CallListItem { /// row. Nothing is deleted; the fields are just not shown as set. pub fn of(call: &Call, backend_url: &str) -> Self { let uploaded = uploaded_here(call, backend_url); + let list_state = ListState::of(call.status, uploaded); Self { id: call.id, app: call.app.clone(), started_at: call.started_at, duration_secs: duration_secs(call), status: call.status, + list_state, + needs_action: list_state.needs_action(), interrupted: call.interrupted, title: call.title.clone(), crm_transcript_id: if uploaded { @@ -53,6 +65,45 @@ impl CallListItem { } } +/// What the call list row (and the detail header's pill) shows about a +/// call's status. Mirrors [`CallStatus`] one-to-one, except that `Done` +/// splits in two: a call is only ever shown as done ("fertig") once its +/// transcript has actually reached *this build's* backend ([`uploaded_here`]); +/// otherwise — never uploaded, or uploaded to a different backend — it is +/// `ReadyToUpload` ("bereit zum Hochladen"), because from this build's +/// point of view the CRM has not seen it yet. +#[derive(Serialize, Clone, Copy, Debug, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub enum ListState { + Recording, + AwaitingDecision, + Processing, + Failed, + Done, + ReadyToUpload, +} + +impl ListState { + fn of(status: CallStatus, uploaded_here: bool) -> Self { + match status { + CallStatus::Recording => ListState::Recording, + CallStatus::AwaitingDecision => ListState::AwaitingDecision, + CallStatus::Processing => ListState::Processing, + CallStatus::Failed => ListState::Failed, + CallStatus::Done if uploaded_here => ListState::Done, + CallStatus::Done => ListState::ReadyToUpload, + } + } + + /// Whether a row in this state needs the user to act on it: not yet + /// transcribed, or transcribed but not uploaded here. Excludes + /// `Failed` (already shown in red) and the transient + /// `Recording`/`Processing` states. + pub fn needs_action(self) -> bool { + matches!(self, ListState::AwaitingDecision | ListState::ReadyToUpload) + } +} + /// Whole seconds from `started_at` to `ended_at`; 0 while the call has not /// ended (and never negative). pub fn duration_secs(call: &Call) -> i64 { @@ -318,6 +369,8 @@ mod tests { started_at: at(10, 14, 0), duration_secs: 60, status: CallStatus::AwaitingDecision, + list_state: ListState::AwaitingDecision, + needs_action: true, interrupted: true, title: None, crm_transcript_id: None, @@ -351,6 +404,64 @@ mod tests { assert!(uploaded_here(&c, BACKEND)); } + #[test] + fn done_is_fertig_only_once_uploaded_to_this_backend() { + let mut c = call(Some(at(10, 15, 0))); + c.status = CallStatus::Done; + + // Never uploaded. + assert_eq!( + CallListItem::of(&c, BACKEND).list_state, + ListState::ReadyToUpload + ); + + // Uploaded, but to a different backend. + c.crm_transcript_id = Some("4711".into()); + c.crm_base_url = Some(OTHER_BACKEND.into()); + assert_eq!( + CallListItem::of(&c, BACKEND).list_state, + ListState::ReadyToUpload + ); + + // Uploaded to this build's backend. + c.crm_base_url = Some(BACKEND.into()); + assert_eq!(CallListItem::of(&c, BACKEND).list_state, ListState::Done); + } + + #[test] + fn needs_action_marks_awaiting_and_ready_to_upload_only() { + let mut c = call(Some(at(10, 15, 0))); + + c.status = CallStatus::AwaitingDecision; + assert!(CallListItem::of(&c, BACKEND).needs_action, "awaiting"); + + c.status = CallStatus::Done; + assert!( + CallListItem::of(&c, BACKEND).needs_action, + "done, never uploaded" + ); + + for status in [ + CallStatus::Processing, + CallStatus::Failed, + CallStatus::Recording, + ] { + c.status = status; + assert!( + !CallListItem::of(&c, BACKEND).needs_action, + "{status:?} must not show the dot" + ); + } + + c.status = CallStatus::Done; + c.crm_transcript_id = Some("4711".into()); + c.crm_base_url = Some(BACKEND.into()); + assert!( + !CallListItem::of(&c, BACKEND).needs_action, + "done and uploaded here" + ); + } + #[test] fn an_upload_to_another_backend_is_hidden_from_the_list_item() { // Uploaded to OTHER_BACKEND; this build's backend is BACKEND: the @@ -503,6 +614,8 @@ mod tests { "started_at": serde_json::to_value(at(10, 14, 0)).unwrap(), "duration_secs": 60, "status": "failed", + "list_state": "failed", + "needs_action": false, "interrupted": false, "title": "Reklamation", "crm_transcript_id": null, diff --git a/ui/src/lib/CallList.svelte b/ui/src/lib/CallList.svelte index 57236d8..f261d99 100644 --- a/ui/src/lib/CallList.svelte +++ b/ui/src/lib/CallList.svelte @@ -28,12 +28,15 @@ aria-current={call.id === selectedId} onclick={() => onselect(call.id)} > + {#if call.needs_action} + + {/if} {call.title ?? appLine(call)} {call.title ? `${appLine(call)} · ` : ''}{formatListTime(call.started_at)} - + @@ -53,11 +56,12 @@ } .row { + position: relative; display: flex; flex-direction: column; gap: 3px; width: 100%; - padding: 9px 10px; + padding: 9px 10px 9px 18px; border: none; border-radius: 8px; background: none; @@ -67,6 +71,17 @@ cursor: pointer; } + .dot { + position: absolute; + left: 7px; + top: 50%; + transform: translateY(-50%); + width: 7px; + height: 7px; + border-radius: 50%; + background: var(--primary); + } + .row:hover { background: var(--bg); } diff --git a/ui/src/lib/StatusPill.svelte b/ui/src/lib/StatusPill.svelte index 752a900..a50d89d 100644 --- a/ui/src/lib/StatusPill.svelte +++ b/ui/src/lib/StatusPill.svelte @@ -1,21 +1,22 @@ - {pill.text}{#if interrupted && status === 'awaiting_decision'}, unterbrochen{/if} + {pill.text}{#if interrupted && state === 'awaiting_decision'}, unterbrochen{/if}