diff --git a/.changeset/36745-flow-header-meta-give-way.md b/.changeset/36745-flow-header-meta-give-way.md new file mode 100644 index 00000000000..344a845de28 --- /dev/null +++ b/.changeset/36745-flow-header-meta-give-way.md @@ -0,0 +1,9 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(studio): the flow header's meta gives way item by item instead of shrinking every item to one character + +In Studio's Automations pillar, the open flow's header shows its meta beside the title: Trigger, Status, Run as, version and, when set, On error. When the row was short of room — with the property panel open, about 80 px were left — every item shrank at once, so the row read as single characters with ellipses. + +Each item now keeps its whole text. When the row cannot hold them all, they drop from the end (On error, then version, then Run as), and hovering the row names each dropped item in full. Trigger and Status always show together: when the row cannot hold those two whole, the meta hides and the hover text names every item. Widen the row and the dropped items come back. The designer's info bar is unchanged. diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.headerMetaGiveWay-36745.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.headerMetaGiveWay-36745.test.tsx new file mode 100644 index 00000000000..edb37f9b620 --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.headerMetaGiveWay-36745.test.tsx @@ -0,0 +1,172 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36745 — with the property panel open, the Studio flow header's + * meta ("Trigger: … · Status: … · Run as: … · v3 · On error: …") shrank every + * item at once, to one character each (objectui#13135's shrinking grid). The + * row now gives way item by item: + * + * - every item keeps its whole text (no item truncates); + * - items drop from the end — On error, then version, then Run as — and the + * row's hover text names each dropped item's whole text, in row order; + * - Trigger and Status are the floor: when the row cannot hold those two + * whole, every item hides and the hover text names all of them; + * - an item that fits again comes back when the row widens; + * - CONTROL: the designer's info bar (`bar`) has no such row. + * + * jsdom lays nothing out, so widths are the elements' own readings, stubbed + * here per element: the row reads the width under test, each item its width. + */ + +import * as React from 'react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, render, screen, within } from '@testing-library/react'; +// The source under test reaches `import('@objectstack/lint')` inside a function +// body; pay that load during collection, never inside a clocked case. +import '@objectstack/lint'; + +vi.stubGlobal( + 'fetch', + vi.fn(async () => new Response('not found', { status: 404 })), +); + +import { FlowMetaPills, fitFlowMetaItems } from './FlowPreview'; +import { t, translateFlowMeta } from '../i18n'; + +const LOCALE = 'en-US'; +const en = (key: string): string => t(key, LOCALE); + +const DRAFT: Record = { + name: 'f1', + label: 'F1', + type: 'autolaunched', + version: 3, + runAs: 'system', + errorHandling: { strategy: 'continue' }, + nodes: [ + { id: 'start', type: 'start', label: 'Start', config: {} }, + { id: 'end', type: 'end', label: 'End' }, + ], + edges: [{ id: 'e1', source: 'start', target: 'end' }], +}; + +/** Each item's whole width with its leading separator; the five sum to 400. */ +const WIDTH: Record = { trigger: 120, status: 110, runAs: 80, version: 30, onError: 60 }; + +let rowWidth = 0; +const original = HTMLElement.prototype.getBoundingClientRect; + +beforeEach(() => { + HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) { + const key = this.dataset.metaItem; + const width = this.dataset.testid === 'flow-meta-row' ? rowWidth : key ? (WIDTH[key] ?? 0) : 0; + return { x: 0, y: 0, top: 0, left: 0, bottom: 16, right: width, width, height: 16, toJSON: () => ({}) } as DOMRect; + }; +}); + +afterEach(() => { + cleanup(); + HTMLElement.prototype.getBoundingClientRect = original; +}); + +const whole = { + trigger: () => `${en('engine.flowPreview.pill.trigger')}: autolaunched`, + status: () => `${en('engine.flowPreview.pill.status')}: ${en('engine.studio.unpublishedDraft')}`, + runAs: () => `${en('engine.flowPreview.pill.runAs')}: ${translateFlowMeta('runAs', 'system', LOCALE)}`, + version: () => 'v3', + onError: () => `${en('engine.flowPreview.pill.onError')}: ${translateFlowMeta('onError', 'continue', LOCALE)}`, +}; + +function renderHeaderAt(width: number, variant: 'header' | 'bar' = 'header') { + rowWidth = width; + return render(); +} + +function row(): HTMLElement { + return screen.getByTestId('flow-meta-row'); +} + +/** The items the row shows, in order: the ones not made invisible. */ +function shownKeys(): string[] { + return Array.from(row().querySelectorAll('[data-meta-item]')) + .filter((el) => !el.classList.contains('invisible')) + .map((el) => el.dataset.metaItem!); +} + +describe('the flow header meta gives way item by item (objectstack#36745)', () => { + it('wide row (400 px): every item shows whole, and the row has no hover text', () => { + renderHeaderAt(400); + expect(shownKeys()).toEqual(['trigger', 'status', 'runAs', 'version', 'onError']); + expect(row()).not.toHaveAttribute('title'); + }); + + it('middle row (320 px): On error, then version, drop; the hover text names both whole', () => { + renderHeaderAt(320); + expect(shownKeys()).toEqual(['trigger', 'status', 'runAs']); + expect(row()).toHaveAttribute('title', [whole.version(), whole.onError()].join('\n')); + }); + + it('narrow row (240 px): Run as drops too; Trigger and Status stay whole', () => { + renderHeaderAt(240); + expect(shownKeys()).toEqual(['trigger', 'status']); + expect(row()).toHaveAttribute('title', [whole.runAs(), whole.version(), whole.onError()].join('\n')); + }); + + it('a row too narrow for Trigger and Status (200 px, the panel-open case) hides every item', () => { + renderHeaderAt(200); + expect(shownKeys()).toEqual([]); + expect(row()).toHaveAttribute( + 'title', + [whole.trigger(), whole.status(), whole.runAs(), whole.version(), whole.onError()].join('\n'), + ); + // Hidden items are out of the accessibility tree, not half-drawn. + for (const el of row().querySelectorAll('[data-meta-item]')) expect(el).toHaveAttribute('aria-hidden', 'true'); + }); + + it('an item that fits again comes back when the row re-renders wider', () => { + const view = renderHeaderAt(200); + expect(shownKeys()).toEqual([]); + rowWidth = 400; + view.rerender(); + expect(shownKeys()).toEqual(['trigger', 'status', 'runAs', 'version', 'onError']); + }); + + it('no header item truncates: each keeps its whole text on one line', () => { + renderHeaderAt(240); + for (const el of row().querySelectorAll('[data-meta-item], [data-meta-item] *')) { + expect(el).not.toHaveClass('truncate'); + } + expect(within(row()).getByText(`${en('engine.flowPreview.pill.status')}:`).parentElement).toHaveClass('whitespace-nowrap'); + }); + + it("CONTROL: a shown Status keeps its own hover text (the run status's reason)", () => { + renderHeaderAt(400); + expect(within(row()).getByText(`${en('engine.flowPreview.pill.status')}:`).parentElement).toHaveAttribute( + 'title', + en('engine.studio.auto.unpublishedTitle'), + ); + }); + + it("CONTROL: the designer's info bar has no give-way row and shows every item", () => { + renderHeaderAt(0, 'bar'); + expect(screen.queryByTestId('flow-meta-row')).toBeNull(); + expect(screen.getByText(`${en('engine.flowPreview.pill.onError')}:`)).toBeVisible(); + }); +}); + +describe('fitFlowMetaItems', () => { + const widths = [120, 110, 80, 30, 60]; + it('keeps as many whole items from the front as fit', () => { + expect(fitFlowMetaItems(widths, 400)).toBe(5); + expect(fitFlowMetaItems(widths, 399)).toBe(4); + expect(fitFlowMetaItems(widths, 310)).toBe(3); + expect(fitFlowMetaItems(widths, 230)).toBe(2); + }); + it('shows nothing below the Trigger + Status floor', () => { + expect(fitFlowMetaItems(widths, 229)).toBe(0); + expect(fitFlowMetaItems(widths, 0)).toBe(0); + }); + it('absorbs a half-pixel of fractional width', () => { + expect(fitFlowMetaItems([120.4, 110.3], 230.5)).toBe(2); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.headerMetaTruncate-13135.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.headerMetaTruncate-13135.test.tsx deleted file mode 100644 index d924de93abe..00000000000 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.headerMetaTruncate-13135.test.tsx +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. - -/** - * objectui#13135 — the Studio flow header's meta pills ("Trigger: … · Status: - * … · Run as: …") were clipped mid-word ("Status: Unpublis") with no ellipsis - * and no tooltip: the header row was a flex row whose minimum width is the sum - * of its items' text, so the meta slot cut it like a picture. - * - * - each header pill truncates with an ellipsis (`truncate`), never a bare - * clip on an unshrinkable `whitespace-nowrap` box; - * - a cut pill names its whole `Label: value` in its `title`, before the - * hover text it already had (the run status's reason); - * - CONTROL: a pill that is not cut keeps the hover text it had, and the - * designer's info bar (`bar`) is not measured at all. - * - * jsdom lays nothing out, so "cut" is the element's own reading, stubbed here: - * `scrollWidth` wider than `clientWidth`, as a browser reports a cut box. - */ - -import * as React from 'react'; -import { afterEach, describe, expect, it, vi } from 'vitest'; -import { cleanup, render, screen } from '@testing-library/react'; - -vi.stubGlobal( - 'fetch', - vi.fn(async () => new Response('not found', { status: 404 })), -); - -import { FlowMetaPills } from './FlowPreview'; -import { t } from '../i18n'; - -const LOCALE = 'en-US'; -const en = (key: string): string => t(key, LOCALE); - -const DRAFT: Record = { - name: 'f1', - label: 'F1', - type: 'autolaunched', - nodes: [ - { id: 'start', type: 'start', label: 'Start', config: {} }, - { id: 'end', type: 'end', label: 'End' }, - ], - edges: [{ id: 'e1', source: 'start', target: 'end' }], -}; - -const restores: Array<() => void> = []; - -/** Every element reports its text wider than its box: a browser's reading of a cut element. */ -function everyBoxCut(): void { - for (const [prop, value] of [ - ['scrollWidth', 200], - ['clientWidth', 100], - ] as const) { - const before = Object.getOwnPropertyDescriptor(HTMLElement.prototype, prop); - Object.defineProperty(HTMLElement.prototype, prop, { configurable: true, get: () => value }); - restores.push(() => { - if (before) Object.defineProperty(HTMLElement.prototype, prop, before); - else delete (HTMLElement.prototype as unknown as Record)[prop]; - }); - } -} - -afterEach(() => { - cleanup(); - while (restores.length) restores.pop()!(); -}); - -/** The pill whose caption is `label`: the element that carries the class and the `title`. */ -function pill(label: string): HTMLElement { - return screen.getByText(`${label}:`).parentElement as HTMLElement; -} - -function renderHeader(variant: 'header' | 'bar' = 'header'): void { - render(); -} - -describe('the flow header meta pills truncate with an ellipsis and a title (objectui#13135)', () => { - it('the header Status pill ellipsizes rather than clipping bare', () => { - renderHeader(); - const status = pill(en('engine.flowPreview.pill.status')); - expect(status).toHaveClass('truncate'); - expect(status).not.toHaveClass('shrink-0'); - }); - - it('a cut Status pill names its whole "Label: value" first, then its reason', () => { - everyBoxCut(); - renderHeader(); - const label = en('engine.flowPreview.pill.status'); - expect(pill(label)).toHaveAttribute( - 'title', - `${label}: ${en('engine.studio.unpublishedDraft')}\n${en('engine.studio.auto.unpublishedTitle')}`, - ); - }); - - it('a cut pill with no hover text of its own names its whole "Label: value"', () => { - everyBoxCut(); - renderHeader(); - const label = en('engine.flowPreview.pill.trigger'); - expect(pill(label)).toHaveAttribute('title', `${label}: autolaunched`); - }); - - it('CONTROL: a header pill that is not cut keeps the hover text it had', () => { - renderHeader(); - expect(pill(en('engine.flowPreview.pill.status'))).toHaveAttribute('title', en('engine.studio.auto.unpublishedTitle')); - expect(pill(en('engine.flowPreview.pill.trigger'))).not.toHaveAttribute('title'); - }); - - it("CONTROL: the designer's info bar is not measured — its pills keep their hover text", () => { - everyBoxCut(); - renderHeader('bar'); - expect(pill(en('engine.flowPreview.pill.status'))).toHaveAttribute('title', en('engine.studio.auto.unpublishedTitle')); - }); -}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.tsx index e77f9b9894d..fab3a9e88f9 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowPreview.tsx @@ -258,13 +258,15 @@ const NO_OBJECTS: ObjectCatalogEntry[] = []; * `header` drops them and separates the items with dots, at the header's meta * size. Each item keeps its `Label:` caption and its value as sibling spans. * - * objectui#13135 — the header lays its items out as a one-row grid whose - * columns may shrink to nothing (`minmax(0, max-content)`), so the row's own - * minimum width is near zero and it fits the meta slot instead of overflowing - * it. Each item then truncates with an ellipsis, and a cut item names its - * whole `Label: value` on hover. The row never wraps, so the header keeps its - * height. (A flex row cannot do it: its minimum width is the sum of its - * items' text, so the slot clipped it mid-word with no ellipsis.) + * objectstack#36745 — the header row gives way item by item, never all at + * once. Every item keeps its whole text; when the row cannot hold them all, + * they drop from the end (On error, then version, then Run as), and the row's + * hover text names each dropped item's whole `Label: value`. Trigger and + * Status are the floor: when the row cannot hold those two whole, every item + * hides and the slot shows nothing. The row never wraps, so the header keeps + * its height. (It replaces objectui#13135's shrinking grid, whose columns all + * gave way together: with the property panel open every item read as one + * character.) See {@link FlowMetaHeaderRow}. */ export function FlowMetaPills({ draft, @@ -286,66 +288,139 @@ export function FlowMetaPills({ const header = variant === 'header'; const catalog = useObjectCatalog(); const trigger = flowTriggerLabel(draft, nodes, catalog.status === 'loaded' ? catalog.data : NO_OBJECTS, locale); - const items: React.ReactNode[] = [ + // `whole` is the item's whole text, which the header row's hover text names + // when the item has given way (objectstack#36745). + const items: Array<{ key: string; whole: string; node: React.ReactNode }> = []; + const add = (key: string, whole: string, node: React.ReactElement) => items.push({ key, whole, node }); + const triggerLabel = tr('engine.flowPreview.pill.trigger', locale); + const statusLabel = tr('engine.flowPreview.pill.status', locale); + const runAsLabel = tr('engine.flowPreview.pill.runAs', locale); + const runAsValue = translateFlowMeta('runAs', runAs, locale); + add( + 'trigger', + `${triggerLabel}: ${trigger.value}`, , + ); + add( + 'status', + `${statusLabel}: ${runView.label}`, , - , - ]; + ); + add( + 'runAs', + `${runAsLabel}: ${runAsValue}`, + , + ); if (version) { - items.push( - header ? ( - - v{version} - - ) : ( - - ), + add( + 'version', + `v${version}`, + header ? v{version} : , ); } if (onError) { - items.push( + const onErrorLabel = tr('engine.flowPreview.pill.onError', locale); + const onErrorValue = translateFlowMeta('onError', onError, locale); + add( + 'onError', + `${onErrorLabel}: ${onErrorValue}`, , ); } - if (!header) return <>{items}; + if (!header) return <>{items.map((item) => item.node)}; + return ; +} + +/** + * objectstack#36745 — how many of the header's meta items the row shows, from + * the front: as many whole items as fit `available`, each item's `widths` + * entry being its whole width with its leading separator. Fewer than `floor` + * (Trigger and Status) ⇒ 0: the row shows nothing rather than half of the + * two items it always leads with. A half-pixel of slack absorbs the + * fractional widths a browser reports. + */ +export function fitFlowMetaItems(widths: readonly number[], available: number, floor = 2): number { + let used = 0; + let shown = 0; + for (const width of widths) { + if (used + width > available + 0.5) break; + used += width; + shown += 1; + } + return shown < Math.min(floor, widths.length) ? 0 : shown; +} + +/** + * objectstack#36745 — the header's meta row. Every item is laid out whole, in + * order, each after its `·` separator; the row takes the meta slot's width and + * clips. After each render and on every resize it measures each item's own + * width and the row's, keeps the first {@link fitFlowMetaItems} items, and + * makes the rest invisible (still laid out, so still measured: an item that + * fits again comes back when the row widens). The row's hover text names each + * hidden item's whole text, one per line; with nothing hidden it has none. + */ +function FlowMetaHeaderRow({ items }: { items: ReadonlyArray<{ key: string; whole: string; node: React.ReactNode }> }) { + const rowRef = React.useRef(null); + const [shown, setShown] = React.useState(items.length); + const fit = React.useCallback(() => { + const row = rowRef.current; + if (!row) return; + const widths = Array.from(row.children, (el) => el.getBoundingClientRect().width); + setShown(fitFlowMetaItems(widths, row.getBoundingClientRect().width)); + }, []); + // Every render: an item's text can change without the row resizing. + React.useLayoutEffect(fit); + React.useEffect(() => { + const row = rowRef.current; + if (!row || typeof ResizeObserver === 'undefined') return; + const observer = new ResizeObserver(fit); + observer.observe(row); + return () => observer.disconnect(); + }, [fit]); + const dropped = items.slice(shown).map((item) => item.whole); return ( - + {items.map((item, i) => ( - + 0 ? ' pl-1.5' : ''}${i < shown ? '' : ' invisible'}`} + > {i > 0 && ( · )} - {item} - + {item.node} + ))} ); @@ -812,11 +887,6 @@ function Pill({ /** The item header's meta (objectui#12454): the value at the caption's weight, plain text muted. */ compact?: boolean; }) { - const ref = React.useRef(null); - const cut = useCutText(ref, compact); - // objectui#13135 — a cut header item says its whole text first, then the - // hover text it already had (the run status's reason, the object's name). - const hover = cut ? [`${label}: ${value}`, title].filter(Boolean).join('\n') : title; const cls = tone === 'green' ? 'text-emerald-700 dark:text-emerald-400' @@ -826,7 +896,7 @@ function Pill({ ? 'text-muted-foreground' : 'text-foreground'; return ( - + {Icon && } {label}: {value} @@ -834,26 +904,3 @@ function Pill({ ); } -/** - * objectui#13135 — whether the element's text is cut (wider than its box), - * measured on every render and on resize, as the Studio header's title - * measures its own (objectui#12897). `false` while `enabled` is off. - */ -function useCutText(ref: React.RefObject, enabled: boolean): boolean { - const [cut, setCut] = React.useState(false); - const measure = React.useCallback(() => { - const el = ref.current; - setCut(enabled && !!el && el.scrollWidth > el.clientWidth + 0.5); - }, [ref, enabled]); - // Every render: the text can change without the box resizing. - React.useLayoutEffect(measure); - React.useEffect(() => { - const el = ref.current; - if (!enabled || !el || typeof ResizeObserver === 'undefined') return; - const observer = new ResizeObserver(measure); - observer.observe(el); - return () => observer.disconnect(); - }, [ref, enabled, measure]); - return cut; -} - diff --git a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx index 9a0c91440ce..74d2150d2ec 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx @@ -9951,6 +9951,8 @@ export function AutomationsPillar({ // Canvas tab's description and title), so the row still reads it // whole as objectui#11665 pins. Without designers the line says // so, and yields to the label on a narrow row as it did. + // objectstack#36745 — the meta wrapper is a block-level flex, so + // the give-way row inside it reads the slot's whole width. meta={ isEditable ? ( <> @@ -9958,7 +9960,7 @@ export function AutomationsPillar({ {t('engine.studio.auto.canvasHint', locale)} {flowOpen && headerRunStatus && ( - + )}