forge
Explore
Log in

Don't you dare go Hollow

A conditional class has never reached the class attribute

Browse files at this commit

5189bb99df96686712bfbbb4fda1197a19cfbc95Ahmet Kaan GümüşParent: 9f8c3b7
  • fix
    • a conditional class has never reached the class attribute
Show full message
🐛 fix(web): a conditional class has never reached the class attribute

Driving the real page in a browser turned up that `class:foo=(cond)`
renders as a literal `class:foo=""` attribute rather than merging into
`class`. The boolean is honoured — a false one is omitted — but the name
is wrong, so the class never applied. Three states have been invisible
since they were written: a finished card never greyed (`card-done`), an
overdue deadline chip never turned red, and a dateless one never dimmed.
The new parts chip made four.

All four are built with the `class!` macro the rest of the file already
uses, and a test asserts no `class:` survives into the rendered board.

Two fixes the same pass found, both on the subtask block: the new-part
field wore a `field-box` around a `field-input`, which is a box inside a
box and drew as two; and its label read `Subtasks` where every other
label on the page is written upper-case in the string itself.

And the dependency picker no longer offers a task its own parts or its
own whole. The store refuses that edge — the relationship already exists
— so the picker was offering an option that could only ever be refused.
crates/izlek-web/src/board.rsmodified+4 -4
@@ -14,7 +14,7 @@ use topcoat::context::Cx;
1414 use topcoat::router::content::Form;
1515 use topcoat::router::request::headers;
1616 use topcoat::router::{HeaderName, StatusCode, header, query_params, route};
17-use topcoat::view::view;
17+use topcoat::view::{class, view};
1818
1919 use crate::i18n::{Key, Lang, t};
2020 use crate::server::{Refusal, accounts, mail, require_user, require_writer};
@@ -361,7 +361,7 @@ async fn render_card(
361361 .collect();
362362 view! {
363363 cx =>
364- <a class="card" class:card-done=(done_column) href=(href.clone())
364+ <a class=(class!("card", "card-done" if done_column)) href=(href.clone())
365365 draggable=(if may_write { "true" } else { "false" })
366366 data-task-id=(task_id.clone())
367367 data-from-column=(from_column.clone())
@@ -376,11 +376,11 @@ async fn render_card(
376376 </div>
377377 <div class="card-title">(card.title.clone())</div>
378378 <div class="card-foot">
379- <span class="card-deadline" class:card-deadline-overdue=(overdue) class:card-deadline-none=(!dated)>
379+ <span class=(class!("card-deadline", "card-deadline-overdue" if overdue, "card-deadline-none" if !dated))>
380380 (deadline)
381381 </span>
382382 if let Some(parts) = subtasks.clone() {
383- <span class="card-subtasks" class:card-subtasks-open=(subtasks_open)>(format!("{parts} \u{2630}"))</span>
383+ <span class=(class!("card-subtasks", "card-subtasks-open" if subtasks_open))>(format!("{parts} \u{2630}"))</span>
384384 }
385385 if comments > 0 { <span class="card-comments">(format!("{comments} \u{270e}"))</span> }
386386 <div class="spacer"></div>
crates/izlek-web/src/detail.rsmodified+16 -6
@@ -321,8 +321,21 @@ async fn load_snapshot(
321321 });
322322 }
323323 }
324+ // A task's own family is not offered: a parent and its part are
325+ // already related, the store refuses the edge, and a picker that
326+ // offers what will always be refused is a worse control than one that
327+ // does not offer it.
328+ let family: Vec<&str> = detail
329+ .subtasks
330+ .iter()
331+ .map(|part| part.id.as_str())
332+ .chain(detail.parent.iter().map(|whole| whole.id.as_str()))
333+ .collect();
324334 for task in tasks {
325- if task.id == detail.id || taken.contains(&task.id.as_str()) {
335+ if task.id == detail.id
336+ || taken.contains(&task.id.as_str())
337+ || family.contains(&task.id.as_str())
338+ {
326339 continue;
327340 }
328341 linkable.push(LinkTarget {
@@ -1802,11 +1815,8 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab)
18021815 if may_write {
18031816 <form class="subtask-new" method="post" action="/api/create_subtask">
18041817 <input type="hidden" name="parent_id" value=(detail.id.clone())>
1805- <label class="field-box subtask-new-box">
1806- (glyph::plus(cx).await?)
1807- <input class="field-input" type="text" name="title"
1808- placeholder=(t(lang, Key::NewSubtask)) required="" maxlength="200">
1809- </label>
1818+ <input class="field-input subtask-new-input" type="text" name="title"
1819+ placeholder=(t(lang, Key::NewSubtask)) required="" maxlength="200">
18101820 <button class="edit-save" type="submit">(t(lang, Key::AddSubtask))</button>
18111821 </form>
18121822 }
crates/izlek-web/src/i18n.rsmodified+2 -2
@@ -836,8 +836,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
836836 (SubtaskGoesWithIt, Tr) => "alt görevi de silinir",
837837 (SubtasksGoWithIt, En) => "subtasks go with it",
838838 (SubtasksGoWithIt, Tr) => "alt görevi de silinir",
839- (Subtasks, En) => "Subtasks",
840- (Subtasks, Tr) => "Alt görevler",
839+ (Subtasks, En) => "SUBTASKS",
840+ (Subtasks, Tr) => "ALT GÖREVLER",
841841 (NoSubtasks, En) => "no subtasks",
842842 (NoSubtasks, Tr) => "alt görev yok",
843843 (NewSubtask, En) => "Subtask",
crates/izlek-web/tests/http.rsmodified+68 -0
@@ -1632,6 +1632,74 @@ async fn a_viewer_may_not_open_or_move_a_subtask() {
16321632 );
16331633 }
16341634
1635+#[tokio::test]
1636+async fn a_card_wears_its_conditional_classes() {
1637+ // `class:foo=(cond)` renders as a literal attribute in this view macro
1638+ // rather than merging into `class`, so every state that used it — a done
1639+ // card, an overdue chip, a dateless chip, an open-parts chip — was
1640+ // invisible. They are built with `class!` now; this holds that.
1641+ let app = App::open().await;
1642+ let admin = admin(&app).await;
1643+ let columns = columns_of(&app).await;
1644+ let task = a_task(&app, &admin, &columns[0], "Undated").await;
1645+
1646+ let page = app.get("/", Some(&admin)).await;
1647+ let page = String::from_utf8_lossy(&page.bytes);
1648+ assert!(
1649+ !page.contains("class:"),
1650+ "a conditional class rendered as a literal attribute"
1651+ );
1652+ assert!(
1653+ page.contains("card-deadline card-deadline-none"),
1654+ "the dateless chip lost its class"
1655+ );
1656+
1657+ // A card in a done column carries card-done, which is what greys it.
1658+ let done = columns.last().unwrap();
1659+ app.post(
1660+ "/api/move_card",
1661+ Some(&admin),
1662+ &[
1663+ ("task_id", &task),
1664+ ("from_column_id", &columns[0]),
1665+ ("to_column_id", done),
1666+ ],
1667+ )
1668+ .await;
1669+ let page = app.get("/", Some(&admin)).await;
1670+ let page = String::from_utf8_lossy(&page.bytes);
1671+ assert!(page.contains("card card-done"), "a finished card is not marked");
1672+}
1673+
1674+#[tokio::test]
1675+async fn a_parents_own_part_is_not_offered_as_a_blocker() {
1676+ let app = App::open().await;
1677+ let admin = admin(&app).await;
1678+ let columns = columns_of(&app).await;
1679+ let parent = a_task(&app, &admin, &columns[0], "Ship the exporter").await;
1680+ let child = a_task(&app, &admin, &columns[0], "Write the CSV writer").await;
1681+ let stranger = a_task(&app, &admin, &columns[0], "Unrelated work").await;
1682+ app.store.set_parent(&child, Some(&parent)).await.unwrap();
1683+
1684+ // The store refuses a parent-to-part edge, so the picker must not offer
1685+ // one: an option that is always refused is a worse control than no option.
1686+ let page = app.get(&format!("/?task={parent}"), Some(&admin)).await;
1687+ let page = String::from_utf8_lossy(&page.bytes);
1688+ let picker = page
1689+ .split_once("link-pop")
1690+ .map(|(_, rest)| rest.split_once("</div>").map(|(p, _)| p).unwrap_or(rest))
1691+ .unwrap_or_default()
1692+ .to_string();
1693+ assert!(
1694+ !picker.contains(&child),
1695+ "the picker offered the task's own part"
1696+ );
1697+ assert!(
1698+ page.contains(&stranger),
1699+ "an unrelated task vanished from the page"
1700+ );
1701+}
1702+
16351703 #[tokio::test]
16361704 async fn a_drop_decided_against_a_stale_board_is_refused() {
16371705 let app = App::open().await;
style/main.scssmodified+1 -1
@@ -1960,7 +1960,7 @@ img.avatar {
19601960 margin-bottom: 8px;
19611961 }
19621962
1963-.subtask-new-box {
1963+.subtask-new-input {
19641964 flex: 1;
19651965 min-width: 0;
19661966 }