diff --git a/.changeset/34696-path-narrow-drawer.md b/.changeset/34696-path-narrow-drawer.md new file mode 100644 index 00000000000..92c2d2f25a5 --- /dev/null +++ b/.changeset/34696-path-narrow-drawer.md @@ -0,0 +1,14 @@ +--- +'@object-ui/plugin-detail': patch +--- + +fix(ui): the record stage bar uses its compact form in a narrow record drawer, not only on a phone + +Clause-②: no +Metadata-protocol: none + +`record:path` chose between its desktop row and its compact form by the viewport alone, so a narrow record drawer opened at a desktop viewport drew the desktop row: seven stages in a 380 px drawer got about 33 px each and read as 'P…', 'Pro…', 'Ne…'. The bar now draws the desktop row only when the viewport is at least `sm` and the bar itself is at least 24rem (384 px) wide. Otherwise it draws the compact form: the progress segments, then "Step N of M" and the current stage's full name, which opens the list of every stage. + +- Below `sm` nothing changes: the compact form, as before. +- A full-width record page keeps the desktop row, pixel for pixel. +- Nothing is authored for this: no new key, prop or translation string. diff --git a/ui/e2e/record-path-narrow-drawer-34696.spec.ts b/ui/e2e/record-path-narrow-drawer-34696.spec.ts new file mode 100644 index 00000000000..41bb09bb946 --- /dev/null +++ b/ui/e2e/record-path-narrow-drawer-34696.spec.ts @@ -0,0 +1,232 @@ +import { test, expect, type Page } from '@playwright/test'; +import { compile } from 'tailwindcss'; +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; +import { uiRoot } from '../scripts/ui-root.mjs'; + +/** + * GEOMETRY pin for `record:path` in a narrow record drawer at a desktop + * viewport (objectstack#34696). + * + * The desktop row and the compact path used to switch on the VIEWPORT alone, + * so a 380 px record drawer at a 1280 px viewport drew the desktop row: seven + * equal shares of about 33 px each, which read as 'P…', 'Pro…', 'Ne…'. The + * path's root is now a Tailwind container and each row stacks `sm` on the + * container's `@sm`, so that drawer draws the compact path, while a wide page + * draws the desktop row exactly as before, and a viewport below `sm` keeps the + * compact path whatever the path's width. + * + * 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 is pinned beside the renderer in `record-path.compact-34595.test.tsx`. + * + * REAL, read out of `record-path.tsx` at run time: the root's class, both + * rows' switch classes, the desktop row's group and stage classes, the label + * and rail base strings and the named PHONE_* constants, plus real Tailwind + * compiled from the installed `tailwindcss` for exactly those candidates. + * FIXTURE: the stage labels, and the element trees, transcribed from the two + * rows. + */ + +const REPO_ROOT = uiRoot(); +const PATH_FILE = 'packages/plugin-detail/src/renderers/record-path.tsx'; +const pathSrc = readFileSync(path.join(REPO_ROOT, PATH_FILE), 'utf8'); + +/** One string out of the source, asserting tokens so a drifted match throws. */ +function grab(re: RegExp, mustContain: string[]): string { + const m = pathSrc.match(re); + if (!m) throw new Error(`${PATH_FILE}: nothing matched ${re}`); + const cls = m[1]; + for (const token of mustContain) { + if (!cls.split(/\s+/).includes(token)) { + throw new Error( + `${PATH_FILE}: ${re} matched "${cls}", which does not carry "${token}" — the extraction ` + + 'walked onto the wrong string, so this measurement would be meaningless.', + ); + } + } + return cls; +} + +const CLS = { + root: grab(/
/, ['@container', 'w-full']), + desktop: grab(/\{\/\* Desktop[^\n]*\*\/\}\s*/, ['flex', 'min-w-0']), + lostGroup: grab(/ { + const stage = (label: string, terminal: boolean) => + `
` + + `` + + `${label}
`; + const forward = FORWARD.map((l, i) => stage(l, i === FORWARD.length - 1)).join(''); + const lost = LOST.map((l) => stage(l, true)).join(''); + const total = FORWARD.length + LOST.length; + return ( + `
` + + `
` + + `
${forward}
` + + `
${lost}
` + + '
' + + `
` + + `' + + `' + + '
' + + '
' + ); +}; + +const NOW = { root: CLS.root, desktop: CLS.desktop, compact: CLS.compact }; +/** The switch as it stood before this card: viewport only, no container. */ +const BEFORE = { + root: CLS.root.replace('@container', '').trim(), + desktop: CLS.desktop.replace('sm:@sm:flex', 'sm:flex'), + compact: CLS.compact.replace('sm:@sm:hidden', 'sm:hidden'), +}; + +let css = ''; +test.beforeAll(async () => { + const twEntry = fileURLToPath(import.meta.resolve('tailwindcss/index.css')); + const compiler = await compile('@import "tailwindcss";', { + base: path.dirname(twEntry), + loadStylesheet: async (id: string, base: string) => { + const file = id === 'tailwindcss' ? twEntry : path.resolve(base, id); + return { path: file, base: path.dirname(file), content: readFileSync(file, 'utf8') }; + }, + }); + css = compiler.build( + [...Object.values(CLS), ...Object.values(BEFORE), 'bg-muted font-normal ml-1 shrink-0 ml-auto h-4 w-4'] + .join(' ') + .split(/\s+/) + .filter(Boolean), + ); + if (!css.includes('@container')) { + throw new Error('Tailwind produced no container query — `sm:@sm:flex` would be inert.'); + } +}); + +type Reading = { + desktopShown: boolean; + compactShown: boolean; + labels: { label: string; ordinary: boolean; width: number; clipped: boolean; top: number; left: number }[]; + current: { clipped: boolean; right: number }; + railsFit: boolean; + drawerRight: number; +}; + +async function readPath( + page: Page, + opts: { viewport: number; container: number; cls?: typeof NOW; forceDesktop?: boolean }, +): Promise { + await page.setViewportSize({ width: opts.viewport, height: 900 }); + const force = opts.forceDesktop ? '#desktop{display:flex!important}' : ''; + await page.setContent( + `` + + `
${fixture(opts.cls ?? NOW)}
`, + { waitUntil: 'load' }, + ); + await page.evaluate(() => document.fonts?.ready); + return page.evaluate(() => { + const round = (n: number) => Math.round(n * 100) / 100; + const shown = (id: string) => getComputedStyle(document.getElementById(id)!).display !== 'none'; + const cur = document.getElementById('current')!; + const rails = document.getElementById('rails')!; + return { + desktopShown: shown('desktop'), + compactShown: shown('compact'), + labels: Array.from(document.querySelectorAll('#desktop [data-label]')).map((el) => { + const r = el.getBoundingClientRect(); + return { + label: el.dataset.label!, + ordinary: el.dataset.ordinary === 'yes', + width: round(r.width), + clipped: el.scrollWidth > el.clientWidth, + top: round(r.top), + left: round(r.left), + }; + }), + current: { clipped: cur.scrollWidth > cur.clientWidth, right: round(cur.getBoundingClientRect().right) }, + railsFit: rails.scrollWidth <= rails.clientWidth, + drawerRight: round(document.getElementById('drawer')!.getBoundingClientRect().right), + }; + }); +} + +test.describe('record:path in a narrow drawer at a desktop viewport (objectstack#34696)', () => { + test('the defect this pins: at 380px the desktop row gives each stage under 50px and cuts the long names', async ({ page }) => { + // Forced on, the desktop row shows what the drawer drew before: not vacuous. + const r = await readPath(page, { viewport: 1280, container: 380, forceDesktop: true }); + const ordinary = r.labels.filter((l) => l.ordinary); + expect(ordinary).toHaveLength(FORWARD.length - 1); + for (const l of ordinary) expect(l.width, `${l.label} got ${l.width}px`).toBeLessThan(50); + for (const name of ['Prospecting', 'Qualification', 'Needs Analysis', 'Negotiation']) { + expect(ordinary.find((l) => l.label === name)?.clipped, `${name} fit whole in the desktop row at 380px`).toBe(true); + } + }); + + for (const container of [360, 380]) { + test(`a ${container}px drawer at a 1280px viewport draws the compact path, the current stage whole`, async ({ page }) => { + const r = await readPath(page, { viewport: 1280, container }); + expect(r.desktopShown, 'the desktop row still draws in the narrow drawer').toBe(false); + expect(r.compactShown, 'the compact path is hidden in the narrow drawer').toBe(true); + expect(r.current.clipped, `${CURRENT} is cut`).toBe(false); + expect(r.current.right).toBeLessThanOrEqual(r.drawerRight + 0.5); + expect(r.railsFit, 'the rail spills out of its row').toBe(true); + }); + } + + test('a viewport below `sm` keeps the compact path even in a path wider than `@sm`', async ({ page }) => { + const r = await readPath(page, { viewport: 600, container: 560 }); + expect(r.desktopShown).toBe(false); + expect(r.compactShown).toBe(true); + }); + + test('CONTROL — a 900px path at a 1280px viewport draws the desktop row, every label readable', async ({ page }) => { + const r = await readPath(page, { viewport: 1280, container: 900 }); + expect(r.desktopShown, 'the wide page lost its desktop row').toBe(true); + expect(r.compactShown, 'the wide page drew the compact path').toBe(false); + for (const l of r.labels) { + expect(l.clipped, `${l.label} is cut on the wide page`).toBe(false); + expect(l.width).toBeGreaterThan(80); + } + }); + + test('CONTROL — the wide desktop row is pixel-identical to the viewport-only switch it replaces', async ({ page }) => { + for (const container of [900, 1200]) { + const now = await readPath(page, { viewport: 1280, container, cls: NOW }); + const before = await readPath(page, { viewport: 1280, container, cls: BEFORE }); + expect(before.desktopShown).toBe(true); + expect(now.labels, `the desktop row moved at ${container}px`).toEqual(before.labels); + } + }); +}); diff --git a/ui/e2e/record-path-phone-row.spec.ts b/ui/e2e/record-path-phone-row.spec.ts index 6cb905a238b..3f0ca69c1d3 100644 --- a/ui/e2e/record-path-phone-row.spec.ts +++ b/ui/e2e/record-path-phone-row.spec.ts @@ -50,7 +50,7 @@ function grab(re: RegExp, mustContain: string[]): string { } const CLS = { - compact: grab(/\{\/\* Mobile:[^\n]*\*\/\}\s* { [...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.'); + throw new Error('Tailwind produced no media queries — `sm:@sm:hidden` would be inert.'); } }); 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 index 485f48a7ccc..b54970fd4ba 100644 --- 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 @@ -67,11 +67,11 @@ const tokens = (el: Element): string[] => el.className.split(/\s+/).filter(Boole 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', () => { + it('is drawn below `sm` (and in a path narrower than `@sm`, objectstack#34696), beside the desktop rail', () => { const r = mount('negotiation'); - expect(tokens(compactOf(r))).toContain('sm:hidden'); + expect(tokens(compactOf(r))).toContain('sm:@sm:hidden'); const desktop = r.container.querySelector('[role="list"]') as HTMLElement; - expect(tokens(desktop)).toEqual(expect.arrayContaining(['hidden', 'sm:flex'])); + expect(tokens(desktop)).toEqual(expect.arrayContaining(['hidden', 'sm:@sm:flex'])); expect(compactOf(r).contains(desktop)).toBe(false); }); @@ -154,3 +154,31 @@ describe('record:path below `sm` is the compact path (objectstack#34595)', () => expect(within(desktop).queryByRole('button')).toBeNull(); }); }); + +describe('record:path picks its row by the viewport AND its own width (objectstack#34696)', () => { + // A 380 px record drawer at a desktop viewport drew the desktop row, whose + // seven equal shares cut each stage to a letter. The path's root is now a + // container, and each row's switch stacks `sm` on the container's `@sm`. + it('the root is the container both rows query, with no container between', () => { + const r = mount('negotiation'); + const compact = compactOf(r); + const desktop = r.container.querySelector('[role="list"]') as HTMLElement; + const root = compact.parentElement as HTMLElement; + expect(desktop.parentElement).toBe(root); + expect(tokens(root)).toEqual(expect.arrayContaining(['@container', 'w-full'])); + for (const row of [compact, desktop]) { + expect(row.closest('[class~="@container"]')).toBe(root); + } + }); + + it('neither row switches on the viewport alone any more', () => { + const r = mount('negotiation'); + const compact = tokens(compactOf(r)); + const desktop = tokens(r.container.querySelector('[role="list"]') as HTMLElement); + expect(compact).toContain('sm:@sm:hidden'); + expect(compact).not.toContain('sm:hidden'); + expect(compact).not.toContain('hidden'); + expect(desktop).toEqual(expect.arrayContaining(['hidden', 'sm:@sm:flex'])); + expect(desktop).not.toContain('sm:flex'); + }); +}); 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 a5b53b4dbd1..9af30f74f57 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 @@ -74,7 +74,7 @@ describe('record:path — the phone row fits and ellipsises (objectstack#26897)' const r = mount(); const phone = rows(r)[1]; const compact = phone.closest('[data-record-path-compact]') as HTMLElement; - expect(tokens(compact)).toContain('sm:hidden'); + expect(tokens(compact)).toContain('sm:@sm:hidden'); // objectstack#34696: viewport AND path width 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) { @@ -114,7 +114,7 @@ describe('record:path — the phone row fits and ellipsises (objectstack#26897)' it('CONTROL: the desktop rail is unchanged — no title, the ordinary label still truncates', () => { const desktop = rows(mount())[0]; - expect(tokens(desktop)).toContain('sm:flex'); + expect(tokens(desktop)).toContain('sm:@sm:flex'); // objectstack#34696: viewport AND path width const el = labelOf(stageNamed(desktop, 'Waiting on Customer')); expect(tokens(el)).toContain('truncate'); expect(el).not.toHaveAttribute('title'); diff --git a/ui/packages/plugin-detail/src/renderers/record-path.tsx b/ui/packages/plugin-detail/src/renderers/record-path.tsx index fbee10ccad3..f8facc48df8 100644 --- a/ui/packages/plugin-detail/src/renderers/record-path.tsx +++ b/ui/packages/plugin-detail/src/renderers/record-path.tsx @@ -122,8 +122,22 @@ const shareOf = (stageCount: number): React.CSSProperties => ({ flexGrow: stageC // 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 +// and the path's own width pick it (below). Geometry pinned in Chromium by // `e2e/record-path-phone-row.spec.ts`, which reads these constants. +// +// ── Which row draws: the viewport AND the path's width (objectstack#34696) ─ +// +// The root is a Tailwind `@container`, the pattern `HeaderHighlight` and +// `DetailSection` use for the same decision, and each row stacks a viewport +// variant on a container one: the desktop row is `hidden sm:@sm:flex`, the +// compact path `sm:@sm:hidden`. So the desktop row draws only when the +// viewport is at least `sm` AND the path itself is at least `@sm` (24rem) +// wide. Below `sm` nothing changes: the compact path, as above. At or above +// `sm`, a full-width record page gives the path more than 24rem, so the wide +// page keeps its desktop row; a narrow record drawer gives it less, so seven +// stages are not cut to a letter each there. Pure CSS, so it is right on the +// first paint with no measurement. Geometry pinned in Chromium by +// `e2e/record-path-narrow-drawer-34696.spec.ts`, which reads both classes. 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 = @@ -688,10 +702,10 @@ const RecordPathBody: React.FC = ({ : null; return ( -
- {/* Desktop: forward rail → optional lost-alt group */} +
+ {/* Desktop, at `sm` and a path of `@sm` or wider: forward rail → optional lost-alt group */}
@@ -759,8 +773,8 @@ const RecordPathBody: React.FC = ({ )}
- {/* Mobile: compact path — rail segments, the summary line, then the stage list (PHONE_* constants above) */} -
+ {/* Mobile: compact path, also for any path narrower than `@sm` — rail segments, the summary line, then the stage list (PHONE_* constants above) */} +
{/* The progress bar is decoration: the summary line and the stage list below carry every stage's name and state. */}