Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/34148-record-page-formula-wraps.md
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 30 additions & 2 deletions ui/packages/plugin-detail/src/DetailSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
resolveRecordPointer,
RECORD_POINTER_CARD_TYPE,
coerceToSafeValue,
FormulaCellRenderer,
FormulaField,
TextAreaField,
TextCellRenderer,
TextField,
Expand Down Expand Up @@ -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 => {};

Expand Down Expand Up @@ -673,6 +675,32 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
/>
);
}
// 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 (
<FormulaField
field={enrichedField as unknown as FieldMetadata}
value={value}
onChange={ignoreReadOnlyChange}
dependentValues={data}
readonly
/>
);
}
if (CellRenderer) {
return (
<CellRenderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { render, screen, cleanup, act, waitFor } from '@testing-library/react';
import * as React from 'react';
import { RecordContextProvider } from '@object-ui/react';
import { TextField, TextCellRenderer, getCellRenderer, registerFieldRenderer } from '@object-ui/fields';
import {
FormulaCellRenderer,
FormulaField,
TextField,
TextCellRenderer,
getCellRenderer,
registerFieldRenderer,
} from '@object-ui/fields';
import { RecordDetailsRenderer } from '../record-details';

/** The case subject the browser pass read cut. */
Expand All @@ -63,17 +70,21 @@ const caseSchema = {
};
const BODY_FIELDS = ['subject', 'reference'];

async function renderBody(record: Record<string, unknown>) {
const ds = { getObjectSchema: vi.fn(async () => caseSchema) };
async function renderBody(
record: Record<string, unknown>,
schema: typeof caseSchema = caseSchema,
bodyFields: string[] = BODY_FIELDS,
) {
const ds = { getObjectSchema: vi.fn(async () => schema) };
render(
<RecordContextProvider
objectName="support_case"
objectName={schema.name}
recordId="C2"
data={{ id: 'C2', case_number: 'CASE-00002', ...record }}
objectSchema={caseSchema}
objectSchema={schema}
dataSource={ds as never}
>
<RecordDetailsRenderer schema={{ fields: BODY_FIELDS } as never} />
<RecordDetailsRenderer schema={{ fields: bodyFields } as never} />
</RecordContextProvider>,
);
await waitFor(() => expect(ds.getObjectSchema).toHaveBeenCalled());
Expand Down Expand Up @@ -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<string, unknown>) =>
markupOf(<FormulaField field={{ name, type: 'formula', label: name, ...extra } as never} value={value} onChange={() => {}} 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(
<FormulaCellRenderer value={EXPLANATION} field={{ name: 'explanation', type: 'formula', returnType: 'text' } as never} />,
);
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 }) => <em data-host-formula>{String(value)}</em>;
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);
}
});
});
Loading