forge
Explore
Log in

Don't you dare go Hollow

iz-web: assignee pickers multi-select with search

Browse files at this commit

074b2fde6e5bf15f5cacea04f27061ad2497e83cAhmet Kaan GümüşParent: 6c2d53c
Selected rows use a stronger accent mix so they read on dark.
The task picker posts several user_ids in one go; both pickers
filter with the house dd-search field.
crates/iz-web/src/detail.rsmodified+106 -35
@@ -666,40 +666,58 @@ async fn set_task_tag(cx: &Cx, Form(input): Form<SetTaskTagForm>) -> Redirect {
666666 redirect(cx, None)
667667 }
668668
669-/// Puts someone on a task. A Viewer can neither do this nor be the target.
669+/// Puts people on a task. A Viewer can neither do this nor be a target.
670+/// Repeated `user_id` pairs assign several people in one post — the create
671+/// picker and the task picker's multi-select both land here.
670672 #[route(POST "/api/assign")]
671-async fn assign(cx: &Cx, Form(input): Form<PersonForm>) -> Redirect {
673+async fn assign(cx: &Cx, Form(pairs): Form<Vec<(String, String)>>) -> Redirect {
672674 use iz_core::detail::ActivityKind;
673675 use time::OffsetDateTime;
674676
675- let (actor, _) = match writer_and_task(cx, &input.task_id).await {
677+ let field = |name: &str| {
678+ pairs
679+ .iter()
680+ .find(|(key, _)| key == name)
681+ .map(|(_, value)| value.as_str())
682+ };
683+ let task_id = field("task_id").unwrap_or_default();
684+ let (actor, _) = match writer_and_task(cx, task_id).await {
676685 Ok(pair) => pair,
677686 Err(refusal) => return redirect(cx, Some(refusal)),
678687 };
679688 let store = store(cx).clone();
680-
681- let Some(person) = store.user(&input.user_id).await? else {
682- return redirect(cx, Some(Refusal::NotFound));
683- };
684- if person.workspace_id != actor.workspace_id {
685- return redirect(cx, Some(Refusal::NotFound));
686- }
687- if !person.role.can_be_assigned() {
688- return redirect(cx, Some(Refusal::Forbidden));
689+ let mut seen: Vec<&str> = Vec::new();
690+ for user_id in pairs
691+ .iter()
692+ .filter(|(key, _)| key == "user_id")
693+ .map(|(_, value)| value.as_str())
694+ {
695+ if user_id.is_empty() || seen.iter().any(|id| *id == user_id) {
696+ continue;
697+ }
698+ seen.push(user_id);
699+ let Some(person) = store.user(user_id).await? else {
700+ return redirect(cx, Some(Refusal::NotFound));
701+ };
702+ if person.workspace_id != actor.workspace_id {
703+ return redirect(cx, Some(Refusal::NotFound));
704+ }
705+ if !person.role.can_be_assigned() {
706+ return redirect(cx, Some(Refusal::Forbidden));
707+ }
708+ store.assign_task(task_id, &person.id).await?;
709+ let activity_id = store
710+ .record_activity(
711+ task_id,
712+ Some(&actor.id),
713+ Some(&person.id),
714+ &ActivityKind::Assigned,
715+ &person.display_name,
716+ OffsetDateTime::now_utc(),
717+ )
718+ .await?;
719+ mail(cx).after_activity(store.clone(), activity_id);
689720 }
690-
691- store.assign_task(&input.task_id, &person.id).await?;
692- let activity_id = store
693- .record_activity(
694- &input.task_id,
695- Some(&actor.id),
696- Some(&person.id),
697- &ActivityKind::Assigned,
698- &person.display_name,
699- OffsetDateTime::now_utc(),
700- )
701- .await?;
702- mail(cx).after_activity(store, activity_id);
703721 redirect(cx, None)
704722 }
705723
@@ -1598,6 +1616,49 @@ pub(crate) async fn datepicker_script<'a>(cx: &'a Cx, lang: Lang) -> Result<impl
15981616 Ok(view! { cx => <script>(Unescaped::new_unchecked(js))</script> }.boxed())
15991617 }
16001618
1619+/// Type-to-filter inside an assignee popover. Reuses `.dd-search` and the
1620+/// dropdown's `tr`+`en` match, as a repair on `iz:wire` so a morph does not
1621+/// leave a typed query sitting over unfiltered rows. Enter does not submit
1622+/// the wrapping create form.
1623+async fn assignee_search_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> {
1624+ use topcoat::view::Unescaped;
1625+ const JS: &str = "\
1626+ (function () {\
1627+ if (window.__izAssigneeSearch) { return; }\
1628+ window.__izAssigneeSearch = true;\
1629+ function filterPanel(panel) {\
1630+ var search = panel.querySelector('.dd-search');\
1631+ if (!search) { return; }\
1632+ var q = search.value;\
1633+ var qTr = q.toLocaleLowerCase('tr');\
1634+ var qEn = q.toLowerCase();\
1635+ panel.querySelectorAll('.pop-row').forEach(function (r) {\
1636+ var t = r.textContent;\
1637+ var miss = t.toLocaleLowerCase('tr').indexOf(qTr) === -1 && t.toLowerCase().indexOf(qEn) === -1;\
1638+ r.classList.toggle('dd-option-hidden', qEn !== '' && miss);\
1639+ });\
1640+ }\
1641+ function wire() {\
1642+ document.querySelectorAll('.assignee-pop .pop-panel').forEach(filterPanel);\
1643+ }\
1644+ document.addEventListener('input', function (e) {\
1645+ var search = e.target && e.target.closest && e.target.closest('.assignee-pop .dd-search');\
1646+ if (!search) { return; }\
1647+ window.__izOwn(search, [], ['value']);\
1648+ var panel = search.closest('.pop-panel');\
1649+ if (panel) { filterPanel(panel); }\
1650+ });\
1651+ document.addEventListener('keydown', function (e) {\
1652+ if (e.key !== 'Enter') { return; }\
1653+ if (!e.target || !e.target.closest || !e.target.closest('.assignee-pop .dd-search')) { return; }\
1654+ e.preventDefault();\
1655+ });\
1656+ document.addEventListener('iz:wire', wire);\
1657+ wire();\
1658+ })();";
1659+ Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed())
1660+}
1661+
16011662 async fn assignee_chip<'a>(
16021663 cx: &'a Cx,
16031664 task_id: &'a str,
@@ -1635,24 +1696,30 @@ async fn assignee_picker<'a>(
16351696 }
16361697 let toggle = format!("assign-{task_id}");
16371698 let put_aria = t(lang, Key::PutSomeoneOnThisTask);
1699+ let search_aria = t(lang, Key::Search);
16381700 Ok(view! {
16391701 cx =>
16401702 <div class="edit edit-pop assignee-pop">
16411703 <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label=(put_aria)>
16421704 <label class="assignee-add edit-view edit-hit" for=(toggle.clone())>(topcoat::view::Child::new(glyph::plus(cx).await?))</label>
16431705 <div class="edit-form pop-panel">
1644- <div class="pop-list pop-list-scroll">
1645- for person in people {
1646- <form class="pop-row-form" method="post" action="/api/assign">
1647- <input type="hidden" name="task_id" value=(task_id.to_string())>
1648- <input type="hidden" name="user_id" value=(person.id.clone())>
1649- <button class="pop-row" type="submit">
1706+ <form class="pop-form" method="post" action="/api/assign">
1707+ <input type="hidden" name="task_id" value=(task_id.to_string())>
1708+ <input class="dd-search" type="text" aria-label=(search_aria) autocomplete="off">
1709+ <div class="pop-list pop-list-scroll">
1710+ for person in people {
1711+ <label class="pop-row">
1712+ <input class="visually-hidden" type="checkbox" name="user_id" value=(person.id.clone())>
16501713 (topcoat::view::Child::new(crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "avatar-sm").await?))
16511714 <span class="pop-row-name">(person.display_name.clone())</span>
1652- </button>
1653- </form>
1654- }
1655- </div>
1715+ </label>
1716+ }
1717+ </div>
1718+ <div class="edit-row">
1719+ <button class="edit-save" type="submit">(t(lang, Key::Save))</button>
1720+ <label class="edit-cancel" for=(toggle)>(t(lang, Key::Cancel))</label>
1721+ </div>
1722+ </form>
16561723 (topcoat::view::Child::new(refused(cx, "assign", lang).await?))
16571724 </div>
16581725 </div>
@@ -2438,6 +2505,7 @@ pub async fn task_modal<'a>(
24382505 </div>
24392506 </div>
24402507 (topcoat::view::Child::new(datepicker_script(cx, lang).await?))
2508+ (topcoat::view::Child::new(assignee_search_script(cx).await?))
24412509 (topcoat::view::Child::new(escape_closes(cx).await?))
24422510 }.boxed())
24432511 }
@@ -2890,6 +2958,7 @@ pub async fn new_task_modal<'a>(
28902958 ) -> Result<impl View + 'a> {
28912959 let columns = columns.to_vec();
28922960 let put_on_aria = t(lang, Key::PutSomeoneOnThisTask);
2961+ let search_aria = t(lang, Key::Search);
28932962 let link_aria = t(lang, Key::LinkAnotherTask);
28942963 Ok(view! {
28952964 cx =>
@@ -2964,6 +3033,7 @@ pub async fn new_task_modal<'a>(
29643033 <input class="edit-toggle" type="checkbox" id="new-task-assign" aria-label=(put_on_aria)>
29653034 <label class="assignee-add edit-view edit-hit" for="new-task-assign">(topcoat::view::Child::new(glyph::plus(cx).await?))</label>
29663035 <div class="edit-form pop-panel">
3036+ <input class="dd-search" type="text" aria-label=(search_aria) autocomplete="off">
29673037 <div class="pop-list pop-list-scroll">
29683038 for person in people {
29693039 <label class="pop-row">
@@ -3025,6 +3095,7 @@ pub async fn new_task_modal<'a>(
30253095 </div>
30263096 </div>
30273097 (topcoat::view::Child::new(datepicker_script(cx, lang).await?))
3098+ (topcoat::view::Child::new(assignee_search_script(cx).await?))
30283099 (topcoat::view::Child::new(escape_closes(cx).await?))
30293100 }.boxed())
30303101 }
crates/iz-web/tests/http.rsmodified+90 -13
@@ -5723,16 +5723,18 @@ async fn the_new_task_modal_carries_the_task_tab_fields() {
57235723 // Anchor at the modal div itself — the page's scripts quote `modal-scrim`
57245724 // too — and stop at the first script after it: what sits between is the
57255725 // modal's own markup.
5726- let start = html
5727- .find("modal modal-new-task")
5728- .expect("no modal scrim");
5726+ let start = html.find("modal modal-new-task").expect("no modal scrim");
57295727 let modal = &html[start..];
57305728 let modal = &modal[..modal.find("<script").unwrap_or(modal.len())];
5731- assert!(modal.contains("name=\"tag_id\""), "no project field: {modal}");
5729+ assert!(
5730+ modal.contains("name=\"tag_id\""),
5731+ "no project field: {modal}"
5732+ );
57325733 assert!(
57335734 modal.contains("name=\"assignee_id\""),
57345735 "no assignee field: {modal}"
57355736 );
5737+ assert!(modal.contains("dd-search"), "no assignee search: {modal}");
57365738 assert!(
57375739 modal.contains("name=\"other_id\""),
57385740 "no dependency field: {modal}"
@@ -5814,6 +5816,61 @@ async fn creating_a_task_can_set_project_assignees_and_a_dependency() {
58145816 );
58155817 }
58165818
5819+/// The assign call takes several people in one post: the task picker's
5820+/// multi-select lands as repeated `user_id` pairs, same as a single assign.
5821+#[tokio::test]
5822+async fn assigning_two_people_at_once_puts_both_on_the_card() {
5823+ let app = App::open().await;
5824+ let admin = admin(&app).await;
5825+ invited(&app, &admin, "ayse@iz.sh", "Ayse", Role::Member).await;
5826+ invited(&app, &admin, "berk@iz.sh", "Berk", Role::Member).await;
5827+ let column = first_column(&app).await;
5828+ let task = a_task(&app, &admin, &column, "Two at once").await;
5829+ let ayse = user_id(&app, "ayse@iz.sh").await;
5830+ let berk = user_id(&app, "berk@iz.sh").await;
5831+
5832+ let html =
5833+ String::from_utf8_lossy(&app.get(&format!("/?task={task}"), Some(&admin)).await.bytes)
5834+ .into_owned();
5835+ assert!(
5836+ html.contains("assignee-pop")
5837+ && html.contains("dd-search")
5838+ && html.contains("name=\"user_id\""),
5839+ "the task picker is not a searchable multi-select: {html}"
5840+ );
5841+
5842+ let answer = app
5843+ .post(
5844+ "/api/assign",
5845+ Some(&admin),
5846+ &[("task_id", &task), ("user_id", &ayse), ("user_id", &berk)],
5847+ )
5848+ .await;
5849+ assert_eq!(
5850+ answer.body, "null",
5851+ "the assign was refused: {}",
5852+ answer.body
5853+ );
5854+
5855+ let workspace_id = app.workspace_id().await;
5856+ let board = iz_core::board::load(app.store.as_ref(), &workspace_id)
5857+ .await
5858+ .unwrap()
5859+ .unwrap();
5860+ let card = board
5861+ .columns
5862+ .iter()
5863+ .flat_map(|c| &c.cards)
5864+ .find(|card| card.id == task)
5865+ .expect("the task is not on the board");
5866+ assert!(
5867+ card.assignees.iter().any(|person| person.id == ayse)
5868+ && card.assignees.iter().any(|person| person.id == berk),
5869+ "both people did not land: {:?}",
5870+ card.assignees
5871+ );
5872+}
5873+
58175874 /// A tag from nowhere refuses the whole create: nothing is written, the same
58185875 /// shape as a create into another workspace's column.
58195876 #[tokio::test]
@@ -7849,11 +7906,13 @@ async fn a_reenabled_member_is_signed_back_in() {
78497906 "the stream did not disable the row"
78507907 );
78517908
7852- let enabled = StreamMember { disabled: false, ..disabled };
7909+ let enabled = StreamMember {
7910+ disabled: false,
7911+ ..disabled
7912+ };
78537913 apply_frame(&app.store, StreamFrame::Profile(enabled)).await;
78547914 assert!(
7855- !app
7856- .store
7915+ !app.store
78577916 .user_by_sub("im-bo@iz.sh")
78587917 .await
78597918 .unwrap()
@@ -7861,7 +7920,10 @@ async fn a_reenabled_member_is_signed_back_in() {
78617920 .disabled,
78627921 "the stream did not re-enable the row"
78637922 );
7864- assert_eq!(app.get("/api/me", Some(&bo)).await.status, StatusCode::NO_CONTENT);
7923+ assert_eq!(
7924+ app.get("/api/me", Some(&bo)).await.status,
7925+ StatusCode::NO_CONTENT
7926+ );
78657927 }
78667928
78677929 /// A live update changes only what actually changed. It morphs the fetched
@@ -10212,7 +10274,10 @@ async fn the_switcher_marks_a_live_sibling_on_and_a_dark_one_off() {
1021210274 "the dark sibling reads off: {html}"
1021310275 );
1021410276 assert!(html.contains(">im</a>"), "the dark sibling renders: {html}");
10215- assert!(!html.contains("ok dev"), "the flyout carries dots only: {html}");
10277+ assert!(
10278+ !html.contains("ok dev"),
10279+ "the flyout carries dots only: {html}"
10280+ );
1021610281 }
1021710282
1021810283 /// The marks are pinned without a router, a bundle or a live sibling: a
@@ -10240,18 +10305,30 @@ fn the_switcher_marks_render_from_resolved_probes_alone() {
1024010305 marks.contains("health-dot health-on"),
1024110306 "the ok sibling reads on: {marks}"
1024210307 );
10243- assert!(marks.contains(">in</a>"), "the live sibling renders: {marks}");
10308+ assert!(
10309+ marks.contains(">in</a>"),
10310+ "the live sibling renders: {marks}"
10311+ );
1024410312 assert!(
1024510313 marks.contains("health-dot health-off"),
1024610314 "the dark sibling reads off: {marks}"
1024710315 );
10248- assert!(marks.contains(">im</a>"), "the dark sibling renders: {marks}");
10249- assert!(!marks.contains(">iz</a>"), "iz's own row stays out: {marks}");
10316+ assert!(
10317+ marks.contains(">im</a>"),
10318+ "the dark sibling renders: {marks}"
10319+ );
10320+ assert!(
10321+ !marks.contains(">iz</a>"),
10322+ "iz's own row stays out: {marks}"
10323+ );
1025010324 assert!(
1025110325 marks.contains("title=\"Files\""),
1025210326 "the mark keeps its human name: {marks}"
1025310327 );
10254- assert!(marks.contains("data-hard"), "the links leave this origin: {marks}");
10328+ assert!(
10329+ marks.contains("data-hard"),
10330+ "the links leave this origin: {marks}"
10331+ );
1025510332 assert!(
1025610333 marks.contains(r#"<span class="service-sep">·</span>"#),
1025710334 "middots between: {marks}"
style/main.scssmodified+7 -1
@@ -1817,7 +1817,13 @@ img.avatar {
18171817 transition: background-color var(--dur-fast) var(--ease);
18181818
18191819 &:hover { background: var(--row-hover); }
1820- &:has(:checked) { background: var(--row-hover); }
1820+ &:has(:checked) {
1821+ background: color-mix(in srgb, var(--accent) 32%, var(--surface));
1822+ color: var(--accent-ink);
1823+ }
1824+ &:has(:checked):hover {
1825+ background: color-mix(in srgb, var(--accent) 32%, var(--surface));
1826+ }
18211827 }
18221828
18231829 .pop-row-name { font-size: 12px; }