Skip to content

Commit 5b17215

Browse files
fix(plugin-detail): the record highlights strip draws a boolean as one neutral chip (#27935)
domain:ui#3 · os-bill · session_01Utp6CaJoinvGQSbHeDaWBe <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg4i9JiKjEjwtuVzd4gKy9hB)_ ## 维护者速读 - 改了什么:记录页顶部的「亮点条」(record:highlights)里,布尔字段不再是「是=绿、否=琥珀」两种颜色,统一画成一个中性的小标签,只显示「是 / 否」字样。 - 为什么改:HotCRM 发现「SLA 已违约:否」被画成警告色,其实「否」才是好事;元数据并没有说哪个值是好的,详情区本来就只画一个中性的词,亮点条应与它一致。 - 风险与回滚:只改一个渲染分支的样式类,不动数据和元数据;回滚即还原这一个提交。 - 先看:`ui/packages/plugin-detail/src/HeaderHighlight.tsx` 布尔分支;`HeaderHighlight.booleanNeutral-27434.test.tsx`。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/plugin-detail/src/__tests__/HeaderHighlight.booleanNeutral-27434.test.tsx`,预期 3 个用例全绿。 - 需要你做的:无,席位落地。 Fixes #27434 Clause-②: no Metadata-protocol: none ## What changes Card #27434 lists seven gaps HotCRM measured on 18.2.0. Each row was re-measured on `main` at e41642d. This PR takes row 4; the other rows are answered below, and the rows that need a new key, a spec change or a change outside `ui/` go to cards of their own, now filed by the seat: #27944 (row 2), #27945 (row 3), #27946 (row 5), #27947 (row 6) and #27948 (rows 7 and 1). With every row taken or carded, this PR closes the card. **Row 4 (taken).** `HeaderHighlight` drew a boolean `true` as an emerald "✓ Yes" chip and `false` as an amber "× No" chip, whatever the field means. Both values now share one neutral chip (`bg-muted`, `text-foreground`, `ring-border`), carrying the locale's Yes / No word from `useBooleanValueLabel` and no glyph. That matches the details body, which draws the same read-only field as the plain word. The now-unused `Check` and `X` icon imports are dropped. A field-level key that says which value is the bad one is not invented here: that is a spec question (see Acceptance notes). | Row | Bucket | Reading on `main` | |---|---|---| | 1 | Already done; the residual joins row 7 | The row reaches the dialog from both doors. The record header (`page:header` `dispatchHeaderAction`) and a list row's menu (`objectGridActionsColumn`) both stash it under `params._rowRecord`. Both param-collection handlers seed `defaultFromRow` from it (by the param's `field`, else its `name`). The runner's `interpolate` fills `${record.x}` in `description` and `helpText` on both doors (objectui#12967, shipped in 18.0.0). What prints raw is a `{{ record.x }}` hole. Measured through the runner: `Email {{ record.display_name }} / ${record.display_name}` reads `Email {{ record.display_name }} / Acme` from both doors. That is the hole-syntax split of row 7. | | 2 | Card (spec + ui) | No action key names the dialog's submit verb; the footer reads `actionDialog.confirm`. | | 3 | Card (spec + form) | A form has no lookup-pick autofill. The only one is the line-item grid column's `autofill`, which copies same-named fields and exists only in that grid. | | 4 | Taken here | See above. | | 5 | Card (spec) | `ActionSchema` has no per-reader `active` / `pressed` predicate. | | 6 | Card (server) | `resolveRef` in the import runner (`@objectstack/core`) still tries `id`, `displayField`, the title field, then `name`/`title`/`label`/`full_name`/`email`/`username`. It never tries the target's `unique` fields. | | 7 | Card (spec + runtime), with row 1's residual | `composeSuccessMessage` fills `outcomeMessages` through `substituteScopeTokens` (`${result.x}`), and `successMessage` through `fillTemplateHoles` (`{{ }}`). The param dialog's `description` and `helpText` read `${…}` through the evaluator. `confirmText` reads `{{ }}`, and the spec tells an author with params to move the confirm question onto `description`, where the same `{{ record.x }}` hole stops filling. | ## Tests - New `HeaderHighlight.booleanNeutral-27434.test.tsx` (3 cases): neither chip carries a state colour class or a glyph; the `true` and `false` chips share one class list and differ only by the word; a control that the strip drew its non-boolean value. - Ablation, run twice against the committed fix and restored from `HEAD` each time (`git hash-object` matched the HEAD blob after both): - The file restored to `origin/main`: 2 of 3 cases red. - Through `scripts/ablation-replace.mjs`, `rounded-full bg-muted px-2` replaced by `rounded-full bg-amber-500/10 px-2` (anchor 1 to 0, blob changed): case 1 red. - Every `plugin-detail` highlights, record page and summary-chip test file (22 files; `HeaderHighlight.booleanLocale-11689` included): 21 passed, 1 skipped, 177 tests passed. - `@object-ui/plugin-detail` `type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`): exit 0. ## Acceptance notes - Row 4's "a field-level key saying which value is the bad one" is the spec half of that row. It is not built here; the neutral default is what the details body already does. - Out of scope, for the seat to file as cards: rows 2, 3, 5 and 6, and row 7 together with row 1's `{{ }}` residual. Titles, bodies, landing sites and dedupe words are in the os-dev report on #27434. - No i18n string changed: the chip reads the existing `useBooleanValueLabel` words. ## Verification Each command was run on 189ad8a, with its exit code captured before any pipe. The derived gate list was reconciled with `dispatch-gates --ran`; the full list is in the report on #27434. Co-authored-by: Claude <noreply@anthropic.com>
1 parent dd9921e commit 5b17215

3 files changed

Lines changed: 104 additions & 12 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 highlights strip draws a boolean as one neutral chip, as the details body does
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The `record:highlights` strip drew `true` as a green "✓ Yes" chip and `false` as a warning-toned "× No" chip, whatever the field meant, so a case's "SLA Violated: No" read as a warning. The metadata does not say which value is the good one, and the details body draws the same field as a plain word, so both values now share one neutral chip: the locale's Yes / No word, with no state colour and no glyph.

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { usePermissions } from '@object-ui/permissions';
2222
import { getCellRenderer, resolveCellRendererType, useBooleanValueLabel } from '@object-ui/fields';
2323
import { useSafeFieldLabel, useInlineEdit, usePredicateScope } from '@object-ui/react';
2424
import { useObjectTranslation, pickLocalized } from '@object-ui/i18n';
25-
import { Check, X, Pencil } from 'lucide-react';
25+
import { Pencil } from 'lucide-react';
2626
import { InlineFieldInput } from './InlineFieldInput';
2727
import {
2828
enrichDetailField,
@@ -402,17 +402,16 @@ export const HeaderHighlight: React.FC<HeaderHighlightProps> = ({
402402
>
403403
<div className="min-w-0 flex-1">
404404
{isBoolean ? (
405-
value ? (
406-
<span className="inline-flex items-center gap-1 self-start rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-600 ring-1 ring-inset ring-emerald-500/30 dark:text-emerald-400">
407-
<Check className="h-3 w-3" aria-hidden />
408-
{booleanLabel(true)}
409-
</span>
410-
) : (
411-
<span className="inline-flex items-center gap-1 self-start rounded-full bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-inset ring-amber-500/30 dark:text-amber-400">
412-
<X className="h-3 w-3" aria-hidden />
413-
{booleanLabel(false)}
414-
</span>
415-
)
405+
// One neutral chip for both values, as the details body
406+
// draws the same field (a plain word): the metadata does
407+
// not say which value is the good one, so neither may
408+
// wear a success or a warning colour.
409+
<span
410+
className="inline-flex items-center self-start rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-foreground ring-1 ring-inset ring-border"
411+
data-boolean-chip=""
412+
>
413+
{booleanLabel(!!value)}
414+
</span>
416415
) : isEmpty ? (
417416
// The SHARED placeholder (objectui#8506). This span
418417
// spelled its own em-dash and resolved its own
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
* The highlights strip draws a boolean neutrally (objectstack#27434, row 4).
11+
*
12+
* The strip coloured `true` as a green "✓ Yes" and `false` as a warning-toned
13+
* "× No", whatever the field means, so a case's "SLA Violated: No" wore the
14+
* warning colour. The metadata does not say which value is the good one, and
15+
* the details body draws the same field as a plain word, so the strip's chip
16+
* is one neutral face for both values: the same classes, no state colour, no
17+
* glyph.
18+
*/
19+
import { describe, it, expect, afterEach } from 'vitest';
20+
import { render, screen, cleanup } from '@testing-library/react';
21+
import * as React from 'react';
22+
import { HeaderHighlight } from '../HeaderHighlight';
23+
24+
afterEach(cleanup);
25+
26+
const objectSchema = {
27+
fields: {
28+
subject: { type: 'text', label: 'Subject' },
29+
is_sla_violated: { type: 'boolean', label: 'SLA Violated' },
30+
is_escalated: { type: 'boolean', label: 'Escalated' },
31+
},
32+
};
33+
34+
function renderStrip() {
35+
render(
36+
<HeaderHighlight
37+
fields={
38+
[
39+
{ name: 'subject', label: 'Subject' },
40+
{ name: 'is_sla_violated', label: 'SLA Violated' },
41+
{ name: 'is_escalated', label: 'Escalated' },
42+
] as any
43+
}
44+
data={{ subject: 'Login fails', is_sla_violated: false, is_escalated: true }}
45+
objectSchema={objectSchema}
46+
/>,
47+
);
48+
}
49+
50+
/** The chip drawn in a column, anchored on the field LABEL. */
51+
const chipOf = (label: string) => {
52+
const column = screen.getByText(label).parentElement as HTMLElement;
53+
const chip = column.querySelector('[data-boolean-chip]');
54+
expect(chip, `a boolean chip under "${label}"`).not.toBeNull();
55+
return chip as HTMLElement;
56+
};
57+
58+
const STATE_COLOUR = /\b(?:bg|text|ring)-(?:emerald|green|amber|red|yellow|orange|destructive|success|warning)\b/;
59+
60+
describe('the highlights strip draws a boolean neutrally (objectstack#27434)', () => {
61+
it('`false` wears no warning colour and `true` no success colour', () => {
62+
renderStrip();
63+
for (const label of ['SLA Violated', 'Escalated']) {
64+
const chip = chipOf(label);
65+
expect(chip.className).not.toMatch(STATE_COLOUR);
66+
expect(chip.querySelector('svg')).toBeNull();
67+
}
68+
});
69+
70+
it('both values share one face: only the word differs', () => {
71+
renderStrip();
72+
const no = chipOf('SLA Violated');
73+
const yes = chipOf('Escalated');
74+
expect(no.className).toBe(yes.className);
75+
expect(no.textContent).toBe('No');
76+
expect(yes.textContent).toBe('Yes');
77+
});
78+
79+
it('CONTROL: the strip drew its non-boolean value too', () => {
80+
renderStrip();
81+
expect(screen.getByText('Login fails')).toBeTruthy();
82+
});
83+
});

0 commit comments

Comments
 (0)