A conditional class has never reached the class attribute
Browse files at this commit5189bb99df96686712bfbbb4fda1197a19cfbc95Parent: 9f8c3b7- fix
- a conditional class has never reached the class attribute
5 changed files +91 -13
- crates/izlek-web/src/board.rs +4 -4
- crates/izlek-web/src/detail.rs +16 -6
- crates/izlek-web/src/i18n.rs +2 -2
- crates/izlek-web/tests/http.rs +68 -0
- style/main.scss +1 -1
crates/izlek-web/src/board.rsmodified+4 -4
| @@ -14,7 +14,7 @@ use topcoat::context::Cx; | ||
| 14 | 14 | use topcoat::router::content::Form; |
| 15 | 15 | use topcoat::router::request::headers; |
| 16 | 16 | use topcoat::router::{HeaderName, StatusCode, header, query_params, route}; |
| 17 | -use topcoat::view::view; | |
| 17 | +use topcoat::view::{class, view}; | |
| 18 | 18 | |
| 19 | 19 | use crate::i18n::{Key, Lang, t}; |
| 20 | 20 | use crate::server::{Refusal, accounts, mail, require_user, require_writer}; |
| @@ -361,7 +361,7 @@ async fn render_card( | ||
| 361 | 361 | .collect(); |
| 362 | 362 | view! { |
| 363 | 363 | 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()) | |
| 365 | 365 | draggable=(if may_write { "true" } else { "false" }) |
| 366 | 366 | data-task-id=(task_id.clone()) |
| 367 | 367 | data-from-column=(from_column.clone()) |
| @@ -376,11 +376,11 @@ async fn render_card( | ||
| 376 | 376 | </div> |
| 377 | 377 | <div class="card-title">(card.title.clone())</div> |
| 378 | 378 | <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))> | |
| 380 | 380 | (deadline) |
| 381 | 381 | </span> |
| 382 | 382 | 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> | |
| 384 | 384 | } |
| 385 | 385 | if comments > 0 { <span class="card-comments">(format!("{comments} \u{270e}"))</span> } |
| 386 | 386 | <div class="spacer"></div> |
crates/izlek-web/src/detail.rsmodified+16 -6
| @@ -321,8 +321,21 @@ async fn load_snapshot( | ||
| 321 | 321 | }); |
| 322 | 322 | } |
| 323 | 323 | } |
| 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(); | |
| 324 | 334 | 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 | + { | |
| 326 | 339 | continue; |
| 327 | 340 | } |
| 328 | 341 | linkable.push(LinkTarget { |
| @@ -1802,11 +1815,8 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool, tab: Tab) | ||
| 1802 | 1815 | if may_write { |
| 1803 | 1816 | <form class="subtask-new" method="post" action="/api/create_subtask"> |
| 1804 | 1817 | <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"> | |
| 1810 | 1820 | <button class="edit-save" type="submit">(t(lang, Key::AddSubtask))</button> |
| 1811 | 1821 | </form> |
| 1812 | 1822 | } |
crates/izlek-web/src/i18n.rsmodified+2 -2
| @@ -836,8 +836,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 836 | 836 | (SubtaskGoesWithIt, Tr) => "alt görevi de silinir", |
| 837 | 837 | (SubtasksGoWithIt, En) => "subtasks go with it", |
| 838 | 838 | (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", | |
| 841 | 841 | (NoSubtasks, En) => "no subtasks", |
| 842 | 842 | (NoSubtasks, Tr) => "alt görev yok", |
| 843 | 843 | (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() { | ||
| 1632 | 1632 | ); |
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 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 | + | |
| 1635 | 1703 | #[tokio::test] |
| 1636 | 1704 | async fn a_drop_decided_against_a_stale_board_is_refused() { |
| 1637 | 1705 | let app = App::open().await; |
style/main.scssmodified+1 -1
| @@ -1960,7 +1960,7 @@ img.avatar { | ||
| 1960 | 1960 | margin-bottom: 8px; |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | -.subtask-new-box { | |
| 1963 | +.subtask-new-input { | |
| 1964 | 1964 | flex: 1; |
| 1965 | 1965 | min-width: 0; |
| 1966 | 1966 | } |