From 8448191406c693c49ea5eb0c9d7af14bfd53e59a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:47:29 +0000 Subject: [PATCH 1/9] wip(ui): phone bar keeps Edit in its first slot Claude-Session: https://claude.ai/code/session_01WGufzg2evNa1V3zxrQq3KX Co-authored-by: Claude --- .../page-header-phone-bar-27058.test.tsx | 106 ++++++++++++++---- .../src/renderers/layout/containers.tsx | 28 +++-- 2 files changed, 103 insertions(+), 31 deletions(-) diff --git a/ui/packages/components/src/__tests__/page-header-phone-bar-27058.test.tsx b/ui/packages/components/src/__tests__/page-header-phone-bar-27058.test.tsx index 4ae20452ed4..552acecc07f 100644 --- a/ui/packages/components/src/__tests__/page-header-phone-bar-27058.test.tsx +++ b/ui/packages/components/src/__tests__/page-header-phone-bar-27058.test.tsx @@ -11,10 +11,11 @@ * row: its actions go to the host's bottom bar (`PageHeaderPhoneContext`), in * the row's bar face, through the same `PageHeaderActions` resolver. * - * - the bar holds the primary action, one more and the `⋯`; - * - the host's Edit is one of the record's actions there: it takes the - * second slot when the page declares one action, and folds into the `⋯` - * when a declared second action fills the bar; + * - the bar holds two buttons and the `⋯`; + * - the host's Edit takes the first slot and the primary action the second, + * whatever the page declares; the page's other actions fold into the `⋯` + * (objectstack#34595 — the order this file pinned before put Edit after + * the page's actions, so a declared second action pushed it into the `⋯`); * - `mobileMaxVisible` still sets the bar's budget when the page declares it; * - nothing is drawn until the host's bar element exists; * - the host's subtitle stands in for an undeclared one, and an authored @@ -47,7 +48,12 @@ const assign = { name: 'assign', locations: ['record_header'], label: 'Assign', const ret = { name: 'return_to_pool', locations: ['record_header'], label: 'Return', type: 'flow' }; /** A host that owns a bottom bar and hands it to the header, as the console's record page does. */ -function PhoneHost({ schema, subtitle, mountBar = true }: { schema: unknown; subtitle?: string; mountBar?: boolean }) { +function PhoneHost({ + schema, + subtitle, + mountBar = true, + hostActions = HOST_ACTIONS, +}: { schema: unknown; subtitle?: string; mountBar?: boolean; hostActions?: unknown[] }) { const [bar, setBar] = React.useState(null); const face = React.useMemo(() => ({ actionBar: bar, subtitle }), [bar, subtitle]); return ( @@ -57,7 +63,7 @@ function PhoneHost({ schema, subtitle, mountBar = true }: { schema: unknown; sub recordId="1" data={{ id: '1', name: 'Mira Costa' }} objectSchema={{ name: 'lead', label: 'Lead' }} - headerSystemActions={HOST_ACTIONS} + headerSystemActions={hostActions} >
@@ -70,7 +76,7 @@ function PhoneHost({ schema, subtitle, mountBar = true }: { schema: unknown; sub ); } -function DesktopHost({ schema }: { schema: unknown }) { +function DesktopHost({ schema, hostActions = HOST_ACTIONS }: { schema: unknown; hostActions?: unknown[] }) { return ( @@ -104,13 +110,13 @@ afterEach(() => { }); describe('a record header on a phone draws its actions into the host\'s bottom bar (objectstack#27058)', () => { - it('one declared action: the bar is [Convert Lead][Edit][⋯], and the header draws no action row', async () => { + it('one declared action: the bar is [Edit][Convert Lead][⋯], and the header draws no action row (objectstack#34595)', async () => { render(); await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); const toolbar = bar().querySelector('[role="toolbar"]')!; expect(toolbar.getAttribute('data-page-header-actions-face')).toBe('bar'); - expect(barButtons()).toEqual(['Convert Lead', 'Edit', 'More actions']); - // The primary leads the bar and is the one filled button; the bar's + expect(barButtons()).toEqual(['Edit', 'Convert Lead', 'More actions']); + // Edit leads the bar (objectstack#34595), the primary follows; the bar's // buttons share its width. const primary = within(bar()).getByRole('button', { name: 'Convert Lead' }); expect(primary.className).toContain('flex-1'); @@ -119,24 +125,26 @@ describe('a record header on a phone draws its actions into the host\'s bottom b expect(await openMore(bar())).toContain('Delete'); }); - it('a declared second action takes the second slot, and the host\'s Edit folds into the ⋯', async () => { + it('declared second and third actions fold into the ⋯; the host\'s Edit keeps its slot (objectstack#34595)', async () => { render(); await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); - expect(barButtons()).toEqual(['Convert Lead', 'Assign', 'More actions']); + expect(barButtons()).toEqual(['Edit', 'Convert Lead', 'More actions']); const items = await openMore(bar()); - // The page's own folded action first, then the host's Edit, then the - // destructive band. - expect(items.indexOf('Return')).toBeGreaterThanOrEqual(0); - expect(items.indexOf('Edit')).toBeGreaterThan(items.indexOf('Return')); - expect(items.indexOf('Delete')).toBeGreaterThan(items.indexOf('Edit')); + // The page's own folded actions first, then the destructive band; Edit + // is not in the `⋯`. + expect(items.indexOf('Assign')).toBeGreaterThanOrEqual(0); + expect(items.indexOf('Return')).toBeGreaterThan(items.indexOf('Assign')); + expect(items).not.toContain('Edit'); + expect(items.indexOf('Delete')).toBeGreaterThan(items.indexOf('Return')); }); it('the page\'s declared mobileMaxVisible still sets the bar\'s budget', async () => { render(); await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); - expect(barButtons()).toEqual(['Convert Lead', 'More actions']); + // A budget of one is Edit's (objectstack#34595); the primary folds. + expect(barButtons()).toEqual(['Edit', 'More actions']); const items = await openMore(bar()); - expect(items).toEqual(expect.arrayContaining(['Assign', 'Edit', 'Delete'])); + expect(items).toEqual(expect.arrayContaining(['Convert Lead', 'Assign', 'Delete'])); }); it('nothing is drawn until the host\'s bar element exists', () => { @@ -179,3 +187,61 @@ describe('a record header on a phone draws its actions into the host\'s bottom b expect(document.querySelector('[data-page-header-subtitle]')).toBeNull(); }); }); + +/** + * objectstack#34595 — on an editable record the phone bar keeps Edit visible. + * Measured on an opportunity at 375 px: the page's own actions ("Generate + * Quote", "Clone Opportunity") filled both slots and Edit was the fifth entry + * of the `⋯`. The bar is now Edit, the primary action, then the `⋯`. + */ +describe('the phone bar keeps Edit visible on an editable record (objectstack#34595)', () => { + const clone = { name: 'clone_opportunity', locations: ['record_header'], label: 'Clone Opportunity', type: 'flow' }; + // Declared second, so the primary is picked by its `variant`, not by position. + const quote = { name: 'generate_quote', locations: ['record_header'], label: 'Generate Quote', type: 'flow', variant: 'primary' }; + const report = { name: 'print_report', locations: ['record_header'], label: 'Print', type: 'flow' }; + const OPPORTUNITY = { type: 'page:header', actions: [clone, quote, report] }; + + it('draws [Edit][primary][⋯]: the primary is the action declaring variant primary, the rest fold', async () => { + render(); + await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); + expect(barButtons()).toEqual(['Edit', 'Generate Quote', 'More actions']); + // One filled button, and it is the primary — not Edit. + expect(within(bar()).getByRole('button', { name: 'Generate Quote' }).className).toContain('bg-primary'); + expect(within(bar()).getByRole('button', { name: 'Edit' }).className).not.toContain('bg-primary'); + const items = await openMore(bar()); + expect(items).toEqual(expect.arrayContaining(['Clone Opportunity', 'Print', 'Delete'])); + expect(items).not.toContain('Edit'); + // The destructive host action still opens the destructive band last. + expect(items[items.length - 1]).toBe('Delete'); + }); + + it('a larger mobileMaxVisible draws the next of the page\'s actions after Edit and the primary', async () => { + render(); + await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); + expect(barButtons()).toEqual(['Edit', 'Generate Quote', 'Clone Opportunity', 'More actions']); + }); + + it('a record the reader cannot edit (no host Edit) keeps the primary and one more', async () => { + render(); + await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); + expect(barButtons()).toEqual(['Generate Quote', 'Clone Opportunity', 'More actions']); + expect(await openMore(bar())).toEqual(['Print', 'Delete']); + }); + + it('with no page action the bar is Edit alone and the filled button, as before', async () => { + render(); + await waitFor(() => expect(bar().querySelector('[role="toolbar"]')).not.toBeNull()); + expect(barButtons()).toEqual(['Edit', 'More actions']); + expect(within(bar()).getByRole('button', { name: 'Edit' }).className).toContain('bg-primary'); + }); + + it('control: the desktop row is unchanged — the page\'s actions inline, primary first, Edit after them', () => { + render(); + const toolbar = screen.getByRole('toolbar'); + expect(toolbar.getAttribute('data-page-header-actions-face')).toBe('row'); + const labels = within(toolbar) + .getAllByRole('button') + .map((b) => b.getAttribute('aria-label') || b.textContent); + expect(labels).toEqual(['Generate Quote', 'Clone Opportunity', 'Print', 'Edit', 'More actions']); + }); +}); diff --git a/ui/packages/components/src/renderers/layout/containers.tsx b/ui/packages/components/src/renderers/layout/containers.tsx index 0fd45a2a018..42d5050cbe2 100644 --- a/ui/packages/components/src/renderers/layout/containers.tsx +++ b/ui/packages/components/src/renderers/layout/containers.tsx @@ -1802,7 +1802,8 @@ function recordPictureUrl(value: unknown): string | undefined { /** * The buttons a phone's bottom action bar holds before its `⋯` - * (objectstack#27058): the primary action and one more. The record page v4 + * (objectstack#27058): on an editable record, Edit and the primary action + * (objectstack#34595); else the primary action and one more. The record page v4 * header row's cap is the primary, two more and the `⋯`; at 390 px the second * of those folds into the `⋯`. */ @@ -1847,10 +1848,10 @@ export interface PageHeaderActionsProps { * Where the row is drawn (objectstack#27058). `row` (the default) is the * header's own action row. `bar` is a phone's bottom action bar: the primary * action, one more and the `⋯`, each button sharing the bar's width. In the - * bar the host's Edit is one of the record's actions like any other: it - * takes a slot after the page's own actions, and folds into the `⋯` when - * they fill the bar. The page's `mobileMaxVisible` still sets the budget - * when it declares one. + * bar the host's Edit takes a slot like any other button, but the first + * one (objectstack#34595): on an editable record the bar is Edit, the + * primary action, then the `⋯` holding the rest. The page's + * `mobileMaxVisible` still sets the budget when it declares one. */ face?: 'row' | 'bar'; } @@ -2500,17 +2501,22 @@ export const PageHeaderActions: React.FC = ({ // the `⋯`'s destructive band, never inline as a red button. // // The phone's bottom bar (objectstack#27058) has room for its budget and - // no more, so there the host's buttons queue after the page's own actions - // for the same slots (the primary keeps the first), and what does not fit - // folds into the `⋯` with them. + // no more, so there every button queues for the same slots and what does + // not fit folds into the `⋯`. The queue is the bar's order + // (objectstack#34595): the host's buttons first — on an editable record + // that is its Edit, the record's base action, which the row never folds + // either — then the primary, then the page's other actions. So the + // default budget of two draws [Edit][primary][⋯] however many actions + // the page declares. A destructive host action is not a host button (see + // `isHostButton`): it still always folds. const authoredButtons = ranked.filter((a) => !isHostAction(a)); const barQueue = barFace - ? [...(primaryAction ? [primaryAction] : []), ...authoredButtons, ...ranked.filter(isHostButton)] + ? [...ranked.filter(isHostButton), ...(primaryAction ? [primaryAction] : []), ...authoredButtons] .filter((a, i, all) => all.indexOf(a) === i) : []; - const inlineAuthored = new Set(barFace ? barQueue.slice(0, maxVisible) : authoredButtons.slice(0, maxVisible)); + const inlineAuthored = new Set(authoredButtons.slice(0, maxVisible)); const inlineActions = barFace - ? ranked.filter((a) => inlineAuthored.has(a)) + ? barQueue.slice(0, maxVisible) : ranked.filter((a) => isHostButton(a) || inlineAuthored.has(a)); const foldedButtons = barFace ? [ From 62a7d5e107872436c208aa6916c2ff5580afd2be Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 05:05:18 +0000 Subject: [PATCH 2/9] wip(ui): compact phone stage bar and two-column key-field strip Claude-Session: https://claude.ai/code/session_01WGufzg2evNa1V3zxrQq3KX Co-authored-by: Claude --- ui/e2e/record-path-phone-row.spec.ts | 171 +++++++++--------- .../plugin-detail/src/HeaderHighlight.tsx | 19 +- ...light.lineFitAndPhoneLayout-12523.test.tsx | 9 +- .../HeaderHighlight.phoneGrid-34595.test.tsx | 111 ++++++++++++ .../record-path.compact-34595.test.tsx | 154 ++++++++++++++++ .../record-path.phoneRow-26897.test.tsx | 32 +++- .../src/renderers/record-path.tsx | 162 +++++++++++++---- 7 files changed, 518 insertions(+), 140 deletions(-) create mode 100644 ui/packages/plugin-detail/src/__tests__/HeaderHighlight.phoneGrid-34595.test.tsx create mode 100644 ui/packages/plugin-detail/src/renderers/__tests__/record-path.compact-34595.test.tsx diff --git a/ui/e2e/record-path-phone-row.spec.ts b/ui/e2e/record-path-phone-row.spec.ts index 8abe3a78993..6cb905a238b 100644 --- a/ui/e2e/record-path-phone-row.spec.ts +++ b/ui/e2e/record-path-phone-row.spec.ts @@ -6,26 +6,27 @@ import path from 'node:path'; import { uiRoot } from '../scripts/ui-root.mjs'; /** - * GEOMETRY pin for `record:path`'s phone row (objectstack#26897). + * GEOMETRY pin for `record:path` below `sm`: the compact path (objectstack#34595). * - * At 390×844 on the HotCRM seed the path's row below `sm` cut the stage at its - * right edge mid-word ("Resolu"): the stages were content-width and - * `whitespace-nowrap` inside a sideways scroller whose scrollbar is hidden, so - * nothing said the row scrolled. The fix gives every stage an equal share with - * a 2.5rem floor, truncates an ordinary label with an ellipsis and wraps a - * terminal one, as the desktop rail does. + * The phone row used to name every stage in an equal share (objectstack#26897), + * which at 375px cut seven opportunity stages to their first letters. Below + * `sm` the path now draws one rail segment per stage and no names, then a + * summary line with the step and the current stage's FULL name, which opens a + * list of every stage. This spec measures, in Chromium, that the rail fits + * its row at phone widths with every segment one width, and that the summary + * shows the current stage's name whole — wrapping a long one — inside the + * viewport, on a 44px touch target. * - * ⚠️ A Playwright spec and not a vitest test for the reason + * A Playwright spec and not a vitest test for the reason * `record-header-title-width.spec.ts` gives: jsdom has no layout engine, so a * width read there is 0 and an assertion on it is vacuous. The class-shape - * half (and the `title` that keeps a cut label readable) is pinned beside the - * renderer in `record-path.phoneRow-26897.test.tsx`. + * half is pinned beside the renderer in `record-path.compact-34595.test.tsx`. * - * REAL, read out of `record-path.tsx` at run time: the phone row's class - * string, the stage, rail and label base strings `renderStage` composes, and - * the three named label/stage constants — plus real Tailwind compiled from the - * installed `tailwindcss` for exactly those candidates. FIXTURE: the stage - * labels, and the element tree, transcribed from `renderStage`. + * REAL, read out of `record-path.tsx` at run time: the compact block's class, + * the rail's base string `railClass` composes and the named PHONE_* constants + * — plus real Tailwind compiled from the installed `tailwindcss` for exactly + * those candidates. FIXTURE: the stage labels, and the element tree, + * transcribed from the compact block. */ const REPO_ROOT = uiRoot(); @@ -49,41 +50,32 @@ function grab(re: RegExp, mustContain: string[]): string { } const CLS = { - row: grab(/\{\/\* Mobile:[^\n]*\*\/\}\s* `Stage number ${i + 1}`); -/** A long path: ten stages, so 2.5rem floors cannot all fit a 320px row. */ -const LONG_STAGES: Stage[] = Array.from({ length: 10 }, (_, i) => ({ label: `Stage number ${i + 1}` })); - -const fixture = (stages: Stage[]) => - `
` + +const fixture = (stages: string[], current: string) => + `
` + + `' + + `' + '
'; let css = ''; @@ -96,7 +88,9 @@ test.beforeAll(async () => { return { path: file, base: path.dirname(file), content: readFileSync(file, 'utf8') }; }, }); - css = compiler.build([...Object.values(CLS), 'bg-muted'].join(' ').split(/\s+/).filter(Boolean)); + css = compiler.build( + [...Object.values(CLS), 'bg-muted ml-1 shrink-0 ml-auto h-4 w-4'].join(' ').split(/\s+/).filter(Boolean), + ); if (!css.includes('@media')) { throw new Error('Tailwind produced no media queries — `sm:hidden` would be inert.'); } @@ -105,16 +99,21 @@ test.beforeAll(async () => { type Reading = { rowClientWidth: number; rowScrollWidth: number; - stages: { label: string; left: number; right: number; width: number; clipped: boolean; ellipsis: boolean }[]; + segments: { left: number; right: number; width: number }[]; + summary: { right: number; height: number }; + current: { right: number; clipped: boolean; lines: number }; }; -async function readRow(page: Page, stages: Stage[], width: number): Promise { +async function readPath(page: Page, stages: string[], current: string, width: number): Promise { await page.setViewportSize({ width, height: 844 }); - await page.setContent(`${fixture(stages)}`, { waitUntil: 'load' }); + await page.setContent( + `${fixture(stages, current)}`, + { waitUntil: 'load' }, + ); // Wait for the row's layout to settle across two frames, then for fonts. await page.waitForFunction( () => { - const row = document.getElementById('row'); + const row = document.getElementById('rails'); if (!row || row.getBoundingClientRect().width <= 0) return false; const w = row.scrollWidth; const prev = (window as unknown as { __w?: number }).__w; @@ -127,58 +126,64 @@ async function readRow(page: Page, stages: Stage[], width: number): Promise document.fonts?.ready); return page.evaluate(() => { const round = (n: number) => Math.round(n * 100) / 100; - const row = document.getElementById('row')!; + const row = document.getElementById('rails')!; + const summary = document.getElementById('summary')!.getBoundingClientRect(); + const cur = document.getElementById('current')!; + const curRect = cur.getBoundingClientRect(); + const lineHeight = parseFloat(getComputedStyle(cur).lineHeight) || 16; return { rowClientWidth: row.clientWidth, rowScrollWidth: row.scrollWidth, - stages: Array.from(row.children).map((item) => { - const label = item.querySelector('span:not(.bg-muted)') as HTMLElement; - const r = item.getBoundingClientRect(); - return { - label: label.textContent ?? '', - left: round(r.left), - right: round(r.right), - width: round(r.width), - clipped: label.scrollWidth > label.clientWidth, - ellipsis: getComputedStyle(label).textOverflow === 'ellipsis', - }; + segments: Array.from(row.children).map((seg) => { + const r = seg.getBoundingClientRect(); + return { left: round(r.left), right: round(r.right), width: round(r.width) }; }), + summary: { right: round(summary.right), height: round(summary.height) }, + current: { + right: round(curRect.right), + clipped: cur.scrollWidth > cur.clientWidth, + lines: Math.round(curRect.height / lineHeight), + }, }; }); } -test.describe('record:path phone row (objectstack#26897)', () => { +test.describe('record:path compact phone path (objectstack#34595)', () => { for (const width of [320, 375, 390]) { - test(`the case path fits its row at ${width}px and every cut label ellipsises`, async ({ page }) => { - const r = await readRow(page, CASE_STAGES, width); - // THE assertion: nothing hides past the row's edge, where the hidden - // scrollbar gave no sign that it was there. + test(`the opportunity's rail fits its row at ${width}px, one width per stage, and names the current stage whole`, async ({ page }) => { + const r = await readPath(page, OPPORTUNITY, 'Negotiation', width); expect( r.rowScrollWidth, - `row holds ${r.rowScrollWidth}px of stages in ${r.rowClientWidth}px — the last stage is cut at the edge`, + `rail holds ${r.rowScrollWidth}px of segments in ${r.rowClientWidth}px — a stage is cut at the edge`, ).toBeLessThanOrEqual(r.rowClientWidth); - for (const s of r.stages) { - expect(s.right, `stage "${s.label}" ends past the row`).toBeLessThanOrEqual(width + 0.5); - // A label that does not fit is cut WITH an ellipsis, never bare. - if (s.clipped) expect(s.ellipsis, `stage "${s.label}" is cut with no ellipsis`).toBe(true); + expect(r.segments).toHaveLength(OPPORTUNITY.length); + for (const s of r.segments) { + expect(s.right, 'a rail segment ends past the viewport').toBeLessThanOrEqual(width + 0.5); + expect(s.width, 'a rail segment collapsed').toBeGreaterThan(8); } - // Not vacuous: at these widths the long labels really are cut. - expect(r.stages.some((s) => s.clipped), 'no label was cut, so the ellipsis went unmeasured').toBe(true); - // Equal shares: every stage is one width. - const widths = new Set(r.stages.map((s) => Math.round(s.width))); - expect(widths.size, `stage widths ${[...widths].join(', ')}`).toBe(1); + // Equal shares: every segment is one width. + const widths = new Set(r.segments.map((s) => Math.round(s.width))); + expect(widths.size, `segment widths ${[...widths].join(', ')}`).toBe(1); + // The current stage's name is whole, inside the viewport, on a 44px target. + expect(r.current.clipped, 'the current stage name is cut').toBe(false); + expect(r.current.right).toBeLessThanOrEqual(width + 0.5); + expect(r.summary.right).toBeLessThanOrEqual(width + 0.5); + expect(r.summary.height).toBeGreaterThanOrEqual(44); }); } - test('a terminal label wraps instead of being cut, as on the desktop rail', async ({ page }) => { - const r = await readRow(page, [...CASE_STAGES.slice(0, 5), { label: 'Closed — Duplicate', terminal: true }], 320); - const terminal = r.stages[r.stages.length - 1]; - expect(terminal.clipped, 'the terminal stage label is cut').toBe(false); + test('a long current stage name wraps instead of being cut', async ({ page }) => { + const long = 'Waiting on Customer Signature and Legal Review of the Master Agreement'; + const r = await readPath(page, OPPORTUNITY, long, 320); + expect(r.current.clipped, 'the long stage name is cut').toBe(false); + expect(r.current.right).toBeLessThanOrEqual(320 + 0.5); + // Not vacuous: at 320px the name really does need more than one line. + expect(r.current.lines, 'the long name fit one line, so wrapping went unmeasured').toBeGreaterThan(1); }); - test('past the floor the stages keep 2.5rem and the row scrolls instead', async ({ page }) => { - const r = await readRow(page, LONG_STAGES, 320); - for (const s of r.stages) expect(s.width).toBeGreaterThanOrEqual(40); - expect(r.rowScrollWidth).toBeGreaterThan(r.rowClientWidth); + test('a twenty-stage path still fits its rail at 320px', async ({ page }) => { + const r = await readPath(page, LONG_PATH, 'Stage number 5', 320); + expect(r.rowScrollWidth).toBeLessThanOrEqual(r.rowClientWidth); + for (const s of r.segments) expect(s.width).toBeGreaterThan(0); }); }); diff --git a/ui/packages/plugin-detail/src/HeaderHighlight.tsx b/ui/packages/plugin-detail/src/HeaderHighlight.tsx index 5b1daac6e96..1670b41f1ca 100644 --- a/ui/packages/plugin-detail/src/HeaderHighlight.tsx +++ b/ui/packages/plugin-detail/src/HeaderHighlight.tsx @@ -145,9 +145,13 @@ export const HeaderHighlight: React.FC = ({ // leaves `--spacing * 1.5` of the padding visible, the bleed of an // editable value's hover background (`-mx-1.5`), and does not clip // the other three sides. Below `sm` there is no border to hide - // (each chip is its own line, see the chip classes). + // (each chip is a separator-less grid cell, see the chip classes). 'sm:-ml-[calc(var(--spacing)*5+1px)]', 'sm:[clip-path:inset(-100vmax_-100vmax_-100vmax_calc(var(--spacing)*3.5+1px))]', + // Below `sm` the strip is the default page's phone grid + // (objectstack#34595): two equal columns, so six highlights read + // as three rows, not six. + 'max-sm:grid max-sm:grid-cols-2 max-sm:gap-x-4 max-sm:gap-y-3', )} > {visibleFields.map((field) => { @@ -348,12 +352,11 @@ export const HeaderHighlight: React.FC = ({ // like the first one. // // Below `sm` the strip is ONE layout (objectui#12523): every chip - // is a full-width line with no separator and no padding. At a - // 358px row two columns leave a value about 150px, which cuts the - // HotCRM lead's phone number and email, while a full line shows - // both whole; and a touch screen cannot hover a `title`. The - // classes are the same for every chip, wide or not, so no chip - // can fall back to the wrapping layout. + // is one cell of the row's two-column grid (objectstack#34595, the + // default page's phone grid), with no separator and no padding. + // The classes are the same for every chip, wide or not, so no chip + // can fall back to the wrapping layout; a value too long for its + // cell is cut by the value span with an ellipsis, as on any row. return (
= ({ useWide ? 'basis-[16rem] min-w-[min(16rem,100%)]' : 'basis-[9rem] min-w-[min(9rem,100%)]', - 'max-sm:basis-full max-sm:max-w-full max-sm:border-l-0 max-sm:px-0', + 'max-sm:min-w-0 max-sm:max-w-full max-sm:border-l-0 max-sm:px-0', )} > diff --git a/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.lineFitAndPhoneLayout-12523.test.tsx b/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.lineFitAndPhoneLayout-12523.test.tsx index 97d6956196c..7c3331900b8 100644 --- a/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.lineFitAndPhoneLayout-12523.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.lineFitAndPhoneLayout-12523.test.tsx @@ -92,8 +92,11 @@ const chipAround = (el: Element) => el.closest('div.group') as HTMLElement; const chipsOf = (container: HTMLElement) => Array.from(container.querySelectorAll('section > div > div.group')) as HTMLElement[]; -/** Below `sm`, every chip is one full-width line with no separator. */ -const PHONE_LAYOUT = ['max-sm:basis-full', 'max-sm:max-w-full', 'max-sm:border-l-0', 'max-sm:px-0']; +/** + * Below `sm`, every chip is one cell of a two-column grid with no separator + * (objectstack#34595 — this pinned a full-width line per chip before). + */ +const PHONE_LAYOUT = ['max-sm:min-w-0', 'max-sm:max-w-full', 'max-sm:border-l-0', 'max-sm:px-0']; describe('a phone drawn from a format gets the phone basis (objectui#12523)', () => { it('gives the `text` + `format: phone` chip the 16rem floor objectui#11659 gave phones', () => { @@ -176,7 +179,7 @@ describe('a wrapped line starts flush, like the first (objectui#12523)', () => { }); describe('below `sm` the strip is one layout (objectui#12523)', () => { - it('gives all six chips of the measured lead the same full-width line', () => { + it('gives all six chips of the measured lead the same grid cell (objectstack#34595)', () => { const { container } = renderLead(); const chips = chipsOf(container); diff --git a/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.phoneGrid-34595.test.tsx b/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.phoneGrid-34595.test.tsx new file mode 100644 index 00000000000..3c9d0885ecb --- /dev/null +++ b/ui/packages/plugin-detail/src/__tests__/HeaderHighlight.phoneGrid-34595.test.tsx @@ -0,0 +1,111 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * A hand-written record page's key-field strip is a two-column grid on a + * phone, as the default page's is (objectstack#34595). + * + * Measured on a hand-written opportunity page at 375 px: the strip drew its + * six key fields one per line, each with its own pencil, so the fields alone + * filled the first screen. The default page's strip is a grid of at least two + * columns there. Below `sm` the hand-written strip now takes the same grid: + * two equal columns, so six fields read as three rows. From `sm` up it is the + * wrapping row it always was. + * + * The test DOM resolves no Tailwind and has no layout engine, so this file + * pins the class shape only; it measures no width. + */ + +import { describe, it, expect } from 'vitest'; +import { render } from '@testing-library/react'; +import * as React from 'react'; +import type { HighlightField } from '@object-ui/types'; +import { HeaderHighlight } from '../HeaderHighlight'; +import { DefaultRecordPageContext } from '../defaultRecordPage'; + +/** The opportunity's six key fields, with their own field shapes. */ +const opportunitySchema = { + fields: { + amount: { type: 'currency', label: 'Amount' }, + expected_revenue: { type: 'currency', label: 'Expected Revenue' }, + close_date: { type: 'date', label: 'Close Date' }, + probability: { type: 'percent', label: 'Probability' }, + account_id: { type: 'lookup', label: 'Account', reference: 'account' }, + owner_id: { type: 'lookup', label: 'Owner', reference: 'sys_user' }, + }, +}; + +const opportunityData = { + amount: 94000, + expected_revenue: 75200, + close_date: '2026-11-24', + probability: 80, + account_id: { id: 'a1', name: 'Vertex Analytics' }, + owner_id: { id: 'u1', name: 'Jianguo Zhuang' }, +}; + +const opportunityFields: HighlightField[] = Object.keys(opportunitySchema.fields).map((name) => ({ name })); + +const mount = (defaultPage = false) => + render( + + + , + ); + +const rowOf = (container: HTMLElement) => container.querySelector('section > div') as HTMLElement; +const chipsOf = (container: HTMLElement) => + Array.from(container.querySelectorAll('section > div > div.group')) as HTMLElement[]; +const tokens = (el: Element): string[] => el.className.split(/\s+/).filter(Boolean); + +describe('a hand-written page\'s key-field strip is a two-column grid on a phone (objectstack#34595)', () => { + it('lays the row out as the default page\'s two-column grid below `sm`', () => { + const { container } = mount(); + const row = rowOf(container); + expect(row).not.toHaveAttribute('data-highlights-face'); + expect(tokens(row)).toEqual( + expect.arrayContaining(['max-sm:grid', 'max-sm:grid-cols-2', 'max-sm:gap-x-4', 'max-sm:gap-y-3']), + ); + }); + + it('gives each of the six fields one cell, wide types included, so they read as three rows', () => { + const { container } = mount(); + const chips = chipsOf(container); + expect(chips).toHaveLength(6); + for (const chip of chips) { + const t = tokens(chip); + // A cell, not a line: nothing asks for the full row or a second column. + expect(t).not.toContain('max-sm:basis-full'); + expect(t.some((c) => c.startsWith('max-sm:col-span'))).toBe(false); + expect(t).toEqual(expect.arrayContaining(['max-sm:min-w-0', 'max-sm:max-w-full'])); + // No separator inside the grid. + expect(t).toEqual(expect.arrayContaining(['max-sm:border-l-0', 'max-sm:px-0'])); + } + }); + + it('CONTROL: from `sm` up the row still wraps with its separators and floors', () => { + const { container } = mount(); + const row = rowOf(container); + expect(tokens(row)).toEqual(expect.arrayContaining(['flex', 'flex-wrap', 'sm:-ml-[calc(var(--spacing)*5+1px)]'])); + expect(tokens(row).some((c) => c === 'grid' || c.startsWith('grid-cols'))).toBe(false); + for (const chip of chipsOf(container)) { + expect(tokens(chip)).toEqual(expect.arrayContaining(['border-l', 'px-5', 'grow', 'max-w-max'])); + } + }); + + it('CONTROL: the default page\'s grid face is untouched', () => { + const { container } = mount(true); + const row = rowOf(container); + expect(row).toHaveAttribute('data-highlights-face', 'grid'); + expect(tokens(row)).toEqual(expect.arrayContaining(['grid', 'grid-cols-2'])); + expect(tokens(row).some((c) => c.startsWith('max-sm:'))).toBe(false); + }); +}); diff --git a/ui/packages/plugin-detail/src/renderers/__tests__/record-path.compact-34595.test.tsx b/ui/packages/plugin-detail/src/renderers/__tests__/record-path.compact-34595.test.tsx new file mode 100644 index 00000000000..2b474f71b11 --- /dev/null +++ b/ui/packages/plugin-detail/src/renderers/__tests__/record-path.compact-34595.test.tsx @@ -0,0 +1,154 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * `record:path` below `sm` is the COMPACT path (objectstack#34595). + * + * Measured on an opportunity at 375 px: seven equal shares cut every stage + * name to its first letters ("Pr… Q… Ne… Pr…"), so the path could not say + * where the record stood. Below `sm` the path now draws one rail segment per + * stage with no names, then one summary line — "Step N of M" (the form's + * `stepOf` copy) and the current stage's full name — and that line opens the + * list of every stage by its full name. + * + * The test DOM resolves no Tailwind, so this file reads class tokens and + * attributes; the geometry is pinned in Chromium by + * `e2e/record-path-phone-row.spec.ts`. + */ + +import * as React from 'react'; +import { describe, it, expect, afterEach } from 'vitest'; +import '@testing-library/jest-dom'; +import { render, cleanup, fireEvent, within, type RenderResult } from '@testing-library/react'; +import { I18nProvider } from '@object-ui/i18n'; +import { RecordContextProvider } from '@object-ui/react'; +import { RecordPathRenderer } from '../record-path'; + +afterEach(() => cleanup()); + +/** The opportunity's path as the CRM seed draws it: five open steps, then won, then lost. */ +const OPPORTUNITY_STAGES = [ + { value: 'prospecting', label: 'Prospecting' }, + { value: 'qualification', label: 'Qualification' }, + { value: 'needs_analysis', label: 'Needs Analysis' }, + { value: 'proposal', label: 'Proposal' }, + { value: 'negotiation', label: 'Negotiation' }, + { value: 'closed_won', label: 'Closed Won', terminal: 'won' }, + { value: 'closed_lost', label: 'Closed Lost', terminal: 'lost' }, +]; + +function mount(stage: string, language?: string): RenderResult { + const tree = ( + + + + ); + return render( + language ? ( + {tree} + ) : ( + tree + ), + ); +} + +const compactOf = (r: RenderResult): HTMLElement => + r.container.querySelector('[data-record-path-compact]') as HTMLElement; +const summaryOf = (r: RenderResult): HTMLElement => + within(compactOf(r)).getByRole('button', { expanded: false }) as HTMLElement; +const listOf = (r: RenderResult): HTMLElement => + compactOf(r).querySelector('[data-record-path-stage-list]') as HTMLElement; +const railsOf = (r: RenderResult): HTMLElement[] => + Array.from(compactOf(r).querySelectorAll('[data-record-path-rails] > [data-stage-rail]')) as HTMLElement[]; +const tokens = (el: Element): string[] => el.className.split(/\s+/).filter(Boolean); +const textOf = (el: Element): string => (el.textContent ?? '').replace(/[✓✗]/g, '').trim(); + +describe('record:path below `sm` is the compact path (objectstack#34595)', () => { + it('is drawn only below `sm`, beside the desktop rail', () => { + const r = mount('negotiation'); + expect(tokens(compactOf(r))).toContain('sm:hidden'); + const desktop = r.container.querySelector('[role="list"]') as HTMLElement; + expect(tokens(desktop)).toEqual(expect.arrayContaining(['hidden', 'sm:flex'])); + expect(compactOf(r).contains(desktop)).toBe(false); + }); + + it('draws one rail segment per stage, no names on them, as one decorative bar', () => { + const r = mount('negotiation'); + const bar = compactOf(r).querySelector('[data-record-path-rails]') as HTMLElement; + expect(bar).toHaveAttribute('aria-hidden', 'true'); + const rails = railsOf(r); + expect(rails).toHaveLength(OPPORTUNITY_STAGES.length); + expect(rails.every((rail) => textOf(rail) === '')).toBe(true); + expect(rails.map((rail) => rail.getAttribute('data-stage-state'))).toEqual([ + 'completed', 'completed', 'completed', 'completed', 'current', 'upcoming', 'upcoming', + ]); + expect(rails[6]).toHaveAttribute('data-stage-terminal', 'lost'); + for (const rail of rails) expect(tokens(rail)).toEqual(expect.arrayContaining(['flex-1', 'min-w-0'])); + }); + + it('reads the current stage\'s full name and its step, counted over the forward stages', () => { + const r = mount('negotiation'); + const summary = summaryOf(r); + // Six forward stages (the five open ones and the won terminus); the lost + // stage stands apart, as on the desktop rail. + expect(textOf(summary)).toBe('Step 5 of 6·Negotiation'); + expect(within(summary).getByText('Negotiation')).toHaveClass('[overflow-wrap:anywhere]'); + expect(within(summary).getByText('Negotiation')).not.toHaveClass('truncate'); + }); + + it('says the step in the session language through the existing `form.stepOf` copy', () => { + const r = mount('negotiation', 'zh'); + expect(textOf(summaryOf(r))).toBe('第 5 步,共 6 步·Negotiation'); + }); + + it('tapping the summary opens every stage by its full name, and tapping again closes it', () => { + const r = mount('negotiation'); + const summary = summaryOf(r); + const list = listOf(r); + expect(summary).toHaveAttribute('aria-controls', list.id); + expect(tokens(list)).toContain('hidden'); + + fireEvent.click(summary); + expect(summary).toHaveAttribute('aria-expanded', 'true'); + expect(tokens(list)).toContain('flex'); + expect(tokens(list)).not.toContain('hidden'); + const items = within(list).getAllByRole('listitem'); + expect(items.map(textOf)).toEqual(OPPORTUNITY_STAGES.map((s) => s.label)); + expect(items[4]).toHaveAttribute('aria-current', 'step'); + for (const item of items) { + const label = item.querySelector(':scope > span:not([data-stage-rail])') as HTMLElement; + expect(tokens(label)).toContain('[overflow-wrap:anywhere]'); + expect(tokens(label)).not.toContain('truncate'); + } + + fireEvent.click(summary); + expect(summary).toHaveAttribute('aria-expanded', 'false'); + expect(tokens(list)).toContain('hidden'); + }); + + it('a record standing on the lost stage shows that stage, marked lost, and no step', () => { + const r = mount('closed_lost'); + const summary = summaryOf(r); + expect(textOf(summary)).toBe('Closed Lost'); + expect(within(summary).getByText('Closed Lost')).toHaveClass('text-destructive'); + expect(summary.textContent).not.toMatch(/Step/); + }); + + it('a record standing on no stage names the path, with no step', () => { + const r = mount('not_a_stage'); + expect(textOf(summaryOf(r))).toBe('Record path'); + }); + + it('CONTROL: the desktop rail is unchanged — every stage named on the rail, the ordinary label truncated', () => { + const r = mount('negotiation'); + const desktop = r.container.querySelector('[role="list"]') as HTMLElement; + const items = within(desktop).getAllByRole('listitem'); + expect(items.map(textOf)).toEqual(OPPORTUNITY_STAGES.map((s) => s.label)); + const negotiation = items[4].querySelector(':scope > span:not([data-stage-rail])') as HTMLElement; + expect(tokens(negotiation)).toContain('truncate'); + expect(within(desktop).queryByRole('button')).toBeNull(); + }); +}); diff --git a/ui/packages/plugin-detail/src/renderers/__tests__/record-path.phoneRow-26897.test.tsx b/ui/packages/plugin-detail/src/renderers/__tests__/record-path.phoneRow-26897.test.tsx index cc1fe9db41b..a5b53b4dbd1 100644 --- a/ui/packages/plugin-detail/src/renderers/__tests__/record-path.phoneRow-26897.test.tsx +++ b/ui/packages/plugin-detail/src/renderers/__tests__/record-path.phoneRow-26897.test.tsx @@ -15,6 +15,13 @@ * an ordinary label truncates and carries its full text in `title`, and a * terminal label wraps, as on the desktop rail (#25895). * + * objectstack#34595 replaced that row with the compact path: rail segments + * with no names, a summary line, and a stage list that names every stage in + * full. The phone `role="list"` read below is that stage list, so its labels + * wrap instead of truncating, and the two equal-share pins became pins on the + * compact path (the rest of the compact path is pinned in + * `record-path.compact-34595.test.tsx`). + * * The test DOM resolves no Tailwind, so this file reads class tokens and * attributes; the widths themselves are pinned in Chromium by * `e2e/record-path-phone-row.spec.ts`. @@ -63,26 +70,33 @@ const labelOf = (stage: HTMLElement): HTMLElement => const tokens = (el: HTMLElement): string[] => el.className.split(/\s+/).filter(Boolean); describe('record:path — the phone row fits and ellipsises (objectstack#26897)', () => { - it('every phone stage takes an equal share with a floor, instead of its content width', () => { - const phone = rows(mount())[1]; - expect(tokens(phone)).toContain('sm:hidden'); + it('every phone stage is one rail segment of an equal share, and one full line of the list (objectstack#34595)', () => { + const r = mount(); + const phone = rows(r)[1]; + const compact = phone.closest('[data-record-path-compact]') as HTMLElement; + expect(tokens(compact)).toContain('sm:hidden'); + const rails = Array.from(compact.querySelectorAll('[data-record-path-rails] > [data-stage-rail]')) as HTMLElement[]; + expect(rails).toHaveLength(CASE_STAGES.length); + for (const rail of rails) { + expect(tokens(rail)).toContain('flex-1'); + expect(tokens(rail)).toContain('min-w-0'); + } for (const stage of within(phone).getAllByRole('listitem')) { const t = tokens(stage); - expect(t).toContain('flex-1'); - expect(t).toContain('min-w-10'); - expect(t).not.toContain('shrink-0'); + expect(t).toContain('w-full'); + expect(t).not.toContain('flex-1'); } }); - it('an ordinary phone label truncates and keeps its full text in title', () => { + it('an ordinary phone label is shown in full: it wraps instead of truncating (objectstack#34595)', () => { const phone = rows(mount())[1]; for (const label of ['In Progress', 'Waiting on Customer', 'Resolution Proposed']) { const el = labelOf(stageNamed(phone, label)); const t = tokens(el); - expect(t).toContain('truncate'); + expect(t).toContain('[overflow-wrap:anywhere]'); expect(t).toContain('min-w-0'); + expect(t).not.toContain('truncate'); expect(t).not.toContain('whitespace-nowrap'); - expect(el).toHaveAttribute('title', label); } }); diff --git a/ui/packages/plugin-detail/src/renderers/record-path.tsx b/ui/packages/plugin-detail/src/renderers/record-path.tsx index 1f3e6e825b7..69e46f31e25 100644 --- a/ui/packages/plugin-detail/src/renderers/record-path.tsx +++ b/ui/packages/plugin-detail/src/renderers/record-path.tsx @@ -58,6 +58,7 @@ */ import React from 'react'; +import { ChevronDown } from 'lucide-react'; import { useRecordContext, useSafeFieldLabel } from '@object-ui/react'; import { useObjectTranslation, pickLocalized } from '@object-ui/i18n'; import type { RecordPathComponentProps } from '@object-ui/types'; @@ -110,21 +111,25 @@ const TERMINAL_LABEL_CLASS = 'text-center [overflow-wrap:anywhere]'; // wraps instead of being cut, so it stays legible on a narrow rail too. const shareOf = (stageCount: number): React.CSSProperties => ({ flexGrow: stageCount, flexShrink: 1, flexBasis: '0%' }); -// ── The phone row FITS its stages, and a label that does not fit ellipsises -// (objectstack#26897) ───────────────────────────────────────────────────── +// ── Below `sm` the path is COMPACT (objectstack#34595) ─────────────────── // -// The row below `sm` used to hold content-width, `whitespace-nowrap` stages -// in a sideways scroller with its scrollbar hidden, so at 390px the stage at -// the right edge was cut mid-word ("Resolu") with nothing to say the row -// scrolled. Now every stage starts from zero and takes an equal share, as on -// the desktop rail; an ordinary label truncates with an ellipsis and keeps -// its full text in `title`, and a terminal label wraps, as on desktop -// (#25895). The `min-w-10` floor keeps a stage from collapsing to a bare -// ellipsis: a path too long for every stage to keep 2.5rem still scrolls -// rather than drawing unreadable cells. Geometry pinned in Chromium by -// `e2e/record-path-phone-row.spec.ts`, which reads these two constants. -const PHONE_STAGE_CLASS = 'flex-1 min-w-10'; -const PHONE_LABEL_CLASS = 'text-center truncate'; +// A phone row has no room for every stage's name: seven equal shares of a +// 375px row cut each label to its first letters. So below `sm` the path draws +// one rail segment per stage and no stage names, then ONE summary line: the +// step the record stands on ("Step N of M", the form's existing `stepOf` +// copy, counted over the forward stages) and the current stage's FULL name, +// which wraps rather than being cut. The line is a disclosure button: pressed, +// it lists every stage by its full name, and on a path that admits stage +// changes each reachable stage there is the same press, behind the same gates, +// as on the desktop rail. Nothing about the mode is authored: the viewport +// picks it, as it picks the desktop rail. Geometry pinned in Chromium by +// `e2e/record-path-phone-row.spec.ts`, which reads these constants. +const PHONE_RAIL_ROW_CLASS = 'flex w-full items-start gap-1'; +const PHONE_RAIL_SEGMENT_CLASS = 'flex-1 min-w-0'; +const PHONE_SUMMARY_CLASS = + 'mt-1.5 flex min-h-11 w-full min-w-0 items-center gap-1.5 rounded-sm text-left text-xs text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring'; +const PHONE_SUMMARY_STAGE_CLASS = 'min-w-0 font-semibold [overflow-wrap:anywhere]'; +const PHONE_LIST_LABEL_CLASS = 'text-left [overflow-wrap:anywhere]'; type StageState = 'completed' | 'current' | 'upcoming'; @@ -300,6 +305,10 @@ const RecordPathBody: React.FC = ({ // Click-to-advance (objectstack#28061) — `pressable` is false unless the // author opted in AND this reader may edit `statusField` on this record. const stageChange = useStageChange(schema.allowStageChange === true, statusField); + // The compact phone path's disclosure (objectstack#34595): whether its full + // stage list is open. Ephemeral by ADR-0054 C3 — nobody expects it back. + const [phoneListOpen, setPhoneListOpen] = React.useState(false); + const phoneListId = React.useId(); /** * WHERE the stages come from: the author, else the status field's picklist * (objectui#11106). @@ -595,14 +604,21 @@ const RecordPathBody: React.FC = ({ labelClassName?: string; /** The label's full text as a `title`, for a row whose labels can be cut. */ labelTitle?: string; + /** A line of the compact phone path's stage list: a short rail beside the name. */ + listLine?: boolean; }) => { + const listLine = o.listLine === true; // A stage is a press only behind the opt-in, never the stage the record // already stands on (there is nowhere to move to), and never a stage the // field's blocking state machine cannot reach from the stored value. const press = stageChange.pressable && o.state !== 'current' && stageChange.admits(o.stage.value); const face = ( <> -