Skip to content

Commit 896bfc4

Browse files
fix(plugin-dashboard): draw a declared gap: 0 with no gap (#37059)
Fixes #36912 Clause-②: no Metadata-protocol: none ## 维护者速读 - 搭仪表盘的人在仪表盘里写了组件间距为零后,卡片现在会紧贴着画出来,以前仍隔着一段默认间距;没写间距的仪表盘不变。 - 属于仪表盘渲染的修正:规范允许间距为零,渲染器却把零当成没写。 - 出错时只是卡片之间的空隙不对,不丢数据,可以直接撤回。 - 无 ## What changes `ui/packages/plugin-dashboard/src/DashboardRenderer.tsx` read the declared gap as `schema.gap || 4`, so a declared `gap: 0` (legal: `gap: z.number().int().min(0).optional()`, `packages/spec/src/ui/dashboard.zod.ts`) fell through to the default 4 (1rem). It now reads `schema.gap ?? 4`; only an absent `gap` takes the default. Every reader of the declared gap in `@object-ui/plugin-dashboard`, read at `b01d8f97`: - `DashboardRenderer.tsx` line 409, `const gap = schema.gap || 4` - the only reader of `schema.gap`; fixed here. - `DashboardRenderer.tsx` `gapPx={gap * 4}` on the design-mode resize handle - derives from the same `gap` constant, so it now sees the declared zero too; no `||` of its own. - `DashboardRenderer.tsx` desktop grid root `gap: gap * 0.25 rem` inline style - derives from the same constant; this is what the test reads. - The mobile body (`flex flex-col gap-4`, metric grid `gap-3`) does not read `schema.gap` at all: fixed Tailwind classes, no `||`, unchanged. Noted below. - `index.tsx` declares `{ name: 'gap', type: 'number' }` as a block input; `DashboardConfigPanel.tsx` edits it. Neither defaults it. ## Live observation The issue asks for a live measurement first. A browser on a dev server needs a full monorepo build plus the Console build in a container shared with two sibling dev agents, where each verify-lock call already queued 4 to 9 minutes; I judged that impractical here and took the reading the dispatch allows instead: the real `DashboardRenderer`, rendered by the new test, reading the grid root's inline `gap` style. | schema | before (`b01d8f97` renderer) | after | |:---|:---|:---| | `gap: 0` | `1rem` (test red: Expected "0rem", Received "1rem") | `0rem` | | `gap` absent | `1rem` | `1rem` | | `gap: 2` | `0.5rem` | `0.5rem` | ## Tests New `ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.gapZero-36912.test.tsx`: renders `gap: 0` and asserts the grid root's style `gap` is `0rem`, with the absent-`gap` control (`1rem`) and a non-zero case (`0.5rem`). It was committed before the fix and run red against the unfixed renderer (1 failed, 2 passed), then green after (3 passed). ## Acceptance notes - The mobile layout ignores the declared `gap` entirely (fixed `gap-4` / `gap-3`). That is the phone layout's own spacing, not a `||` reader, and outside this card; not filed. - Outside this package, `ui/packages/components/src/renderers/action/action-bar.tsx` reads `schema.gap || 'gap-2'`, but its `gap` is a class string, where only an empty string falls through; not the same defect, not filed. ## Verification Two-minute check: `cd ui/packages/plugin-dashboard && pnpm exec vitest run --root ../.. packages/plugin-dashboard/src/__tests__/DashboardRenderer.gapZero-36912.test.tsx` - expect 3 passed; revert line 409 to `||` and the `gap: 0` case reads `1rem`. Read first: `DashboardRenderer.tsx` around line 409 (the one-line change), then the new test. <details><summary>Local readings at 282baba</summary> - `@object-ui/plugin-dashboard` tests: Test Files 217 passed (217), Tests 2100 passed, 6 skipped (2106), TEST_EXIT=0. - `@object-ui/plugin-dashboard` type-check (turbo, with its dependency builds): Tasks 54 successful, 54 total; lock VERDICT command-exit 0. - `pnpm --dir ui exec vitest run scripts/`: Test Files 172 passed, 2 skipped (174); Tests 5129 passed, 2 skipped; VERDICT command-exit 0. - `dispatch-gates --commands` derived 38 families on this diff; all 38 exited 0; `--ran` reconciliation: 38 run, 0 NOT-MEASURED (a derived zero). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 67154ed commit 896bfc4

3 files changed

Lines changed: 72 additions & 1 deletion

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-dashboard': patch
3+
---
4+
5+
fix(plugin-dashboard): a dashboard that declares `gap: 0` is drawn with no gap
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The dashboard renderer read the declared `gap` as `schema.gap || 4`, so a declared `gap: 0`, which the spec admits (`min(0)`), fell through to the default and widgets an author wanted flush were drawn 1rem apart. It now reads `schema.gap ?? 4`: only an absent `gap` takes the default of 4 (1rem), and a declared zero draws the grid with no gap. The design-mode resize handle, which measures a span from the same gap, uses the declared zero too.

‎ui/packages/plugin-dashboard/src/DashboardRenderer.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ const DashboardRendererInner = forwardRef<HTMLDivElement, DashboardRendererProps
406406
return 4;
407407
})();
408408
const columns = inferredColumns;
409-
const gap = schema.gap || 4;
409+
// The spec admits `gap: 0` (`min(0)`), so only an ABSENT gap takes the
410+
// default; `||` drew a declared zero 1rem apart (objectstack#36912).
411+
const gap = schema.gap ?? 4;
410412
// Positioned (explicit-columns) grid vs responsive auto-flow grid.
411413
// Defined here (not just above desktopBody) so renderWidget can give
412414
// layout-less widgets a sensible default span in the positioned grid.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
* A declared `gap: 0` draws no gap (objectstack#36912).
11+
*
12+
* The spec admits zero (`gap: z.number().int().min(0).optional()`,
13+
* `packages/spec/src/ui/dashboard.zod.ts`), so only an ABSENT `gap` takes the
14+
* default of 4. The renderer used to read `schema.gap || 4`, which sent a
15+
* declared zero to the default too: widgets an author wanted flush were drawn
16+
* 1rem apart. These cases read the grid root's inline `gap` style by
17+
* rendering, with the absent-`gap` control beside the zero case so a renderer
18+
* that ignored `gap` altogether is red as well.
19+
*/
20+
21+
import { describe, it, expect, afterEach } from 'vitest';
22+
import { render, cleanup } from '@testing-library/react';
23+
import type { DashboardComponentSchema } from '@object-ui/types';
24+
import { DashboardRenderer } from '../DashboardRenderer';
25+
26+
afterEach(cleanup);
27+
28+
function dashboard(extra: Record<string, unknown> = {}): DashboardComponentSchema {
29+
return {
30+
type: 'dashboard',
31+
name: 'ops',
32+
label: 'Operations',
33+
columns: 12,
34+
widgets: [],
35+
...extra,
36+
} as unknown as DashboardComponentSchema;
37+
}
38+
39+
/** The inline `gap` style on the dashboard's grid root. */
40+
function rootGap(schema: DashboardComponentSchema): string {
41+
const { container } = render(<DashboardRenderer schema={schema} />);
42+
const root = container.firstElementChild as HTMLElement | null;
43+
if (!root) throw new Error('the dashboard rendered no root element');
44+
return root.style.gap;
45+
}
46+
47+
describe('DashboardRenderer declared gap (objectstack#36912)', () => {
48+
it('draws a declared gap: 0 as no gap', () => {
49+
expect(rootGap(dashboard({ gap: 0 }))).toBe('0rem');
50+
});
51+
52+
it('draws the default gap (4 = 1rem) only when gap is absent', () => {
53+
expect(rootGap(dashboard())).toBe('1rem');
54+
});
55+
56+
it('draws a declared non-zero gap in 0.25rem steps', () => {
57+
expect(rootGap(dashboard({ gap: 2 }))).toBe('0.5rem');
58+
});
59+
});

0 commit comments

Comments
 (0)