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 {
666 redirect(cx, None)666 redirect(cx, None)
667 }667 }
668 668
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.
670 #[route(POST "/api/assign")]672 #[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 {
672 use iz_core::detail::ActivityKind;674 use iz_core::detail::ActivityKind;
673 use time::OffsetDateTime;675 use time::OffsetDateTime;
674 676
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 {
676 Ok(pair) => pair,685 Ok(pair) => pair,
677 Err(refusal) => return redirect(cx, Some(refusal)),686 Err(refusal) => return redirect(cx, Some(refusal)),
678 };687 };
679 let store = store(cx).clone();688 let store = store(cx).clone();
680-689+ let mut seen: Vec<&str> = Vec::new();
681- let Some(person) = store.user(&input.user_id).await? else {690+ for user_id in pairs
682- return redirect(cx, Some(Refusal::NotFound));691+ .iter()
683- };692+ .filter(|(key, _)| key == "user_id")
684- if person.workspace_id != actor.workspace_id {693+ .map(|(_, value)| value.as_str())
685- return redirect(cx, Some(Refusal::NotFound));694+ {
686- }695+ if user_id.is_empty() || seen.iter().any(|id| *id == user_id) {
687- if !person.role.can_be_assigned() {696+ continue;
688- return redirect(cx, Some(Refusal::Forbidden));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);
689 }720 }
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);
703 redirect(cx, None)721 redirect(cx, None)
704 }722 }
705 723
@@ -1598,6 +1616,49 @@ pub(crate) async fn datepicker_script<'a>(cx: &'a Cx, lang: Lang) -> Result<impl
1598 Ok(view! { cx => <script>(Unescaped::new_unchecked(js))</script> }.boxed())1616 Ok(view! { cx => <script>(Unescaped::new_unchecked(js))</script> }.boxed())
1599 }1617 }
1600 1618
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+
1601 async fn assignee_chip<'a>(1662 async fn assignee_chip<'a>(
1602 cx: &'a Cx,1663 cx: &'a Cx,
1603 task_id: &'a str,1664 task_id: &'a str,
@@ -1635,24 +1696,30 @@ async fn assignee_picker<'a>(
1635 }1696 }
1636 let toggle = format!("assign-{task_id}");1697 let toggle = format!("assign-{task_id}");
1637 let put_aria = t(lang, Key::PutSomeoneOnThisTask);1698 let put_aria = t(lang, Key::PutSomeoneOnThisTask);
1699+ let search_aria = t(lang, Key::Search);
1638 Ok(view! {1700 Ok(view! {
1639 cx =>1701 cx =>
1640 <div class="edit edit-pop assignee-pop">1702 <div class="edit edit-pop assignee-pop">
1641 <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label=(put_aria)>1703 <input class="edit-toggle" type="checkbox" id=(toggle.clone()) aria-label=(put_aria)>
1642 <label class="assignee-add edit-view edit-hit" for=(toggle.clone())>(topcoat::view::Child::new(glyph::plus(cx).await?))</label>1704 <label class="assignee-add edit-view edit-hit" for=(toggle.clone())>(topcoat::view::Child::new(glyph::plus(cx).await?))</label>
1643 <div class="edit-form pop-panel">1705 <div class="edit-form pop-panel">
1644- <div class="pop-list pop-list-scroll">1706+ <form class="pop-form" method="post" action="/api/assign">
1645- for person in people {1707+ <input type="hidden" name="task_id" value=(task_id.to_string())>
1646- <form class="pop-row-form" method="post" action="/api/assign">1708+ <input class="dd-search" type="text" aria-label=(search_aria) autocomplete="off">
1647- <input type="hidden" name="task_id" value=(task_id.to_string())>1709+ <div class="pop-list pop-list-scroll">
1648- <input type="hidden" name="user_id" value=(person.id.clone())>1710+ for person in people {
1649- <button class="pop-row" type="submit">1711+ <label class="pop-row">
1712+ <input class="visually-hidden" type="checkbox" name="user_id" value=(person.id.clone())>
1650 (topcoat::view::Child::new(crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "avatar-sm").await?))1713 (topcoat::view::Child::new(crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "avatar-sm").await?))
1651 <span class="pop-row-name">(person.display_name.clone())</span>1714 <span class="pop-row-name">(person.display_name.clone())</span>
1652- </button>1715+ </label>
1653- </form>1716+ }
1654- }1717+ </div>
1655- </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>
1656 (topcoat::view::Child::new(refused(cx, "assign", lang).await?))1723 (topcoat::view::Child::new(refused(cx, "assign", lang).await?))
1657 </div>1724 </div>
1658 </div>1725 </div>
@@ -2438,6 +2505,7 @@ pub async fn task_modal<'a>(
2438 </div>2505 </div>
2439 </div>2506 </div>
2440 (topcoat::view::Child::new(datepicker_script(cx, lang).await?))2507 (topcoat::view::Child::new(datepicker_script(cx, lang).await?))
2508+ (topcoat::view::Child::new(assignee_search_script(cx).await?))
2441 (topcoat::view::Child::new(escape_closes(cx).await?))2509 (topcoat::view::Child::new(escape_closes(cx).await?))
2442 }.boxed())2510 }.boxed())
2443 }2511 }
@@ -2890,6 +2958,7 @@ pub async fn new_task_modal<'a>(
2890 ) -> Result<impl View + 'a> {2958 ) -> Result<impl View + 'a> {
2891 let columns = columns.to_vec();2959 let columns = columns.to_vec();
2892 let put_on_aria = t(lang, Key::PutSomeoneOnThisTask);2960 let put_on_aria = t(lang, Key::PutSomeoneOnThisTask);
2961+ let search_aria = t(lang, Key::Search);
2893 let link_aria = t(lang, Key::LinkAnotherTask);2962 let link_aria = t(lang, Key::LinkAnotherTask);
2894 Ok(view! {2963 Ok(view! {
2895 cx =>2964 cx =>
@@ -2964,6 +3033,7 @@ pub async fn new_task_modal<'a>(
2964 <input class="edit-toggle" type="checkbox" id="new-task-assign" aria-label=(put_on_aria)>3033 <input class="edit-toggle" type="checkbox" id="new-task-assign" aria-label=(put_on_aria)>
2965 <label class="assignee-add edit-view edit-hit" for="new-task-assign">(topcoat::view::Child::new(glyph::plus(cx).await?))</label>3034 <label class="assignee-add edit-view edit-hit" for="new-task-assign">(topcoat::view::Child::new(glyph::plus(cx).await?))</label>
2966 <div class="edit-form pop-panel">3035 <div class="edit-form pop-panel">
3036+ <input class="dd-search" type="text" aria-label=(search_aria) autocomplete="off">
2967 <div class="pop-list pop-list-scroll">3037 <div class="pop-list pop-list-scroll">
2968 for person in people {3038 for person in people {
2969 <label class="pop-row">3039 <label class="pop-row">
@@ -3025,6 +3095,7 @@ pub async fn new_task_modal<'a>(
3025 </div>3095 </div>
3026 </div>3096 </div>
3027 (topcoat::view::Child::new(datepicker_script(cx, lang).await?))3097 (topcoat::view::Child::new(datepicker_script(cx, lang).await?))
3098+ (topcoat::view::Child::new(assignee_search_script(cx).await?))
3028 (topcoat::view::Child::new(escape_closes(cx).await?))3099 (topcoat::view::Child::new(escape_closes(cx).await?))
3029 }.boxed())3100 }.boxed())
3030 }3101 }
crates/iz-web/tests/http.rsmodified+90 -13
@@ -5723,16 +5723,18 @@ async fn the_new_task_modal_carries_the_task_tab_fields() {
5723 // Anchor at the modal div itself — the page's scripts quote `modal-scrim`5723 // Anchor at the modal div itself — the page's scripts quote `modal-scrim`
5724 // too — and stop at the first script after it: what sits between is the5724 // too — and stop at the first script after it: what sits between is the
5725 // modal's own markup.5725 // modal's own markup.
5726- let start = html5726+ let start = html.find("modal modal-new-task").expect("no modal scrim");
5727- .find("modal modal-new-task")
5728- .expect("no modal scrim");
5729 let modal = &html[start..];5727 let modal = &html[start..];
5730 let modal = &modal[..modal.find("<script").unwrap_or(modal.len())];5728 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+ );
5732 assert!(5733 assert!(
5733 modal.contains("name=\"assignee_id\""),5734 modal.contains("name=\"assignee_id\""),
5734 "no assignee field: {modal}"5735 "no assignee field: {modal}"
5735 );5736 );
5737+ assert!(modal.contains("dd-search"), "no assignee search: {modal}");
5736 assert!(5738 assert!(
5737 modal.contains("name=\"other_id\""),5739 modal.contains("name=\"other_id\""),
5738 "no dependency field: {modal}"5740 "no dependency field: {modal}"
@@ -5814,6 +5816,61 @@ async fn creating_a_task_can_set_project_assignees_and_a_dependency() {
5814 );5816 );
5815 }5817 }
5816 5818
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+
5817 /// A tag from nowhere refuses the whole create: nothing is written, the same5874 /// A tag from nowhere refuses the whole create: nothing is written, the same
5818 /// shape as a create into another workspace's column.5875 /// shape as a create into another workspace's column.
5819 #[tokio::test]5876 #[tokio::test]
@@ -7849,11 +7906,13 @@ async fn a_reenabled_member_is_signed_back_in() {
7849 "the stream did not disable the row"7906 "the stream did not disable the row"
7850 );7907 );
7851 7908
7852- let enabled = StreamMember { disabled: false, ..disabled };7909+ let enabled = StreamMember {
7910+ disabled: false,
7911+ ..disabled
7912+ };
7853 apply_frame(&app.store, StreamFrame::Profile(enabled)).await;7913 apply_frame(&app.store, StreamFrame::Profile(enabled)).await;
7854 assert!(7914 assert!(
7855- !app7915+ !app.store
7856- .store
7857 .user_by_sub("im-bo@iz.sh")7916 .user_by_sub("im-bo@iz.sh")
7858 .await7917 .await
7859 .unwrap()7918 .unwrap()
@@ -7861,7 +7920,10 @@ async fn a_reenabled_member_is_signed_back_in() {
7861 .disabled,7920 .disabled,
7862 "the stream did not re-enable the row"7921 "the stream did not re-enable the row"
7863 );7922 );
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+ );
7865 }7927 }
7866 7928
7867 /// A live update changes only what actually changed. It morphs the fetched7929 /// 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() {
10212 "the dark sibling reads off: {html}"10274 "the dark sibling reads off: {html}"
10213 );10275 );
10214 assert!(html.contains(">im</a>"), "the dark sibling renders: {html}");10276 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+ );
10216 }10281 }
10217 10282
10218 /// The marks are pinned without a router, a bundle or a live sibling: a10283 /// 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() {
10240 marks.contains("health-dot health-on"),10305 marks.contains("health-dot health-on"),
10241 "the ok sibling reads on: {marks}"10306 "the ok sibling reads on: {marks}"
10242 );10307 );
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+ );
10244 assert!(10312 assert!(
10245 marks.contains("health-dot health-off"),10313 marks.contains("health-dot health-off"),
10246 "the dark sibling reads off: {marks}"10314 "the dark sibling reads off: {marks}"
10247 );10315 );
10248- assert!(marks.contains(">im</a>"), "the dark sibling renders: {marks}");10316+ assert!(
10249- assert!(!marks.contains(">iz</a>"), "iz's own row stays out: {marks}");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+ );
10250 assert!(10324 assert!(
10251 marks.contains("title=\"Files\""),10325 marks.contains("title=\"Files\""),
10252 "the mark keeps its human name: {marks}"10326 "the mark keeps its human name: {marks}"
10253 );10327 );
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+ );
10255 assert!(10332 assert!(
10256 marks.contains(r#"<span class="service-sep">·</span>"#),10333 marks.contains(r#"<span class="service-sep">·</span>"#),
10257 "middots between: {marks}"10334 "middots between: {marks}"
style/main.scssmodified+7 -1
@@ -1817,7 +1817,13 @@ img.avatar {
1817 transition: background-color var(--dur-fast) var(--ease);1817 transition: background-color var(--dur-fast) var(--ease);
1818 1818
1819 &:hover { background: var(--row-hover); }1819 &: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+ }
1821 }1827 }
1822 1828
1823 .pop-row-name { font-size: 12px; }1829 .pop-row-name { font-size: 12px; }