|
1 |
+ |
//! The problems inbox, described rather than built.
|
|
2 |
+ |
//!
|
|
3 |
+ |
//! <!-- wiki: quasi-overview -->
|
|
4 |
+ |
//!
|
|
5 |
+ |
//! The eighth screen ported, and the last one on the list that needed nothing
|
|
6 |
+ |
//! decided first: `problems.js` is 229 lines and tasks-shaped, a ranked list
|
|
7 |
+ |
//! whose rows act on themselves. The shipped screen is still that file; see
|
|
8 |
+ |
//! [the module above](super).
|
|
9 |
+ |
//!
|
|
10 |
+ |
//! GoingsOn is the list of solutions. A problem is a candidate pulled from
|
|
11 |
+ |
//! somewhere else that becomes work only when promoted, which is why nothing
|
|
12 |
+ |
//! here creates one and why [`promote`](crate::commands::problem::promote) is
|
|
13 |
+ |
//! shared with the command rather than reimplemented: two screens disagreeing
|
|
14 |
+ |
//! about what a promotion defaults to would be two meanings of the word.
|
|
15 |
+ |
//!
|
|
16 |
+ |
//! # The shape
|
|
17 |
+ |
//!
|
|
18 |
+ |
//! - `GET /problems` — the document.
|
|
19 |
+ |
//! - `GET /problems/list` — the ranked list alone, which is what the filters
|
|
20 |
+ |
//! swap.
|
|
21 |
+ |
//! - `POST /problems/{id}/promote` — make a task from it.
|
|
22 |
+ |
//! - `POST /problems/{id}/status` — dismiss it, or send it back to triage.
|
|
23 |
+ |
//!
|
|
24 |
+ |
//! The filters are query params rather than module state, per decision 2 and
|
|
25 |
+ |
//! for the same reason as contacts: `problems.js` holds `{status, source}` in
|
|
26 |
+ |
//! module scope, so the view a user is looking at has no address. Its comment
|
|
27 |
+ |
//! defends that ("the inbox is a working view, not a place you deep-link
|
|
28 |
+ |
//! into"), and the port disagrees on the evidence of the file itself — the
|
|
29 |
+ |
//! source filter needs a workaround, [`sources`], precisely because the list it
|
|
30 |
+ |
//! is drawn from is whatever the last fetch happened to hold.
|
|
31 |
+ |
//!
|
|
32 |
+ |
//! Each status change names its target rather than cycling, which is the same
|
|
33 |
+ |
//! decision the monthly review's goals landed on and for the same reason: a
|
|
34 |
+ |
//! control that derives its target from what it was drawn with races anything
|
|
35 |
+ |
//! that already moved the row.
|
|
36 |
+ |
//!
|
|
37 |
+ |
//! # The sixth finding again, and this time it bit before it was read
|
|
38 |
+ |
//!
|
|
39 |
+ |
//! The target travels as `to`, not as `status`, because `status` is already
|
|
40 |
+ |
//! this screen's view filter. Written the obvious way the route works and the
|
|
41 |
+ |
//! screen moves under the user: dismissing from the Open inbox answers with the
|
|
42 |
+ |
//! Dismissed list, because the write's own parameter is what the next
|
|
43 |
+ |
//! `status_filter` reads back. This port found it by a failing test rather than
|
|
44 |
+ |
//! by reading, which is the argument for the finding the mail port filed
|
|
45 |
+ |
//! against quasicoherent: the convention is held by hand, it is invisible until
|
|
46 |
+ |
//! something collides, and `Params` knows enough to make it a compile-time
|
|
47 |
+ |
//! question. Second screen to hit it, second one to work around it by naming.
|
|
48 |
+ |
|
|
49 |
+ |
// Handlers take their params by value because `quasi_router::Handler` is a
|
|
50 |
+ |
// plain `fn(&S, Params)` pointer, so the signature is the router's and not a
|
|
51 |
+ |
// choice made here. Same allow, for the same reason, as quasi-axum's tests.
|
|
52 |
+ |
#![allow(clippy::needless_pass_by_value)]
|
|
53 |
+ |
|
|
54 |
+ |
use std::collections::{HashMap, HashSet};
|
|
55 |
+ |
|
|
56 |
+ |
use chrono::{DateTime, Utc};
|
|
57 |
+ |
use goingson_core::{Problem, ProblemBand, ProblemFilter, ProblemId, ProblemStatus, ProjectId};
|
|
58 |
+ |
use quasi_router::screen::{Act, Row, Tag};
|
|
59 |
+ |
use quasi_router::{Action, Node, RegionKind, Response, RouteError, Router, Screen, Slot};
|
|
60 |
+ |
|
|
61 |
+ |
use crate::commands::{PromoteProblemInput, promote};
|
|
62 |
+ |
use crate::state::{AppState, DESKTOP_USER_ID};
|
|
63 |
+ |
|
|
64 |
+ |
#[cfg(test)]
|
|
65 |
+ |
mod tests;
|
|
66 |
+ |
|
|
67 |
+ |
/// The status words the filter offers, in triage order. `None` is "everything",
|
|
68 |
+ |
/// which the JS spells as a fifth option on the same control.
|
|
69 |
+ |
const STATUSES: [Option<ProblemStatus>; 5] = [
|
|
70 |
+ |
Some(ProblemStatus::Open),
|
|
71 |
+ |
Some(ProblemStatus::Promoted),
|
|
72 |
+ |
Some(ProblemStatus::Dismissed),
|
|
73 |
+ |
Some(ProblemStatus::Resolved),
|
|
74 |
+ |
None,
|
|
75 |
+ |
];
|
|
76 |
+ |
|
|
77 |
+ |
/// How urgent the score says it is.
|
|
78 |
+ |
///
|
|
79 |
+ |
/// `problems.js` maps the band onto its own palette words (red, yellow, blue,
|
|
80 |
+ |
/// muted). Here it maps onto what the band *means*, which is the tone, and the
|
|
81 |
+ |
/// palette is the renderer's business.
|
|
82 |
+ |
const fn band_tone(band: ProblemBand) -> makeover_layout::Tone {
|
|
83 |
+ |
match band {
|
|
84 |
+ |
ProblemBand::Critical => makeover_layout::Tone::Danger,
|
|
85 |
+ |
ProblemBand::High => makeover_layout::Tone::Warning,
|
|
86 |
+ |
ProblemBand::Medium => makeover_layout::Tone::Info,
|
|
87 |
+ |
ProblemBand::Low => makeover_layout::Tone::Neutral,
|
|
88 |
+ |
}
|
|
89 |
+ |
}
|
|
90 |
+ |
|
|
91 |
+ |
/// What the triage state says about itself.
|
|
92 |
+ |
const fn status_tone(status: ProblemStatus) -> makeover_layout::Tone {
|
|
93 |
+ |
match status {
|
|
94 |
+ |
ProblemStatus::Promoted => makeover_layout::Tone::Success,
|
|
95 |
+ |
ProblemStatus::Resolved => makeover_layout::Tone::Info,
|
|
96 |
+ |
ProblemStatus::Open | ProblemStatus::Dismissed => makeover_layout::Tone::Neutral,
|
|
97 |
+ |
}
|
|
98 |
+ |
}
|
|
99 |
+ |
|
|
100 |
+ |
/// A param that is present and not blank. Blank is absent, which is what the
|
|
101 |
+ |
/// "all sources" option means.
|
|
102 |
+ |
fn text<'a>(params: &'a quasi_router::Params, name: &str) -> Option<&'a str> {
|
|
103 |
+ |
params.get(name).map(str::trim).filter(|v| !v.is_empty())
|
|
104 |
+ |
}
|
|
105 |
+ |
|
|
106 |
+ |
/// The status the screen is filtered to.
|
|
107 |
+ |
///
|
|
108 |
+ |
/// Absent means `Open`, because the inbox question is what is untriaged;
|
|
109 |
+ |
/// `all` means unfiltered. Same three cases as `list_problems`, and an
|
|
110 |
+ |
/// unrecognised word is a 404 rather than a silent fall back to `Open`, which
|
|
111 |
+ |
/// would answer with a different list than the one asked for.
|
|
112 |
+ |
fn status_filter(params: &quasi_router::Params) -> Result<Option<ProblemStatus>, RouteError> {
|
|
113 |
+ |
match text(params, "status") {
|
|
114 |
+ |
None => Ok(Some(ProblemStatus::Open)),
|
|
115 |
+ |
Some(word) if word.eq_ignore_ascii_case("all") => Ok(None),
|
|
116 |
+ |
Some(word) => word
|
|
117 |
+ |
.parse()
|
|
118 |
+ |
.map(Some)
|
|
119 |
+ |
.map_err(|_| RouteError::not_found("not a triage state")),
|
|
120 |
+ |
}
|
|
121 |
+ |
}
|
|
122 |
+ |
|
|
123 |
+ |
/// The word a status filter travels as.
|
|
124 |
+ |
fn status_word(status: Option<ProblemStatus>) -> &'static str {
|
|
125 |
+ |
status.as_ref().map_or("all", ProblemStatus::as_str)
|
|
126 |
+ |
}
|
|
127 |
+ |
|
|
128 |
+ |
/// Carry the current filters on an action, so every control keeps the view it
|
|
129 |
+ |
/// was pressed in. The same job `in_month` does on the monthly review.
|
|
130 |
+ |
fn filtered(mut action: Action, status: Option<ProblemStatus>, source: Option<&str>) -> Action {
|
|
131 |
+ |
action = action.with("status", status_word(status));
|
|
132 |
+ |
if let Some(source) = source {
|
|
133 |
+ |
action = action.with("source", source);
|
|
134 |
+ |
}
|
|
135 |
+ |
action
|
|
136 |
+ |
}
|
|
137 |
+ |
|
|
138 |
+ |
/// The address of the list under a given filter pair.
|
|
139 |
+ |
fn list_action(status: Option<ProblemStatus>, source: Option<&str>) -> Action {
|
|
140 |
+ |
filtered(Action::get("/problems/list"), status, source)
|
|
141 |
+ |
}
|
|
142 |
+ |
|
|
143 |
+ |
/// Read one problem, or answer 404.
|
|
144 |
+ |
fn load(state: &AppState, id: ProblemId) -> Result<Problem, RouteError> {
|
|
145 |
+ |
state
|
|
146 |
+ |
.problems
|
|
147 |
+ |
.get_by_id(id, DESKTOP_USER_ID)
|
|
148 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?
|
|
149 |
+ |
.ok_or_else(|| RouteError::not_found("no such problem"))
|
|
150 |
+ |
}
|
|
151 |
+ |
|
|
152 |
+ |
/// Parse the path id, or answer 404.
|
|
153 |
+ |
fn problem_id(params: &quasi_router::Params) -> Result<ProblemId, RouteError> {
|
|
154 |
+ |
let raw = params
|
|
155 |
+ |
.get("id")
|
|
156 |
+ |
.ok_or_else(|| RouteError::not_found("no id"))?;
|
|
157 |
+ |
uuid::Uuid::parse_str(raw)
|
|
158 |
+ |
.map(ProblemId::from)
|
|
159 |
+ |
.map_err(|_| RouteError::not_found("not an id"))
|
|
160 |
+ |
}
|
|
161 |
+ |
|
|
162 |
+ |
/// Every source that has ever reported a problem, in a stable order.
|
|
163 |
+ |
///
|
|
164 |
+ |
/// Drawn from the whole table rather than from the rows on screen, which is the
|
|
165 |
+ |
/// one place this screen deliberately does more work than `problems.js`. That
|
|
166 |
+ |
/// file builds the option list out of the rows it last fetched, so filtering to
|
|
167 |
+ |
/// a source with nothing Open would empty the control that got you there; it
|
|
168 |
+ |
/// carries a workaround pushing the current selection back in. Reading the
|
|
169 |
+ |
/// sources from the sources removes the need for one.
|
|
170 |
+ |
fn sources(state: &AppState) -> Result<Vec<String>, RouteError> {
|
|
171 |
+ |
let all = state
|
|
172 |
+ |
.problems
|
|
173 |
+ |
.list(DESKTOP_USER_ID, &ProblemFilter::default())
|
|
174 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
175 |
+ |
|
|
176 |
+ |
let mut sources: Vec<String> = all.into_iter().map(|problem| problem.source).collect();
|
|
177 |
+ |
sources.sort_unstable();
|
|
178 |
+ |
sources.dedup();
|
|
179 |
+ |
Ok(sources)
|
|
180 |
+ |
}
|
|
181 |
+ |
|
|
182 |
+ |
/// One problem as a row.
|
|
183 |
+ |
///
|
|
184 |
+ |
/// # What the shipped screen says with a tooltip, and this one says out loud
|
|
185 |
+ |
///
|
|
186 |
+ |
/// `rowHtml` puts the score's derivation in a `title=` on the badge and the
|
|
187 |
+ |
/// source ref in a `title=` on the age. A description has no word for "text
|
|
188 |
+ |
/// that appears if you hover", and should not grow one: hover is absent on a
|
|
189 |
+ |
/// touch screen and on a keyboard, so a `title` is a fact the app knows and
|
|
190 |
+ |
/// most of its users never see. Both move into `meta`, where a plain fact
|
|
191 |
+ |
/// belongs.
|
|
192 |
+ |
///
|
|
193 |
+ |
/// # A finding: the screen never shows staleness
|
|
194 |
+ |
///
|
|
195 |
+ |
/// `ProblemResponse` has carried a `stale` flag since the inbox was built, and
|
|
196 |
+ |
/// the comment on it explains why staleness is shown rather than deleted — a
|
|
197 |
+ |
/// source being briefly unreachable must not erase triage history. Nothing in
|
|
198 |
+ |
/// `problems.js` reads the field. So the backend computes a fact for the user,
|
|
199 |
+ |
/// serialises it, and the screen drops it on the floor. Described, it is a
|
|
200 |
+ |
/// badge like any other. Filed rather than only fixed here, because the shipped
|
|
201 |
+ |
/// screen has the same gap until it retires.
|
|
202 |
+ |
fn row_for(
|
|
203 |
+ |
problem: &Problem,
|
|
204 |
+ |
project: Option<&str>,
|
|
205 |
+ |
last_pull: Option<DateTime<Utc>>,
|
|
206 |
+ |
status: Option<ProblemStatus>,
|
|
207 |
+ |
source: Option<&str>,
|
|
208 |
+ |
) -> Row {
|
|
209 |
+ |
let mut row = Row::new(&problem.title);
|
|
210 |
+ |
|
|
211 |
+ |
if !problem.body.trim().is_empty() {
|
|
212 |
+ |
row = row.secondary(problem.body.clone());
|
|
213 |
+ |
}
|
|
214 |
+ |
|
|
215 |
+ |
// The score leads the row: it is the reason this problem is where it is in
|
|
216 |
+ |
// the list, so it reads before the title in every renderer that puts tokens
|
|
217 |
+ |
// first, and it is the sort key either way.
|
|
218 |
+ |
row = row.token(Tag::badge(problem.painhours().to_string()).tone(band_tone(problem.band())));
|
|
219 |
+ |
|
|
220 |
+ |
// The source is also the filter, which is the click contacts already
|
|
221 |
+ |
// established on a row's own tags. Not latched: a row says what it carries,
|
|
222 |
+ |
// and whether that is the active filter is the band's question.
|
|
223 |
+ |
row = row.token(Tag::chip(
|
|
224 |
+ |
&problem.source,
|
|
225 |
+ |
list_action(status, Some(&problem.source)),
|
|
226 |
+ |
));
|
|
227 |
+ |
|
|
228 |
+ |
if let Some(project) = project {
|
|
229 |
+ |
row = row.token(Tag::badge(project).tone(makeover_layout::Tone::Info));
|
|
230 |
+ |
}
|
|
231 |
+ |
|
|
232 |
+ |
if problem.status.is_settled() {
|
|
233 |
+ |
row = row.token(Tag::badge(problem.status.as_str()).tone(status_tone(problem.status)));
|
|
234 |
+ |
}
|
|
235 |
+ |
|
|
236 |
+ |
// A problem its project has shelved is frozen rather than triaged, and the
|
|
237 |
+ |
// two look identical in a ranking that only shows the score.
|
|
238 |
+ |
if problem.is_dormant() {
|
|
239 |
+ |
row = row.token(Tag::badge("Dormant").tone(makeover_layout::Tone::Neutral));
|
|
240 |
+ |
}
|
|
241 |
+ |
|
|
242 |
+ |
if last_pull.is_some_and(|at| problem.is_stale(at)) {
|
|
243 |
+ |
row = row.token(Tag::badge("Stale").tone(makeover_layout::Tone::Warning));
|
|
244 |
+ |
}
|
|
245 |
+ |
|
|
246 |
+ |
for tag in &problem.tags {
|
|
247 |
+ |
row = row.token(Tag::badge(tag));
|
|
248 |
+ |
}
|
|
249 |
+ |
|
|
250 |
+ |
row = row.meta(format!(
|
|
251 |
+ |
"pain {} x scale {}, aged {} · {}",
|
|
252 |
+ |
problem.pain,
|
|
253 |
+ |
problem.scale,
|
|
254 |
+ |
problem.age(),
|
|
255 |
+ |
problem.source_ref,
|
|
256 |
+ |
));
|
|
257 |
+ |
|
|
258 |
+ |
for act in acts_for(problem, status, source) {
|
|
259 |
+ |
row = row.act(act);
|
|
260 |
+ |
}
|
|
261 |
+ |
|
|
262 |
+ |
row
|
|
263 |
+ |
}
|
|
264 |
+ |
|
|
265 |
+ |
/// The moves a problem offers, which are its triage state's.
|
|
266 |
+ |
fn acts_for(problem: &Problem, status: Option<ProblemStatus>, source: Option<&str>) -> Vec<Act> {
|
|
267 |
+ |
let id = problem.id;
|
|
268 |
+ |
let reopen = || {
|
|
269 |
+ |
Act::new(
|
|
270 |
+ |
"Reopen",
|
|
271 |
+ |
filtered(
|
|
272 |
+ |
Action::post(format!("/problems/{id}/status")).with("status", "Open"),
|
|
273 |
+ |
status,
|
|
274 |
+ |
source,
|
|
275 |
+ |
),
|
|
276 |
+ |
)
|
|
277 |
+ |
};
|
|
278 |
+ |
|
|
279 |
+ |
match problem.status {
|
|
280 |
+ |
ProblemStatus::Open => vec![
|
|
281 |
+ |
Act::new(
|
|
282 |
+ |
"Promote",
|
|
283 |
+ |
filtered(
|
|
284 |
+ |
Action::post(format!("/problems/{id}/promote")),
|
|
285 |
+ |
status,
|
|
286 |
+ |
source,
|
|
287 |
+ |
),
|
|
288 |
+ |
),
|
|
289 |
+ |
Act::new(
|
|
290 |
+ |
"Dismiss",
|
|
291 |
+ |
filtered(
|
|
292 |
+ |
Action::post(format!("/problems/{id}/status")).with("to", "Dismissed"),
|
|
293 |
+ |
status,
|
|
294 |
+ |
source,
|
|
295 |
+ |
),
|
|
296 |
+ |
),
|
|
297 |
+ |
],
|
|
298 |
+ |
// The backlink is the point of promoting, so the row offers it. The JS
|
|
299 |
+ |
// switches view and calls into the tasks module; here it is an address,
|
|
300 |
+ |
// which is the whole of what "open the task" means.
|
|
301 |
+ |
ProblemStatus::Promoted => {
|
|
302 |
+ |
let mut acts = Vec::with_capacity(2);
|
|
303 |
+ |
if let Some(task) = problem.promoted_task_id {
|
|
304 |
+ |
acts.push(Act::new("Open task", Action::get(format!("/tasks/{task}"))));
|
|
305 |
+ |
}
|
|
306 |
+ |
acts.push(reopen());
|
|
307 |
+ |
acts
|
|
308 |
+ |
}
|
|
309 |
+ |
ProblemStatus::Dismissed | ProblemStatus::Resolved => vec![reopen()],
|
|
310 |
+ |
}
|
|
311 |
+ |
}
|
|
312 |
+ |
|
|
313 |
+ |
/// The ranked list, filtered the way the screen's two filters filter it.
|
|
314 |
+ |
///
|
|
315 |
+ |
/// The repository ranks by painhours descending, so nothing here re-sorts. The
|
|
316 |
+ |
/// score moves with the clock, which is why it is computed on read and why the
|
|
317 |
+ |
/// order is the repository's rather than SQL's.
|
|
318 |
+ |
fn ranked(
|
|
319 |
+ |
state: &AppState,
|
|
320 |
+ |
status: Option<ProblemStatus>,
|
|
321 |
+ |
source: Option<&str>,
|
|
322 |
+ |
) -> Result<Node, RouteError> {
|
|
323 |
+ |
let problems = state
|
|
324 |
+ |
.problems
|
|
325 |
+ |
.list(
|
|
326 |
+ |
DESKTOP_USER_ID,
|
|
327 |
+ |
&ProblemFilter {
|
|
328 |
+ |
source: source.map(str::to_owned),
|
|
329 |
+ |
status,
|
|
330 |
+ |
project_id: None,
|
|
331 |
+ |
},
|
|
332 |
+ |
)
|
|
333 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
334 |
+ |
|
|
335 |
+ |
if problems.is_empty() {
|
|
336 |
+ |
return Ok(Node::empty(match (status, source) {
|
|
337 |
+ |
(Some(ProblemStatus::Open), None) => {
|
|
338 |
+ |
"Nothing waiting for triage. Problems arrive from wam and from audit runs; \
|
|
339 |
+ |
they are candidates, and promoting one makes it a task."
|
|
340 |
+ |
}
|
|
341 |
+ |
(Some(_), _) | (None, Some(_)) => "No problems match that filter.",
|
|
342 |
+ |
(None, None) => "No problems yet.",
|
|
343 |
+ |
}));
|
|
344 |
+ |
}
|
|
345 |
+ |
|
|
346 |
+ |
// One project lookup for the whole list rather than one per row, and one
|
|
347 |
+ |
// last-pull lookup per distinct source rather than per row. Both are the
|
|
348 |
+ |
// shape `list_problems` already uses.
|
|
349 |
+ |
let projects = state
|
|
350 |
+ |
.projects
|
|
351 |
+ |
.list_all(DESKTOP_USER_ID)
|
|
352 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
353 |
+ |
let name_of = |id: Option<ProjectId>| {
|
|
354 |
+ |
id.and_then(|id| {
|
|
355 |
+ |
projects
|
|
356 |
+ |
.iter()
|
|
357 |
+ |
.find(|p| p.id == id)
|
|
358 |
+ |
.map(|p| p.name.as_str())
|
|
359 |
+ |
})
|
|
360 |
+ |
};
|
|
361 |
+ |
|
|
362 |
+ |
let mut last_pulls: HashMap<&str, Option<DateTime<Utc>>> = HashMap::new();
|
|
363 |
+ |
for name in problems
|
|
364 |
+ |
.iter()
|
|
365 |
+ |
.map(|problem| problem.source.as_str())
|
|
366 |
+ |
.collect::<HashSet<_>>()
|
|
367 |
+ |
{
|
|
368 |
+ |
let at = state
|
|
369 |
+ |
.problems
|
|
370 |
+ |
.last_pulled_at(DESKTOP_USER_ID, name)
|
|
371 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
372 |
+ |
last_pulls.insert(name, at);
|
|
373 |
+ |
}
|
|
374 |
+ |
|
|
375 |
+ |
Ok(Node::list(problems.iter().map(|problem| {
|
|
376 |
+ |
let last_pull = last_pulls.get(problem.source.as_str()).copied().flatten();
|
|
377 |
+ |
row_for(
|
|
378 |
+ |
problem,
|
|
379 |
+ |
name_of(problem.project_id),
|
|
380 |
+ |
last_pull,
|
|
381 |
+ |
status,
|
|
382 |
+ |
source,
|
|
383 |
+ |
)
|
|
384 |
+ |
})))
|
|
385 |
+ |
}
|
|
386 |
+ |
|
|
387 |
+ |
/// The whole screen.
|
|
388 |
+ |
fn index(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
389 |
+ |
let status = status_filter(¶ms)?;
|
|
390 |
+ |
let source = text(¶ms, "source");
|
|
391 |
+ |
|
|
392 |
+ |
let mut band = Slot::new("problems-band", RegionKind::Band).with(Node::page("Problems"));
|
|
393 |
+ |
|
|
394 |
+ |
for offered in STATUSES {
|
|
395 |
+ |
let latched = offered == status;
|
|
396 |
+ |
band = band.with(Node::Token(
|
|
397 |
+ |
Tag::chip(status_word(offered), list_action(offered, source)).latched(latched),
|
|
398 |
+ |
));
|
|
399 |
+ |
}
|
|
400 |
+ |
|
|
401 |
+ |
// A source that is filtered on stays offered even when it is the only one
|
|
402 |
+ |
// left, so the way back is always on screen: pressing a latched chip clears
|
|
403 |
+ |
// it. Same rule as the contacts tag filter.
|
|
404 |
+ |
for offered in sources(state)? {
|
|
405 |
+ |
let latched = source == Some(offered.as_str());
|
|
406 |
+ |
let action = list_action(status, (!latched).then_some(offered.as_str()));
|
|
407 |
+ |
band = band.with(Node::Token(Tag::chip(&offered, action).latched(latched)));
|
|
408 |
+ |
}
|
|
409 |
+ |
|
|
410 |
+ |
Ok(Screen::list_detail("Problems", false)
|
|
411 |
+ |
.with(band)
|
|
412 |
+ |
.with(Slot::new("problems-list", RegionKind::Pane).with(ranked(state, status, source)?))
|
|
413 |
+ |
.into())
|
|
414 |
+ |
}
|
|
415 |
+ |
|
|
416 |
+ |
/// The list alone, which is what a filter chip replaces.
|
|
417 |
+ |
fn list(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
418 |
+ |
let status = status_filter(¶ms)?;
|
|
419 |
+ |
let source = text(¶ms, "source");
|
|
420 |
+ |
Ok(Response::fragment(
|
|
421 |
+ |
"problems-list",
|
|
422 |
+ |
ranked(state, status, source)?,
|
|
423 |
+ |
))
|
|
424 |
+ |
}
|
|
425 |
+ |
|
|
426 |
+ |
/// Answer a triage decision with the list it happened in, re-read.
|
|
427 |
+ |
///
|
|
428 |
+ |
/// Re-read rather than patched in memory, for the reason the contacts removals
|
|
429 |
+ |
/// are: the row may well leave the list it was in, since the filter it was
|
|
430 |
+ |
/// pressed under is usually `Open` and the press is what settles it.
|
|
431 |
+ |
fn triaged(
|
|
432 |
+ |
state: &AppState,
|
|
433 |
+ |
params: &quasi_router::Params,
|
|
434 |
+ |
message: &str,
|
|
435 |
+ |
) -> Result<Response, RouteError> {
|
|
436 |
+ |
let status = status_filter(params)?;
|
|
437 |
+ |
let source = text(params, "source");
|
|
438 |
+ |
Ok(
|
|
439 |
+ |
Response::fragment("problems-list", ranked(state, status, source)?)
|
|
440 |
+ |
.toast(makeover_layout::Tone::Success, message),
|
|
441 |
+ |
)
|
|
442 |
+ |
}
|
|
443 |
+ |
|
|
444 |
+ |
/// Make a task from a problem.
|
|
445 |
+ |
///
|
|
446 |
+ |
/// One press with nothing to fill in, which is `problems.js`'s decision and a
|
|
447 |
+ |
/// good one: the description defaults to the problem's own text and the
|
|
448 |
+ |
/// priority to its painhours band, and both are better than anything retyped at
|
|
449 |
+ |
/// triage time. Shape the task afterwards if it needs it.
|
|
450 |
+ |
fn promote_one(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
451 |
+ |
let id = problem_id(¶ms)?;
|
|
452 |
+ |
let outcome = promote(
|
|
453 |
+ |
state,
|
|
454 |
+ |
id,
|
|
455 |
+ |
&PromoteProblemInput {
|
|
456 |
+ |
description: None,
|
|
457 |
+ |
priority: None,
|
|
458 |
+ |
},
|
|
459 |
+ |
)
|
|
460 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?;
|
|
461 |
+ |
|
|
462 |
+ |
triaged(
|
|
463 |
+ |
state,
|
|
464 |
+ |
¶ms,
|
|
465 |
+ |
if outcome.created {
|
|
466 |
+ |
"Promoted to a task."
|
|
467 |
+ |
} else {
|
|
468 |
+ |
"Already promoted; the task it made is on the row."
|
|
469 |
+ |
},
|
|
470 |
+ |
)
|
|
471 |
+ |
}
|
|
472 |
+ |
|
|
473 |
+ |
/// Move a problem to a named triage state.
|
|
474 |
+ |
///
|
|
475 |
+ |
/// The target is a param, never derived from what the row was drawn with. Two
|
|
476 |
+ |
/// windows on the same inbox therefore cannot disagree about what "the next
|
|
477 |
+ |
/// state" was.
|
|
478 |
+ |
fn set_status(state: &AppState, params: quasi_router::Params) -> Result<Response, RouteError> {
|
|
479 |
+ |
let id = problem_id(¶ms)?;
|
|
480 |
+ |
let target: ProblemStatus = params
|
|
481 |
+ |
.get("to")
|
|
482 |
+ |
.ok_or_else(|| RouteError::not_found("no status"))?
|
|
483 |
+ |
.parse()
|
|
484 |
+ |
.map_err(|_| RouteError::not_found("not a triage state"))?;
|
|
485 |
+ |
|
|
486 |
+ |
// The row has to exist before the message can claim anything happened to it.
|
|
487 |
+ |
load(state, id)?;
|
|
488 |
+ |
state
|
|
489 |
+ |
.problems
|
|
490 |
+ |
.set_status(id, DESKTOP_USER_ID, target)
|
|
491 |
+ |
.map_err(|error| RouteError::internal(error.to_string()))?
|
|
492 |
+ |
.ok_or_else(|| RouteError::not_found("no such problem"))?;
|
|
493 |
+ |
|
|
494 |
+ |
triaged(
|
|
495 |
+ |
state,
|
|
496 |
+ |
¶ms,
|
|
497 |
+ |
match target {
|
|
498 |
+ |
ProblemStatus::Open => "Back in triage.",
|
|
499 |
+ |
ProblemStatus::Dismissed => "Dismissed. It stays down through the next pull.",
|
|
500 |
+ |
ProblemStatus::Promoted => "Marked promoted.",
|