diff --git a/.changeset/34148-record-page-formula-wraps.md b/.changeset/34148-record-page-formula-wraps.md new file mode 100644 index 00000000000..82fa530d5df --- /dev/null +++ b/.changeset/34148-record-page-formula-wraps.md @@ -0,0 +1,12 @@ +--- +'@object-ui/plugin-detail': patch +--- + +fix(plugin-detail): a long text formula on the record page wraps instead of being cut to one line + +Clause-②: no — a value that was cut now shows in full; no surface added +Metadata-protocol: none + +The record page's field grid drew `formula` values with the formula cell, whose text face is the grid's one-line cell (`truncate`, an ellipsis, the whole value only in a hover `title`). A long text formula, such as an explanation sentence, read as its first few words, and touch and screen-reader users never reached the rest. + +A formula row now reads through `FormulaField`, the formula's own read display and the face the record form draws. Its text face wraps. Number, money, date and boolean results read the same words as before, because the widget reads the value by the rule the cell reads it by. List grid rows and the highlights strip keep the one-line cell. A host that registered its own `formula` cell keeps it on the record page. diff --git a/ui/packages/plugin-detail/src/DetailSection.tsx b/ui/packages/plugin-detail/src/DetailSection.tsx index 55eee3eb198..425bbac814c 100644 --- a/ui/packages/plugin-detail/src/DetailSection.tsx +++ b/ui/packages/plugin-detail/src/DetailSection.tsx @@ -45,6 +45,8 @@ import { resolveRecordPointer, RECORD_POINTER_CARD_TYPE, coerceToSafeValue, + FormulaCellRenderer, + FormulaField, TextAreaField, TextCellRenderer, TextField, @@ -114,8 +116,8 @@ export function getResponsiveSpanClass(span: number | undefined, columns: number /** * The `onChange` a read display is handed. The `readonly` branches of - * `TextAreaField` and `TextField` render no control and never call it; the - * widget contract requires the slot. + * `TextAreaField` and `TextField`, and the read-only `FormulaField`, render + * no control and never call it; the widget contract requires the slot. */ const ignoreReadOnlyChange = (): void => {}; @@ -673,6 +675,32 @@ export const DetailSection: React.FC = ({ /> ); } + // A formula reads through `FormulaField`, its own field widget's read + // display, the face the record form draws (objectstack#34148): the + // same move the two branches above make. The formula cell's text face + // is `TextCellRenderer`, one line and an ellipsis with the whole value + // only in a hover `title`, which is right for a grid row and stays + // there. `FormulaField` reads the value by the rule the cell reads it + // by, and `formulaFaces.*` in the fields package compare the two + // faces' text for every return type, so a number, money, date or + // boolean result reads the same words here; its text face wraps. + // Matched by renderer identity and the `formula` type, so a host that + // registered its own `formula` face keeps it, and `summary` (which the + // table also maps to this cell) keeps the cell. The raw value goes in: + // the widget coerces it as the cell does and reads a JS number as a + // number. The row is the widget's record, as it is the cell's below, + // for a `record`-mode currency that a sibling field names. + if (CellRenderer === FormulaCellRenderer && resolvedType === 'formula') { + return ( + + ); + } if (CellRenderer) { return ( ) { - const ds = { getObjectSchema: vi.fn(async () => caseSchema) }; +async function renderBody( + record: Record, + schema: typeof caseSchema = caseSchema, + bodyFields: string[] = BODY_FIELDS, +) { + const ds = { getObjectSchema: vi.fn(async () => schema) }; render( - + , ); await waitFor(() => expect(ds.getObjectSchema).toHaveBeenCalled()); @@ -195,3 +206,99 @@ describe('objectstack#25897 — CONTROLS', () => { } }); }); + +/** + * objectstack#34148 — a text-returning formula wraps in `record:details` read + * mode too. + * + * A downstream CRM read a margin-precheck explanation (a text formula of about + * 120 characters) cut to one line with an ellipsis, the whole sentence only in + * a hover `title`. `formula` maps to `FormulaCellRenderer`, whose text face is + * the grid's one-line `TextCellRenderer`. The row now reads it through + * `FormulaField`, the face the record form draws. + * The change is a renderer choice and a class list, so a viewport-sized + * happy-dom render covers 1440 px and phone width alike: no layout engine + * runs, and none is needed to read which element draws the value. + * + * Controls: the grid keeps the one-line formula cell; a number formula keeps + * its number text; a host's own `formula` face is kept on the record page. + */ +const EXPLANATION = ( + 'Lowest landed cost of cost week 2026-W46: 6520 (Shanxi plant: 6260 + 260); quoted 7123.89; margin 8.48% >= tier A 4%, passes.' +).slice(0, 120); + +const quoteLineSchema = { + name: 'quote_line', + label: 'Quote line', + nameField: 'case_number', + fields: { + case_number: { type: 'text', label: 'Line' }, + explanation: { type: 'formula', label: 'Precheck Explanation', returnType: 'text', expression: 'record.case_number' }, + undeclared: { type: 'formula', label: 'Undeclared Formula', expression: 'record.case_number' }, + margin: { type: 'formula', label: 'Margin', returnType: 'number', scale: 2, expression: '1' }, + }, +} as unknown as typeof caseSchema; +const QUOTE_LINE_FIELDS = ['explanation', 'undeclared', 'margin']; +const QUOTE_LINE = { explanation: EXPLANATION, undeclared: EXPLANATION, margin: 1234.5 }; + +const formulaReadDisplay = (name: string, value: unknown, extra: Record) => + markupOf( {}} readonly />); + +for (const [layout, width] of [['desktop 1440', 1440], ['phone', MOBILE_WIDTH]] as const) { + describe(`objectstack#34148 — record:details read mode, ${layout}: a long text formula wraps`, () => { + const cellLayout = layout === 'phone' ? 'mobile' : 'desktop'; + beforeEach(pinViewport(width)); + + it('the fixture is a 120-character value', () => { + expect(EXPLANATION).toHaveLength(120); + }); + + for (const [label, name, extra] of [ + ['Precheck Explanation', 'explanation', { returnType: 'text', expression: 'record.case_number' }], + ['Undeclared Formula', 'undeclared', { expression: 'record.case_number' }], + ] as const) { + it(`a formula \`${name}\` cell holds the read display FormulaField renders, and wraps`, async () => { + await renderBody(QUOTE_LINE, quoteLineSchema, QUOTE_LINE_FIELDS); + const cell = valueCellOf(label, cellLayout); + expect(cell.innerHTML).toBe(formulaReadDisplay(name, EXPLANATION, extra)); + const node = drawingNodeOf(cell, EXPLANATION); + expect(node.textContent).toBe(EXPLANATION); + expect(oneLineClassesBetween(node, cell)).toEqual([]); + // The whole value is the visible text, not a hover tooltip. + expect(node).not.toHaveAttribute('title'); + }); + } + }); +} + +describe('objectstack#34148 — CONTROLS', () => { + beforeEach(pinViewport(1440)); + + it('the grid keeps its one-line formula cell, titled with the whole value', () => { + expect(getCellRenderer('formula')).toBe(FormulaCellRenderer); + const { container } = render( + , + ); + const span = container.querySelector('span'); + expect(span).toHaveClass('truncate'); + expect(span).toHaveAttribute('title', EXPLANATION); + }); + + it('a number formula keeps its number text on the record page', async () => { + await renderBody(QUOTE_LINE, quoteLineSchema, QUOTE_LINE_FIELDS); + expect(valueCellOf('Margin', 'desktop').textContent).toBe('1,234.50'); + }); + + it("a host's own `formula` face is kept on the record page", async () => { + const shipped = getCellRenderer('formula'); + const HostFormula = ({ value }: { value: unknown }) => {String(value)}; + try { + registerFieldRenderer('formula', HostFormula as never); + await renderBody(QUOTE_LINE, quoteLineSchema, QUOTE_LINE_FIELDS); + const cell = valueCellOf('Precheck Explanation', 'desktop'); + expect(cell.querySelector('em[data-host-formula]')?.textContent).toBe(EXPLANATION); + } finally { + registerFieldRenderer('formula', shipped); + } + }); +});