Skip to content

Commit 28749e3

Browse files
fix(plugin-detail): summary chip honours percentDisplay plain (#36279)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XTRdLmK9YYgMSCJ7NH2PuUY)_ Fixes #36078 Clause-②: no Metadata-protocol: none ## 维护者速读 - 看记录页的用户:标题旁的摘要小标签里,百分比字段设成「只显示数字」时,以前仍画进度条,改后只显示百分数;其他情况不变。 - 为什么做:让记录页和列表对同一个百分比字段显示一致,解决胜率、利润率这类比率被误读成进度的问题。 - 出错会怎样:最坏是摘要小标签多画或少画一条进度条,数值文字不受影响,可直接撤回本次改动。 - 要你做什么:无。 ## What changes The record header's `summaryFields` chip now honours a percent field's `percentDisplay` (the `percentDisplay` describe in `packages/spec/src/data/field.zod.ts`: `plain` = "the percentage as text alone, with no bar"). In `DetailView`'s chip percent arm, the bar's fill value is computed only when the merged field bag (view entry over object schema, the same `percentField` bag the arm already reads `scale` and `max` from) does not say `plain`; with `plain`, the chip falls through to the plain Badge branch, so the text (`formatPercent`, unchanged) and the accessible name (`Label: 40%`, unchanged) stay and only the bar goes. Because the arm is chosen by `armType`, a `formula` whose `returnType` is `percent` takes the same path and its own `percentDisplay` counts too. The bar-or-not rule is the literal `percentDisplay === 'plain'` test, inline in `PercentCellRenderer` (`@object-ui/fields`) and not exported, so this is a local read of the one key, not a second copy of an exported helper and not a published-export change. No `packages/spec` change. Changeset: `@object-ui/plugin-detail` patch. Read first (by risk): 1. `ui/packages/plugin-detail/src/DetailView.tsx`, the hunk guarding `summaryChipPercentPoints` with `percentField.percentDisplay !== 'plain'`. 2. `ui/packages/plugin-detail/src/__tests__/summaryChip.percentPlain-36078.test.tsx`. Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-detail/src/__tests__/summaryChip.percentPlain-36078.test.tsx` (spec, formula and client built) prints 7 passed. ## Tests New `summaryChip.percentPlain-36078.test.tsx` (7 cases), stored value `0.4`: - percent field `plain` reads `40%`, accessible name `Probability: 40%`, no bar track; - percent formula (`returnType: 'percent'`) `plain`: same; - `plain` declared on the object schema only (no view entry), judged after an arrival probe: same; - CONTROL: percent field with no `percentDisplay`, and with `bar`, draws the bar filled to `40%`; - CONTROL: percent formula with no `percentDisplay`, and with `bar`, draws the bar; - CONTROL: a view entry `bar` over an object schema `plain` draws the bar (precedence). ## Acceptance notes - Directions on the base tree were predicted before the first run and the ablation matched them: the three `plain` cases red, the four controls green. - Overlap: `overlap-check.mjs` names open PR #36234 as sharing `DetailView.tsx`; it merges cleanly with this branch. - No out-of-scope findings. ## Verification All readings at head `4bf99c41`. <details><summary>Targeted tests (under the shared verify lock)</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/src/__tests__/summaryChip`: Test Files 10 passed, 1 skipped (11); Tests 106 passed, 8 skipped. The existing `summaryChip*` pins stay green. - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/src/__tests__/percentDisplayRelay-28255.test.tsx packages/plugin-grid/src/__tests__/percentAbsentScale.fiveFaces-9843.test.tsx packages/plugin-detail/src/__tests__/DetailView`: Test Files 25 passed (25); Tests 170 passed (170). - `pnpm --filter @object-ui/plugin-detail run type-check`: exit 0 (after building the `@object-ui/plugin-detail^...` closure); `tsconfig.test.json --listFilesOnly` includes the new test file. - The full `@object-ui/plugin-detail` suite (405 test files) is declared to CI's `Test UI`, not run locally. </details> <details><summary>Ablation (one, on the committed fix)</summary> `node scripts/ablation-replace.mjs` replaced the guard `if (percentField.percentDisplay !== 'plain') {` with an always-true guard: anchor 1 to 0, blob `c62b65de4f71` to `915375fad2c8`. The new file then read 3 failed, 4 passed: exactly the three `plain` cases red, all four controls green. Restore: blob after restore equals HEAD (`c62b65de4f71`), `git diff HEAD` empty, marker count 0. The test imports `../DetailView` from source, so no build sits between the mutation and the run. </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 38 commands for this diff; 37 ran locally with exit 0; `pnpm check:type-check-debt` is NOT MEASURED (its closure build never acquired the shared verify lock, exit 3 PREREQUISITE NOT MET) and is CI's `Lint & Repo Gates`. `--ran` reconciliation: 38 derived, 37 run, 1 NOT-MEASURED, 0 UNRUN. Also `pnpm --dir ui run check:new-line-citations`: 0 new citations. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5oLLK7uoxp33riiBJL)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8925d5b commit 28749e3

3 files changed

Lines changed: 179 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): the record header's summary chip honours `percentDisplay: 'plain'`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The `summaryFields` chip beside the record title drew its progress bar for every `percent` field and every `formula` whose `returnType` is `percent`, even when the field declares `percentDisplay: 'plain'` — the face `@objectstack/spec` describes as "the percentage as text alone, with no bar", which the list cell already honoured. The chip now reads `percentDisplay` off the same merged field it reads `scale` and `max` from (the view's entry over the object schema): `plain` shows the percentage text alone, while an absent `percentDisplay` or `bar` keeps the bar. The text, its accessible name and the stored value are unchanged.

‎ui/packages/plugin-detail/src/DetailView.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,17 @@ export const DetailView: React.FC<DetailViewProps> = ({
14571457
// `50%`. Text and bar take the one answer.
14581458
const percentScale = percentCellScale({ type: armType, max: percentField.max });
14591459
display = formatPercent(num, percentScale, scale, displayLocale);
1460-
const points = summaryChipPercentPoints(num, percentScale);
1461-
percentValue = Math.max(0, Math.min(100, points));
1460+
// The field's read-only face, `percentDisplay` in
1461+
// `@objectstack/spec`: `plain` is a rate or a
1462+
// probability, not progress, so the chip states the
1463+
// percentage alone and draws no bar; absent or `bar`
1464+
// keeps it. The same literal test `PercentCellRenderer`
1465+
// applies, read off the same merged bag (view over
1466+
// object), so a percent formula's own key counts too.
1467+
if (percentField.percentDisplay !== 'plain') {
1468+
const points = summaryChipPercentPoints(num, percentScale);
1469+
percentValue = Math.max(0, Math.min(100, points));
1470+
}
14621471
}
14631472
} else if (ftype === 'select' || ftype === 'status' || ftype === 'multiselect') {
14641473
// Resolve raw option label from field metadata as
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#36078: the `summaryFields` chip beside the record H1 honours a
11+
* percent field's `percentDisplay` (`@objectstack/spec`, `FieldSchema`):
12+
* `plain` states the percentage alone and draws no bar, for a `percent` field
13+
* and for a `formula` whose `returnType` is `percent`. The key is read off the
14+
* chip's merged field bag, view entry over object schema. Absent or `bar`
15+
* keeps the bar (CONTROL).
16+
*
17+
* ── Directions on the base tree (predicted before the first run) ─────────
18+
* percent field, plain RED (bar drawn)
19+
* percent formula, plain RED (bar drawn)
20+
* object-schema plain, no view entry RED (bar drawn)
21+
* control: absent / bar, field and formula GREEN (bar drawn)
22+
* control: view `bar` over object `plain` GREEN (bar drawn)
23+
*/
24+
25+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
26+
import { render, cleanup, waitFor } from '@testing-library/react';
27+
import * as React from 'react';
28+
import { I18nProvider, LocalizationProvider } from '@object-ui/i18n';
29+
import { DetailView } from '../DetailView';
30+
import type { DetailViewSchema, FieldMetadata } from '@object-ui/types';
31+
32+
/**
33+
* `useRecordEditable` falls back to the GLOBAL fetch with no
34+
* `SchemaRendererProvider` in the tree; served from a double so no case here
35+
* depends on the network (the stub `summaryChip.currencyMode-10422` uses).
36+
*/
37+
beforeEach(() => {
38+
vi.stubGlobal(
39+
'fetch',
40+
vi.fn(async () => ({ ok: true, json: async () => ({ record: { visible: true } }) })),
41+
);
42+
});
43+
afterEach(() => {
44+
vi.unstubAllGlobals();
45+
cleanup();
46+
});
47+
48+
/**
49+
* Renders a page whose summary chips are `kpi`, stored as `0.4`, and
50+
* `region`, the ARRIVAL PROBE: it has no view entry, so its accessible name
51+
* reads `Region: EMEA` only once the object schema below has landed.
52+
*/
53+
function renderPage(
54+
viewField: Record<string, unknown> | null,
55+
objectSchema?: Record<string, unknown>,
56+
): HTMLElement {
57+
const dataSource = objectSchema
58+
? ({ getObjectSchema: async () => objectSchema } as any)
59+
: undefined;
60+
return render(
61+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }} persistLanguage={false}>
62+
<LocalizationProvider value={{ locale: 'en', currency: 'USD' }}>
63+
<DetailView
64+
dataSource={dataSource}
65+
schema={
66+
{
67+
type: 'record:details',
68+
objectName: 'opportunity',
69+
summaryFields: ['kpi', 'region'],
70+
fields: viewField ? [{ name: 'kpi', label: 'Probability', ...viewField } as FieldMetadata] : [],
71+
data: { id: 'O1', name: 'Acme renewal', kpi: 0.4, region: 'EMEA' },
72+
} as unknown as DetailViewSchema
73+
}
74+
/>
75+
</LocalizationProvider>
76+
</I18nProvider>,
77+
).container;
78+
}
79+
80+
const requireChip = (c: HTMLElement, field = 'kpi'): HTMLElement => {
81+
const chip = c.querySelector<HTMLElement>(`[data-summary-chip="${field}"]`);
82+
expect(chip, `a summary chip for "${field}" is beside the H1`).not.toBeNull();
83+
return chip!;
84+
};
85+
86+
const OBJECT_PLAIN = {
87+
fields: {
88+
kpi: { type: 'percent', label: 'Probability', percentDisplay: 'plain' },
89+
region: { type: 'text', label: 'Region' },
90+
},
91+
};
92+
93+
const objectSchemaArrived = (c: HTMLElement) =>
94+
waitFor(() =>
95+
expect(requireChip(c, 'region'), 'CONTROL: the object schema arrived').toHaveAccessibleName('Region: EMEA'),
96+
);
97+
98+
const textOf = (el: HTMLElement) => (el.textContent ?? '').replace(/\s+/g, ' ').trim();
99+
100+
/** The chip's bar FILL — the inner span of its decorative track — or null. */
101+
const barFill = (chip: HTMLElement) => chip.querySelector<HTMLElement>('span[aria-hidden] > span');
102+
103+
/** The chip reads `40%` as text alone: no bar track, no fill. */
104+
function expectPlain(chip: HTMLElement) {
105+
expect(textOf(chip)).toBe('40%');
106+
expect(chip).toHaveAccessibleName('Probability: 40%');
107+
expect(chip.querySelector('span[aria-hidden]'), 'no bar track in a plain chip').toBeNull();
108+
}
109+
110+
/** The chip reads `40%` beside a bar filled to 40%. */
111+
function expectBar(chip: HTMLElement) {
112+
expect(textOf(chip)).toBe('40%');
113+
expect(barFill(chip), 'the chip draws its bar').not.toBeNull();
114+
expect(barFill(chip)!.style.width).toBe('40%');
115+
}
116+
117+
const percentFormula = (extra: Record<string, unknown> = {}) => ({
118+
type: 'formula',
119+
returnType: 'percent',
120+
expression: 'record.a',
121+
...extra,
122+
});
123+
124+
describe('the summary chip honours percentDisplay: plain (objectstack#36078)', () => {
125+
it('a percent field set to plain reads 40% with no bar', () => {
126+
expectPlain(requireChip(renderPage({ type: 'percent', percentDisplay: 'plain' })));
127+
});
128+
129+
it('a formula whose returnType is percent, set to plain, reads 40% with no bar', () => {
130+
expectPlain(requireChip(renderPage(percentFormula({ percentDisplay: 'plain' }))));
131+
});
132+
133+
it('plain declared on the object schema alone (no view entry) is read too', async () => {
134+
const container = renderPage(null, OBJECT_PLAIN);
135+
await objectSchemaArrived(container);
136+
expectPlain(requireChip(container));
137+
});
138+
139+
it('CONTROL: a percent field with no percentDisplay draws the bar', () => {
140+
expectBar(requireChip(renderPage({ type: 'percent' })));
141+
});
142+
143+
it('CONTROL: a percent field set to bar draws the bar', () => {
144+
expectBar(requireChip(renderPage({ type: 'percent', percentDisplay: 'bar' })));
145+
});
146+
147+
it('CONTROL: a percent formula with no percentDisplay, and one set to bar, draws the bar', () => {
148+
expectBar(requireChip(renderPage(percentFormula())));
149+
cleanup();
150+
expectBar(requireChip(renderPage(percentFormula({ percentDisplay: 'bar' }))));
151+
});
152+
153+
it('CONTROL: a view entry set to bar wins over an object schema set to plain', async () => {
154+
const container = renderPage({ type: 'percent', percentDisplay: 'bar' }, OBJECT_PLAIN);
155+
await objectSchemaArrived(container);
156+
expectBar(requireChip(container));
157+
});
158+
});

0 commit comments

Comments
 (0)