Public: anyone can read this; the crew can change it.

Asks on a phone: full-width rows, one-thumb actions, and the pull says what it removed #1002

Closed opened this in answer to
Closed without merging

scout/forge:scout/691-asks-on-a-phone-full-width-rows-one-thum → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +153 −55
src/web/studio/asks.ts +49 −43
@@ -873,7 +873,10 @@ export function decisionForm(d: Decision): Html | null {
873873 * word. Saying something to the crew happens on the change's own page,
874874 * where the conversation is — not in a box in a list.
875875 */
876 export function decisionActions(ctx: Ctx, d: Decision): Html {
876 export function decisionSplit(
877 ctx: Ctx,
878 d: Decision,
879 ): { primary: Html; rest: Html | null } {
877880 const base = repoBase(d.repo);
878881 const pull = d.pull;
879882 const preview =
@@ -883,53 +886,56 @@ export function decisionActions(ctx: Ctx, d: Decision): Html {
883886 ? undefined
884887 : `${base}/app/pull-${pull.number}/open`;
885888 if (d.kind === "stopped" && pull)
886 return html`${btn("Tell them", {
887 href: `${changeHref(base, pull.number)}#comment-body`,
888 size: "sm",
889 variant: "primary",
890 })}
891 ${btn("Close", {
892 size: "sm",
893 form: askFormId(d),
894 })}
895 ${btn("See", {
896 href: changeHref(base, pull.number),
897 size: "sm",
898 })}`;
889 return {
890 primary: btn("Tell them", {
891 href: `${changeHref(base, pull.number)}#comment-body`,
892 size: "sm",
893 variant: "primary",
894 }),
895 rest: html`${btn("Close", { size: "sm", form: askFormId(d) })}
896 ${btn("See", { href: changeHref(base, pull.number), size: "sm" })}`,
897 };
899898 if ((d.kind === "look" || d.kind === "review") && pull)
900 return html`${btn("Ship", {
901 size: "sm",
902 form: askFormId(d),
903 variant: "primary",
904 })}
905 ${when(
906 preview,
907 (href) =>
908 html`${btn("Preview", {
909 href,
899 return {
900 primary: btn("Ship", {
901 size: "sm",
902 form: askFormId(d),
903 variant: "primary",
904 }),
905 rest: html`${when(preview, (href) => html`${btn("Preview", { href, size: "sm" })}`)}
906 ${btn("Not like this", {
907 href: `${changeHref(base, pull.number)}#comment-body`,
910908 size: "sm",
911909 })}`,
912 )}
913 ${btn("Not like this", {
914 href: `${changeHref(base, pull.number)}#comment-body`,
915 size: "sm",
916 })}`;
910 };
917911 if (d.kind === "declined" && d.issue)
918 return html`${btn("Answer", {
919 href: `${base}/issues/${d.issue.number}#comment-body`,
920 size: "sm",
921 variant: "primary",
922 })}`;
912 return {
913 primary: btn("Answer", {
914 href: `${base}/issues/${d.issue.number}#comment-body`,
915 size: "sm",
916 variant: "primary",
917 }),
918 rest: null,
919 };
923920 if (d.kind === "parked" && d.issue)
924 return html`${btn("Tell them", {
925 href: `${base}/issues/${d.issue.number}#comment-body`,
926 size: "sm",
927 variant: "primary",
928 })}`;
929 return html`${btn("Settings", {
930 href: `${base}/settings/autonomy`,
931 size: "sm",
932 })}`;
921 return {
922 primary: btn("Tell them", {
923 href: `${base}/issues/${d.issue.number}#comment-body`,
924 size: "sm",
925 variant: "primary",
926 }),
927 rest: null,
928 };
929 return {
930 primary: btn("Settings", { href: `${base}/settings/autonomy`, size: "sm" }),
931 rest: null,
932 };
933 }
934
935 /** Every action on one line (the change page's bar): the primary, then the rest. */
936 export function decisionActions(ctx: Ctx, d: Decision): Html {
937 const { primary, rest } = decisionSplit(ctx, d);
938 return html`${primary} ${rest}`;
933939 }
934940
935941 /**
src/web/studio/asks_page.ts +47 −11
@@ -30,8 +30,8 @@ import {
3030 askSentence,
3131 ASK_WORDS,
3232 ROW_PLURAL,
33 decisionActions,
3433 decisionForm,
34 decisionSplit,
3535 decisionsFor,
3636 forgeNeedsFor,
3737 type AskRow,
@@ -80,6 +80,40 @@ const weight = (c: Consequence, which?: string): Html | null =>
8080 ? html`<b>${c.why}</b>${which === undefined ? null : html`: \u201c${which}\u201d`} · `
8181 : null;
8282
83 /** The kind, in the word the head's meta line opens with. */
84 const KIND_WORD: Readonly<Record<Decision["kind"], string>> = {
85 look: "Look",
86 review: "Review",
87 stopped: "Stopped",
88 parked: "Parked",
89 declined: "Declined",
90 paused: "Paused",
91 };
92
93 /** The head's meta line: the kind, then the repository, on one line. */
94 const meta = (kind: Decision["kind"], r: { ownerName: string; name: string }): Html =>
95 html`<span class="ask-meta muted small">${KIND_WORD[kind]} · ${r.ownerName}/${r.name}</span>`;
96
97 /** A row's icon: a column a phone does without (the kind is in the meta line). */
98 const kindIcon = (kind: Decision["kind"]): Html =>
99 html`<span class="ask-ico">${icon(kind === "look" ? "eye" : "pull")}</span>`;
100
101 /**
102 * A row's actions: the primary at the trailing edge, 44px tall on a phone;
103 * the rest behind one "More" there, flat beside it on a wider screen.
104 */
105 function acts(ctx: Ctx, d: Decision): Html {
106 const { primary, rest } = decisionSplit(ctx, d);
107 return html`<span class="ask-acts"
108 ><span class="ask-primary">${primary}</span>${rest === null
109 ? null
110 : html`<details class="ask-rest">
111 <summary class="btn" data-size="sm">More</summary>
112 ${rest}
113 </details>`}</span
114 >`;
115 }
116
83117 /** One clause, and what happens if nobody acts — never the same sentence twice. */
84118 const clause = (
85119 d: Decision | undefined,
@@ -87,10 +121,12 @@ const clause = (
87121 c: Consequence,
88122 which?: string,
89123 ): Html =>
90 html`<p>
91 ${weight(c, which)}${d === undefined ? null : html`${d.short.charAt(0).toUpperCase()}${d.short.slice(1)}. `}<span class="muted"
92 >If nobody acts, ${ASK_WORDS[kind].ifNothing}.</span
93 >
124 html`<p class="ask-clause${kind === "look" || kind === "review" ? " ask-lookish" : ""}">
125 ${weight(c, which)}${d === undefined
126 ? null
127 : html`<span class="${kind === "look" || kind === "review" ? "ask-short" : ""}"
128 >${d.short.charAt(0).toUpperCase()}${d.short.slice(1)}. </span
129 >`}<span class="muted ask-ifnot">If nobody acts, ${ASK_WORDS[kind].ifNothing}.</span>
94130 </p>`;
95131
96132 function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html {
@@ -102,12 +138,12 @@ function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html
102138 : html`<a href="${base}/settings/autonomy">Paused</a>`;
103139 return card(
104140 html`${clause(d, d.kind, d.consequence)}
105 <div class="bar mt">${decisionActions(ctx, d)}</div>`,
141 <div class="mt">${acts(ctx, d)}</div>`,
106142 {
107143 id: askAnchor(d.id),
108 head: html`${pick(d, picked) ?? icon(d.kind === "look" ? "eye" : "pull")}
144 head: html`${pick(d, picked) ?? kindIcon(d.kind)}
109145 <h2>${title}</h2>
110 <span class="muted small">${d.repo.ownerName}/${d.repo.name}</span>`,
146 ${meta(d.kind, d.repo)}`,
111147 },
112148 );
113149 }
@@ -132,7 +168,7 @@ function rowCard(ctx: Ctx, r: AskRow<Decision>, picked: ReadonlySet<string>): Ht
132168 return row({
133169 ...(box === null ? {} : { lead: box }),
134170 title: html`<a href="${href}">${d.pull?.title ?? d.issue?.title ?? ""}</a>`,
135 meta: html`<span class="bar">${decisionActions(ctx, d)}</span>`,
171 meta: acts(ctx, d),
136172 });
137173 });
138174 // On a phone a group is its head line, its asks one tap away, so two
@@ -155,9 +191,9 @@ function rowCard(ctx: Ctx, r: AskRow<Decision>, picked: ReadonlySet<string>): Ht
155191 data-select-all
156192 aria-label="Select all ${r.items.length}"
157193 />`
158 : icon(r.kind === "look" ? "eye" : "pull")}
194 : kindIcon(r.kind)}
159195 <h2>${rowHead(r.kind, r.items.length)}</h2>
160 <span class="muted small">${r.repo.ownerName}/${r.repo.name}</span>`,
196 ${meta(r.kind, r.repo)}`,
161197 // The row ranks by its weightiest ask (first, `askRows`): name it.
162198 foot: clause(
163199 undefined,
src/web/style/content.ts +38
@@ -1197,4 +1197,42 @@ textarea.editor:focus { outline: none; }
11971197 }
11981198 }
11991199 .needs-you .ask-group > summary { padding: 10px 14px; cursor: pointer; }
1200 /* Asks: the primary action at a row's trailing edge, the rest flat beside
1201 it where a details element can be held open (elsewhere: behind "More"). */
1202 .needs-you .ask-acts { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
1203 .needs-you .ask-rest { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
1204 .needs-you .ask-rest > summary { list-style: none; cursor: pointer; }
1205 .needs-you .ask-rest > summary::-webkit-details-marker { display: none; }
1206 @supports selector(::details-content) {
1207 @media (min-width: 481px) {
1208 .needs-you .ask-rest > summary { display: none; }
1209 .needs-you .ask-rest::details-content { content-visibility: visible; display: contents; }
1210 }
1211 }
1212 /* A phone: rows use the full width (the page's 16px gutter is the only
1213 margin), no card box, no icon column, a title that wraps, the kind and
1214 the repository on one line, a thumb-sized action at the trailing edge. */
1215 @media (max-width: 600px) {
1216 .needs-you .card { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: none; box-shadow: none; }
1217 .needs-you .card-head { background: none; border: 0; padding: 12px 0 0; gap: 4px 8px; }
1218 .needs-you .card-body { padding: 2px 0 12px; }
1219 .needs-you .card-foot { background: none; border: 0; padding: 0 0 12px; }
1220 .needs-you .card-head h2 { order: 2; flex: 1 1 100%; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
1221 .needs-you .ask-meta { order: 1; flex: 1 1 0; min-width: 0; }
1222 .needs-you .ask-pick { order: 0; }
1223 .needs-you .ask-ico, .needs-you .ask-ifnot, .needs-you .ask-short { display: none; }
1224 .needs-you .ask-clause { margin: 0; }
1225 .needs-you .ask-lookish:not(:has(b)) { display: none; }
1226 .needs-you .ask-group > summary { padding: 10px 0; min-height: 44px; display: flex; align-items: center; }
1227 .needs-you .row { padding: 8px 0; flex-wrap: wrap; }
1228 .needs-you .row-title { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
1229 .needs-you .row-meta { white-space: normal; overflow: visible; }
1230 .needs-you .ask-acts { display: flex; width: 100%; justify-content: flex-end; margin-top: 6px; }
1231 .needs-you .ask-primary { order: 2; flex: 1 1 0; display: flex; }
1232 .needs-you .ask-primary .btn { flex: 1; min-height: 44px; }
1233 .needs-you .ask-rest { order: 1; }
1234 .needs-you .ask-rest > summary { min-height: 44px; display: inline-flex; align-items: center; }
1235 .needs-you .ask-rest .btn { min-height: 44px; }
1236 .needs-you .ask-rest:not([open]) > :not(summary) { display: none; }
1237 }
12001238 `;
test/asks-rank.test.ts +19 −1
@@ -248,7 +248,7 @@ describe("asks that earn their place", () => {
248248 expect(asks).toContain("<summary>1 more</summary>");
249249 // The phone's "more" opens in place to every ask: the wide screen's
250250 // "more" sits inside it, and the stylesheet hides each where it is not.
251 expect(wide!.indexOf('id="asks-more"')).toBeLessThan(wide!.indexOf("</details>"));
251 expect(wide!.indexOf('id="asks-more"')).toBeLessThan(wide!.lastIndexOf("</details>"));
252252 const css = await (await fetch(`${servers.url}${home.match(/href="(\/[^"]*\.css[^"]*)"/)![1]}`)).text();
253253 // Only where the browser can hold a details element open: an older one
254254 // keeps both summaries, so no ask is out of reach.
@@ -355,4 +355,22 @@ describe("asks that earn their place", () => {
355355 ".needs-you .ask-group > summary { display: none; }",
356356 );
357357 });
358 test("a phone's ask is a full-width row: kind with repo, primary at the trailing edge, the rest behind More (#691)", async () => {
359 const home = await page("/");
360 const asks = home.slice(home.indexOf('<section id="needs-you"'));
361 // The kind and the repository share one line.
362 expect(asks).toMatch(/<span class="ask-meta muted small">(Look|Review|Stopped|Parked|Paused|Declined) · [^<]+\/[^<]+<\/span>/);
363 // The primary action stands alone; the others sit in one "More".
364 expect(asks).toContain('<span class="ask-primary">');
365 expect(asks).toContain('<details class="ask-rest">');
366 expect(asks).toContain("<summary class=\"btn\" data-size=\"sm\">More</summary>");
367 // The repeated sentence is tagged so a phone can drop them.
368 expect(asks).toContain("ask-ifnot");
369 const css = await (await fetch(`${servers.url}${home.match(/href="(\/[^"]*\.css[^"]*)"/)![1]}`)).text();
370 const phone = css.slice(css.indexOf("A phone: rows use the full width"));
371 expect(phone).toContain(".needs-you .card { border: 0;");
372 expect(phone).toContain(".needs-you .ask-primary .btn { flex: 1; min-height: 44px; }");
373 expect(phone).toContain(".needs-you .ask-ico, .needs-you .ask-ifnot, .needs-you .ask-short { display: none; }");
374 expect(phone).toContain(".needs-you .row-title { white-space: normal;");
375 });
358376 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs