@micha.bigler/ui-core-micha 3.0.1 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/WORK_ORDERS.md +20 -0
- package/dist/components/charts/ChartFrame.js +42 -27
- package/dist/components/charts/chartDefaults.js +9 -3
- package/docs/CHART-LAYOUT.md +13 -3
- package/package.json +1 -1
- package/scripts/chart-api-census.mjs +407 -0
- package/src/components/charts/ChartFrame.jsx +36 -31
- package/src/components/charts/chartDefaults.js +9 -3
- package/tests/ChartFrame.test.jsx +67 -27
- package/tests/chart-api-census.test.js +366 -0
- package/tests/chartDefaults.test.js +9 -0
- package/work-orders/UCM-CHART-13.md +122 -0
- package/work-orders/UCM-CHART-14.md +198 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { findChartApiUsage, runCensus, TARGET_PROPS } from '../scripts/chart-api-census.mjs';
|
|
6
|
+
|
|
7
|
+
const IMPORT_LINE = "import { BarChart, LineChart, ScatterChart, TimeSeriesChart, ChartFrame } from '@micha.bigler/ui-core-micha';\n";
|
|
8
|
+
|
|
9
|
+
function propsFound(entry) {
|
|
10
|
+
return TARGET_PROPS.filter((p) => entry.props[p]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// UCM-CHART-14: this WO exists because a grep could not see JSX structure. First-round fixtures
|
|
14
|
+
// (below) cover what broke the ad-hoc scans behind this series' wrong consumer counts (see
|
|
15
|
+
// work-orders/UCM-CHART-14.md's own table of six). A second, independent review round (both
|
|
16
|
+
// `reviewer` and `ui_reviewer`) found the FIRST version of this file could itself produce a WRONG,
|
|
17
|
+
// non-UNPARSED answer -- worse than honest UNPARSED -- and that two of these very fixtures did not
|
|
18
|
+
// actually exercise the trap their name claimed. Both are fixed; the second-round traps are in the
|
|
19
|
+
// next describe block. Each fixture asserts the EXACT props found, not just "found something".
|
|
20
|
+
describe('findChartApiUsage -- traps that broke ad-hoc grep scans (UCM-CHART-14)', () => {
|
|
21
|
+
it('trap 1: an arrow function inside a prop value does not truncate the tag at its own "=>"', () => {
|
|
22
|
+
const source = `${IMPORT_LINE}
|
|
23
|
+
function Panel() {
|
|
24
|
+
return (
|
|
25
|
+
<ScatterChart
|
|
26
|
+
getPointStyle={(point) => ({ hollow: point.isStatusQuo, color: point.isStatusQuo ? undefined : '#123' })}
|
|
27
|
+
aspect={1.8}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const [entry] = findChartApiUsage(source);
|
|
33
|
+
expect(entry.component).toBe('ScatterChart');
|
|
34
|
+
expect(entry.unparsed).toBe(false);
|
|
35
|
+
expect(propsFound(entry)).toEqual(['aspect']);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Second-round finding: the original fixture put the comment BETWEEN two already-closed tags
|
|
39
|
+
// (JSX children), never exercising an open tag's own attribute-scan while a comment is active.
|
|
40
|
+
// This version puts both a line comment AND a block comment, each carrying an apostrophe, INSIDE
|
|
41
|
+
// the attribute list itself -- the position that actually needs string/comment tracking to be
|
|
42
|
+
// correct, since a naive apostrophe could be misread as a string-open.
|
|
43
|
+
it('trap 2: an apostrophe inside a comment WITHIN the attribute list does not desynchronise string tracking', () => {
|
|
44
|
+
const source = `${IMPORT_LINE}
|
|
45
|
+
function Panel() {
|
|
46
|
+
return (
|
|
47
|
+
<ChartFrame
|
|
48
|
+
// don't confuse this line comment's apostrophe with a string open
|
|
49
|
+
minHeight={300}
|
|
50
|
+
/* it's a block comment here too */
|
|
51
|
+
title="Body weight"
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
const [entry] = findChartApiUsage(source);
|
|
57
|
+
expect(entry.component).toBe('ChartFrame');
|
|
58
|
+
expect(propsFound(entry)).toEqual(['minHeight']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Second-round finding: the original fixture's nested keys (`angle`/`left`/`top`) were not even
|
|
62
|
+
// in TARGET_PROPS, so a parser that falsely collected ANY nested key would still have passed.
|
|
63
|
+
// This version nests `aspect` and `height` themselves as object keys several levels deep -- the
|
|
64
|
+
// exact prop names the census is looking for -- so a depth-tracking bug that leaks nested keys
|
|
65
|
+
// up as top-level attributes is now something this test can actually catch.
|
|
66
|
+
it('trap 3: nested braces are tracked by depth -- a nested key with a TARGET PROP NAME is never mistaken for a top-level attribute', () => {
|
|
67
|
+
const source = `${IMPORT_LINE}
|
|
68
|
+
function Panel() {
|
|
69
|
+
return (
|
|
70
|
+
<BarChart
|
|
71
|
+
xAxis={[{ scaleType: 'band', tickLabelStyle: { aspect: 'not-real', height: 999 } }]}
|
|
72
|
+
margin={{ top: 8 }}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
const [entry] = findChartApiUsage(source);
|
|
78
|
+
// `margin` IS a top-level attribute (found); the nested `aspect`/`height` keys -- despite being
|
|
79
|
+
// real TARGET_PROPS names -- must never surface as attributes of the tag itself.
|
|
80
|
+
expect(propsFound(entry)).toEqual(['margin']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('trap 4: a prop many lines below the component name is still attributed to the same tag', () => {
|
|
84
|
+
const source = `${IMPORT_LINE}
|
|
85
|
+
function Panel() {
|
|
86
|
+
return (
|
|
87
|
+
<ChartFrame
|
|
88
|
+
title="Body weight"
|
|
89
|
+
subtitle="Last 12 months"
|
|
90
|
+
variant="outlined"
|
|
91
|
+
titleVariant="h6"
|
|
92
|
+
exportOptions
|
|
93
|
+
meta="Updated daily"
|
|
94
|
+
aspect={1.8}
|
|
95
|
+
>
|
|
96
|
+
{children}
|
|
97
|
+
</ChartFrame>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
const [entry] = findChartApiUsage(source);
|
|
102
|
+
expect(entry.component).toBe('ChartFrame');
|
|
103
|
+
expect(propsFound(entry)).toEqual(['aspect']);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Second review round -- the four NEW traps that surfaced against the first version's three-pass
|
|
108
|
+
// design (a raw regex tag-open search with no string/comment context, and no regex-literal
|
|
109
|
+
// tracking at all). All four are wrong-answer risks, not merely UNPARSED risks -- exactly the
|
|
110
|
+
// class of bug this WO's own F1 finding is about (a false measurement nobody flagged).
|
|
111
|
+
describe('findChartApiUsage -- second-round traps: string/comment-blind matching and regex literals', () => {
|
|
112
|
+
it('does not count JSX-looking text inside a STRING literal as a real element', () => {
|
|
113
|
+
const source = `${IMPORT_LINE}
|
|
114
|
+
const example = '<BarChart aspect />';
|
|
115
|
+
function Panel() {
|
|
116
|
+
return <LineChart margin={{ top: 1 }} />;
|
|
117
|
+
}
|
|
118
|
+
`;
|
|
119
|
+
const entries = findChartApiUsage(source);
|
|
120
|
+
expect(entries).toHaveLength(1);
|
|
121
|
+
expect(entries[0].component).toBe('LineChart');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('does not count JSX-looking text inside a LINE comment as a real element', () => {
|
|
125
|
+
const source = `${IMPORT_LINE}
|
|
126
|
+
// <BarChart aspect />
|
|
127
|
+
function Panel() {
|
|
128
|
+
return <LineChart margin={{ top: 1 }} />;
|
|
129
|
+
}
|
|
130
|
+
`;
|
|
131
|
+
const entries = findChartApiUsage(source);
|
|
132
|
+
expect(entries).toHaveLength(1);
|
|
133
|
+
expect(entries[0].component).toBe('LineChart');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('does not count JSX-looking text inside a BLOCK comment as a real element', () => {
|
|
137
|
+
const source = `${IMPORT_LINE}
|
|
138
|
+
/* an old example: <BarChart aspect /> -- removed */
|
|
139
|
+
function Panel() {
|
|
140
|
+
return <LineChart margin={{ top: 1 }} />;
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
const entries = findChartApiUsage(source);
|
|
144
|
+
expect(entries).toHaveLength(1);
|
|
145
|
+
expect(entries[0].component).toBe('LineChart');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// The concrete case found in review: a regex literal's `}`/`>` characters must not be read as
|
|
149
|
+
// real brace/tag-close tokens, or a later real prop on the same tag gets silently dropped.
|
|
150
|
+
it('a regex literal in a prop value does not corrupt brace depth or close the tag early', () => {
|
|
151
|
+
const source = `${IMPORT_LINE}
|
|
152
|
+
function Panel() {
|
|
153
|
+
return (
|
|
154
|
+
<BarChart
|
|
155
|
+
data={/[}>]/}
|
|
156
|
+
aspect={1.8}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
`;
|
|
161
|
+
const [entry] = findChartApiUsage(source);
|
|
162
|
+
expect(entry.unparsed).toBe(false);
|
|
163
|
+
expect(propsFound(entry)).toEqual(['aspect']);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// A component nested INSIDE another target component's own prop expression -- the outer tag's
|
|
167
|
+
// scan must not swallow the inner one, and each must report its OWN props independently.
|
|
168
|
+
it('finds a target component nested inside another target component\'s prop expression', () => {
|
|
169
|
+
const source = `${IMPORT_LINE}
|
|
170
|
+
function Panel() {
|
|
171
|
+
return (
|
|
172
|
+
<ChartFrame minHeight={300} content={<BarChart aspect={1.8} />} />
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
const entries = findChartApiUsage(source);
|
|
177
|
+
const frame = entries.find((e) => e.component === 'ChartFrame');
|
|
178
|
+
const bar = entries.find((e) => e.component === 'BarChart');
|
|
179
|
+
expect(entries).toHaveLength(2);
|
|
180
|
+
expect(propsFound(frame)).toEqual(['minHeight']);
|
|
181
|
+
expect(propsFound(bar)).toEqual(['aspect']);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Regression test for a bug this WO's OWN verification run found (not review, an actual real-
|
|
185
|
+
// world run against hram): the regex-literal heuristic originally included `<`/`>` in the set of
|
|
186
|
+
// characters that can precede a regex-starting `/`. Every JSX CLOSING tag (`</Something>`) has a
|
|
187
|
+
// `/` immediately after a `<` -- so `</ChartFrame>` itself was misread as opening a regex
|
|
188
|
+
// literal, silently corrupting brace depth for the rest of the file and turning every multi-line
|
|
189
|
+
// `<ChartFrame>...</ChartFrame>` usage in the estate into a false UNPARSED. This fixture is
|
|
190
|
+
// shaped like the real file that exposed it: a target component with real JSX children,
|
|
191
|
+
// including an interleaved NON-target component's own closing tag before the target's own.
|
|
192
|
+
it('a target component with real JSX children (own closing tag, and a sibling non-target closing tag) is not corrupted by the </Tag> regex-heuristic bug', () => {
|
|
193
|
+
const source = `${IMPORT_LINE}
|
|
194
|
+
function Panel() {
|
|
195
|
+
return (
|
|
196
|
+
<ChartFrame minHeight={320} toolbar={<Toolbar><Button>Go</Button></Toolbar>}>
|
|
197
|
+
<ScatterChart aspect={1.8}>
|
|
198
|
+
<ScatterReferenceLine from={{ x: 0, y: 0 }} to={{ x: 1, y: 1 }} />
|
|
199
|
+
</ScatterChart>
|
|
200
|
+
</ChartFrame>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
`;
|
|
204
|
+
const entries = findChartApiUsage(source);
|
|
205
|
+
const frame = entries.find((e) => e.component === 'ChartFrame');
|
|
206
|
+
const scatter = entries.find((e) => e.component === 'ScatterChart');
|
|
207
|
+
expect(frame).toBeDefined();
|
|
208
|
+
expect(frame.unparsed).toBe(false);
|
|
209
|
+
expect(propsFound(frame)).toEqual(['minHeight']);
|
|
210
|
+
expect(scatter).toBeDefined();
|
|
211
|
+
expect(scatter.unparsed).toBe(false);
|
|
212
|
+
expect(propsFound(scatter)).toEqual(['aspect']);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('findChartApiUsage -- import resolution and non-traps', () => {
|
|
217
|
+
it('only counts components actually imported from @micha.bigler/ui-core-micha -- a same-named local component is not a consumer', () => {
|
|
218
|
+
const source = `
|
|
219
|
+
import { BarChart } from './my-local-chart';
|
|
220
|
+
function Panel() {
|
|
221
|
+
return <BarChart aspect={1.8} />;
|
|
222
|
+
}
|
|
223
|
+
`;
|
|
224
|
+
expect(findChartApiUsage(source)).toEqual([]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('resolves an aliased import back to its canonical export name', () => {
|
|
228
|
+
const source = `
|
|
229
|
+
import { BarChart as Bar } from '@micha.bigler/ui-core-micha';
|
|
230
|
+
function Panel() {
|
|
231
|
+
return <Bar aspect={1.8} />;
|
|
232
|
+
}
|
|
233
|
+
`;
|
|
234
|
+
const [entry] = findChartApiUsage(source);
|
|
235
|
+
expect(entry.component).toBe('BarChart');
|
|
236
|
+
expect(propsFound(entry)).toEqual(['aspect']);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('reports no elements in a file with no matching import at all (the fast path)', () => {
|
|
240
|
+
expect(findChartApiUsage('const BarChart = 1; const x = <BarChart aspect={1} />;')).toEqual([]);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('reports a boolean-shorthand attribute (no value) the same as a valued one', () => {
|
|
244
|
+
const source = `${IMPORT_LINE}
|
|
245
|
+
const el = <ChartFrame minHeight />;
|
|
246
|
+
`;
|
|
247
|
+
const [entry] = findChartApiUsage(source);
|
|
248
|
+
expect(propsFound(entry)).toEqual(['minHeight']);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('finds a clean element with none of the target props as an entry with an empty prop list', () => {
|
|
252
|
+
const source = `${IMPORT_LINE}
|
|
253
|
+
const el = <BarChart xAxisLabel="Month" series={[]} />;
|
|
254
|
+
`;
|
|
255
|
+
const [entry] = findChartApiUsage(source);
|
|
256
|
+
expect(entry.unparsed).toBe(false);
|
|
257
|
+
expect(propsFound(entry)).toEqual([]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('finds multiple distinct elements in the same file, each with its own props', () => {
|
|
261
|
+
const source = `${IMPORT_LINE}
|
|
262
|
+
const a = <BarChart aspect={1} />;
|
|
263
|
+
const b = <LineChart margin={{ top: 1 }} />;
|
|
264
|
+
`;
|
|
265
|
+
const entries = findChartApiUsage(source);
|
|
266
|
+
expect(entries).toHaveLength(2);
|
|
267
|
+
expect(entries[0].component).toBe('BarChart');
|
|
268
|
+
expect(entries[1].component).toBe('LineChart');
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Definition of Done: "A tag it cannot close is reported as UNPARSED, never skipped and never
|
|
273
|
+
// counted as clean" -- a census that silently drops what it cannot read is the failure it exists
|
|
274
|
+
// to prevent.
|
|
275
|
+
describe('findChartApiUsage -- UNPARSED, never silently skipped', () => {
|
|
276
|
+
it('reports a tag that never closes as UNPARSED rather than dropping it', () => {
|
|
277
|
+
const source = `${IMPORT_LINE}
|
|
278
|
+
const el = <BarChart aspect={1.8} xAxisLabel="Month unterminated
|
|
279
|
+
`; // no closing `>` or `/>` anywhere after this point
|
|
280
|
+
const entries = findChartApiUsage(source);
|
|
281
|
+
expect(entries).toHaveLength(1);
|
|
282
|
+
expect(entries[0].unparsed).toBe(true);
|
|
283
|
+
expect(entries[0].component).toBe('BarChart');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('keeps scanning after an UNPARSED tag and still finds a later, well-formed one', () => {
|
|
287
|
+
// An unmatched `{` (not a string) leaves brace depth permanently elevated but string tracking
|
|
288
|
+
// intact -- so a LATER tag, opening at that same (now-baseline) depth, can still close
|
|
289
|
+
// correctly relative to it. `BarChart` never returns to its own start depth and is UNPARSED;
|
|
290
|
+
// `LineChart` opens and closes entirely within the leaked depth and is found correctly.
|
|
291
|
+
const source = `${IMPORT_LINE}
|
|
292
|
+
const broken = <BarChart aspect={1.8} xAxis={{ scaleType: 'band';
|
|
293
|
+
const el2 = <LineChart margin={{ top: 1 }} />;
|
|
294
|
+
`;
|
|
295
|
+
const entries = findChartApiUsage(source);
|
|
296
|
+
const bar = entries.find((e) => e.component === 'BarChart');
|
|
297
|
+
const lineChart = entries.find((e) => e.component === 'LineChart');
|
|
298
|
+
expect(bar.unparsed).toBe(true);
|
|
299
|
+
expect(lineChart).toBeDefined();
|
|
300
|
+
expect(lineChart.unparsed).toBe(false);
|
|
301
|
+
expect(propsFound(lineChart)).toEqual(['margin']);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// An UNTERMINATED STRING is a genuinely different case from an unmatched brace: nothing can
|
|
305
|
+
// recover from it without guessing where the string was meant to end, so honestly reporting
|
|
306
|
+
// "nothing found after this point" is the correct behaviour, not a bug -- the alternative (the
|
|
307
|
+
// first version of this scanner's per-tag-independent design) would have silently RESYNCHRONISED
|
|
308
|
+
// past a real syntax error, which is exactly the kind of confident-but-wrong answer this WO's
|
|
309
|
+
// second review round exists to rule out.
|
|
310
|
+
it('an unterminated string desyncs the rest of the file -- reported as UNPARSED, not silently resynchronised', () => {
|
|
311
|
+
const source = `${IMPORT_LINE}
|
|
312
|
+
const broken = <BarChart aspect={1.8} xAxisLabel="unterminated;
|
|
313
|
+
const el2 = <LineChart margin={{ top: 1 }} />;
|
|
314
|
+
`;
|
|
315
|
+
const entries = findChartApiUsage(source);
|
|
316
|
+
expect(entries).toHaveLength(1);
|
|
317
|
+
expect(entries[0].component).toBe('BarChart');
|
|
318
|
+
expect(entries[0].unparsed).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe('runCensus -- filesystem walking degrades gracefully (UCM-CHART-14 Risks)', () => {
|
|
323
|
+
let workspaceRoot;
|
|
324
|
+
|
|
325
|
+
afterEach(() => {
|
|
326
|
+
if (workspaceRoot) rmSync(workspaceRoot, { recursive: true, force: true });
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('reports "not present" for a sibling with no frontend/src or src, and never throws', () => {
|
|
330
|
+
workspaceRoot = mkdtempSync(join(tmpdir(), 'ucm-census-'));
|
|
331
|
+
mkdirSync(join(workspaceRoot, 'empty-repo'));
|
|
332
|
+
|
|
333
|
+
const result = runCensus(workspaceRoot);
|
|
334
|
+
const entry = result.apps.find((a) => a.app === 'empty-repo');
|
|
335
|
+
expect(entry.present).toBe(false);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('finds a real usage under frontend/src, and reports a clean sibling with no ucm import as present with zero entries', () => {
|
|
339
|
+
workspaceRoot = mkdtempSync(join(tmpdir(), 'ucm-census-'));
|
|
340
|
+
const appSrc = join(workspaceRoot, 'sample-app', 'frontend', 'src');
|
|
341
|
+
mkdirSync(appSrc, { recursive: true });
|
|
342
|
+
writeFileSync(
|
|
343
|
+
join(appSrc, 'Panel.jsx'),
|
|
344
|
+
`${IMPORT_LINE}\nconst el = <BarChart aspect={1.8} />;\n`,
|
|
345
|
+
);
|
|
346
|
+
mkdirSync(join(workspaceRoot, 'clean-app', 'src'), { recursive: true });
|
|
347
|
+
writeFileSync(join(workspaceRoot, 'clean-app', 'src', 'index.js'), 'export const x = 1;\n');
|
|
348
|
+
|
|
349
|
+
const result = runCensus(workspaceRoot);
|
|
350
|
+
const sample = result.apps.find((a) => a.app === 'sample-app');
|
|
351
|
+
const clean = result.apps.find((a) => a.app === 'clean-app');
|
|
352
|
+
expect(sample.present).toBe(true);
|
|
353
|
+
expect(sample.entries).toHaveLength(1);
|
|
354
|
+
expect(sample.entries[0].props.aspect).toBe(true);
|
|
355
|
+
expect(clean.present).toBe(true);
|
|
356
|
+
expect(clean.entries).toHaveLength(0);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('excludes ui-core-micha itself from the sibling walk by default', () => {
|
|
360
|
+
workspaceRoot = mkdtempSync(join(tmpdir(), 'ucm-census-'));
|
|
361
|
+
mkdirSync(join(workspaceRoot, 'ui-core-micha', 'src'), { recursive: true });
|
|
362
|
+
|
|
363
|
+
const result = runCensus(workspaceRoot);
|
|
364
|
+
expect(result.apps.find((a) => a.app === 'ui-core-micha')).toBeUndefined();
|
|
365
|
+
});
|
|
366
|
+
});
|
|
@@ -292,6 +292,15 @@ describe('removed chart props throw in dev, naming their replacement (UCM-CHART-
|
|
|
292
292
|
.toThrow(/BarChart.*minHeight.*Use size instead\./s);
|
|
293
293
|
});
|
|
294
294
|
|
|
295
|
+
// UCM-CHART-13 (codex review finding): a shared helper hardcoding one WO/version string would
|
|
296
|
+
// misattribute the removal for a different call site's own, different removal.
|
|
297
|
+
it('defaults removedIn to UCM-CHART-12/v3.0.0 (the four presets\' own call sites), but a caller can override it', () => {
|
|
298
|
+
expect(() => assertRemovedChartProp('BarChart', 'minHeight', 320, 'Use size instead.'))
|
|
299
|
+
.toThrow(/UCM-CHART-12, v3\.0\.0/);
|
|
300
|
+
expect(() => assertRemovedChartProp('ChartFrame', 'aspect', 1.8, 'Use size instead.', 'UCM-CHART-13, v3.1.0'))
|
|
301
|
+
.toThrow(/UCM-CHART-13, v3\.1\.0/);
|
|
302
|
+
});
|
|
303
|
+
|
|
295
304
|
it('assertRemovedChartProp stays inert in production', () => {
|
|
296
305
|
const original = process.env.NODE_ENV;
|
|
297
306
|
process.env.NODE_ENV = 'production';
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# UCM-CHART-13 — A card has no size of its own. Remove `height` and `aspect` from `ChartFrame`.
|
|
2
|
+
|
|
3
|
+
- **Repo:** `ui-core-micha`, branch `main`
|
|
4
|
+
- **Tier:** 3 — shared-core API removal, **four measured consumer call sites** (see below). Breaking:
|
|
5
|
+
`4.0.0`, sequenced with `FM-CHART-1`.
|
|
6
|
+
- **Status:** planned
|
|
7
|
+
- **Workstream:** `CHART-*`
|
|
8
|
+
- **Files:** `src/components/charts/ChartFrame.jsx` and its tests.
|
|
9
|
+
|
|
10
|
+
> **Why. Twice reversed — the reasoning below is what settled it, not the earlier prop-inventory.**
|
|
11
|
+
>
|
|
12
|
+
> Draft 1 said remove `height` **and** `aspect`, on the grounds that both were dead code. That
|
|
13
|
+
> premise was wrong: `aspect` **is** applied — `ChartFrame.jsx:136-139` sets
|
|
14
|
+
> `sx={{ width: '100%', minHeight, aspectRatio: aspect, ... }}`.
|
|
15
|
+
>
|
|
16
|
+
> Draft 2 therefore kept `aspect`. **That was the worse error**, and the operator caught it: it
|
|
17
|
+
> reintroduces through the card exactly what `UCM-CHART-12` removed from the chart.
|
|
18
|
+
>
|
|
19
|
+
> **The structural argument, which neither earlier draft made.** After the migration a consumer
|
|
20
|
+
> looks like this:
|
|
21
|
+
>
|
|
22
|
+
> ```jsx
|
|
23
|
+
> <ChartFrame minHeight={320} aspect="960 / 380"> // height derived from WIDTH
|
|
24
|
+
> <LineChart size="tall" /> // height from a TOKEN
|
|
25
|
+
> </ChartFrame>
|
|
26
|
+
> ```
|
|
27
|
+
>
|
|
28
|
+
> **Two independent size sources for nested boxes that have to agree.** Before the migration they
|
|
29
|
+
> were coherent — same ratio on both. Afterwards the frame tracks width and the chart tracks a token,
|
|
30
|
+
> and they coincide only by accident. Whichever way they diverge is a defect this series already has
|
|
31
|
+
> a name for: the frame taller than its content is dead space, the frame shorter is the
|
|
32
|
+
> `UCM-CHART-9` overflow.
|
|
33
|
+
>
|
|
34
|
+
> **A card must have no size of its own.** Its height is its content's height, with `minHeight` as a
|
|
35
|
+
> floor so an empty or loading state does not collapse. That is what `UCM-CHART-9` established — it
|
|
36
|
+
> found the defect at a fixed `height`; `aspect` is the same defect derived from width instead of
|
|
37
|
+
> stated directly.
|
|
38
|
+
>
|
|
39
|
+
> | prop | applied today | verdict |
|
|
40
|
+
> |---|---|---|
|
|
41
|
+
> | `minHeight` | yes (`:138`) | **stays** — the floor, and the only legitimate one |
|
|
42
|
+
> | `aspect` | yes (`:139`) | **goes** — a second size source on a box that must follow its content |
|
|
43
|
+
> | `height` | no — only feeds a warning | **goes** — accepted and silently ignored |
|
|
44
|
+
>
|
|
45
|
+
> **This one has consumer impact**, unlike draft 2's claim: four `ChartFrame`s pass `aspect` —
|
|
46
|
+
> `fitness-monitor/BodyHistoryPage.jsx:328, :449` and `EnvironmentPage.jsx:250, :284`. They are
|
|
47
|
+
> migrated by `FM-CHART-1`, not here.
|
|
48
|
+
|
|
49
|
+
## Part A — Envelope (authoritative WHAT/WHY)
|
|
50
|
+
|
|
51
|
+
### Goal
|
|
52
|
+
|
|
53
|
+
`ChartFrame` has no size source of its own. Its height is its content's height, floored by
|
|
54
|
+
`minHeight`. `aspect` and `height` are gone.
|
|
55
|
+
|
|
56
|
+
### Definition of Done
|
|
57
|
+
|
|
58
|
+
- [ ] **`aspect` removed** from the signature and from the applied `sx` (`:139`). A card that sizes
|
|
59
|
+
itself from its width can be shorter than its content (the `UCM-CHART-9` overflow) or taller
|
|
60
|
+
(dead space); both are defects this series already has names for.
|
|
61
|
+
- [ ] **`height` removed** from `ChartFrame`'s signature, and `warnOnChartFrameHeightMismatch` deleted
|
|
62
|
+
with it — the warning exists only to explain a prop that should not be accepted in the first
|
|
63
|
+
place. **A prop that is accepted and silently ignored is worse than one that errors**: it lets a
|
|
64
|
+
caller believe the card was sized when it was not, which is precisely the `UCM-CHART-9`
|
|
65
|
+
regression in slow motion.
|
|
66
|
+
- [ ] **`minHeight` stays, unchanged.** It is the one justified prop: a card with a loading or empty
|
|
67
|
+
state would otherwise collapse, and `UCM-CHART-9` established the floor as correct. Do not
|
|
68
|
+
touch its behaviour.
|
|
69
|
+
- [ ] **Passing `height` or `aspect` to `ChartFrame` is a dev-mode error naming what to do instead**
|
|
70
|
+
— `minHeight` for a floor, or `size` on the chart *inside* the frame if the caller meant the
|
|
71
|
+
chart's height. Consistent with how `UCM-CHART-12` treats the presets' removed props.
|
|
72
|
+
- [ ] **`docs/CHART-LAYOUT.md`'s "What stays unchanged" entry is made precise.** It lists the frame's
|
|
73
|
+
`minHeight`/`height`/`aspect` as retained without saying which are applied. Replace it: the frame
|
|
74
|
+
keeps **`minHeight` only**, as a floor; it has no size source of its own, and a chart's height
|
|
75
|
+
comes from its `size` token.
|
|
76
|
+
|
|
77
|
+
### Non-goals
|
|
78
|
+
|
|
79
|
+
- Do not change `minHeight`'s semantics, and do not give `ChartFrame` a `size` token. The frame is
|
|
80
|
+
not a chart (`UCM-CHART-9`); its height follows its content with a floor, and that is correct.
|
|
81
|
+
- Do not touch the four presets. `UCM-CHART-12` settled them.
|
|
82
|
+
- No consumer migration here. The four `ChartFrame`s passing `aspect` are fitness-monitor's, and
|
|
83
|
+
`FM-CHART-1` removes them — **sequence this after `FM-CHART-1`, or land both together**, or those
|
|
84
|
+
four cards hit the new error.
|
|
85
|
+
|
|
86
|
+
### Risks
|
|
87
|
+
|
|
88
|
+
- **`height` is free — no consumer passes it and it does nothing.** `aspect` is not: four cards
|
|
89
|
+
depend on it and lose their shape when it goes. That is intended (their height becomes their
|
|
90
|
+
content's), but it is a **visible change in fitness-monitor**, so `FM-CHART-1`'s rendered two-width
|
|
91
|
+
check is what confirms it, not this WO's unit tests.
|
|
92
|
+
- **Re-run the consumer scan by reading the call sites, not by grepping.** Both earlier drafts of this
|
|
93
|
+
WO were wrong about `aspect` — once from a grep that matched nothing, once from a `head`-truncated
|
|
94
|
+
grep that cut off the line where it is applied. Open the files.
|
|
95
|
+
|
|
96
|
+
### Tests to WRITE — narrow
|
|
97
|
+
|
|
98
|
+
- `ChartFrame` with `minHeight`: floor applied, `UCM-CHART-9`'s existing assertions unchanged.
|
|
99
|
+
- `ChartFrame` given `height` or `aspect`: dev-mode error naming the replacement, and **no
|
|
100
|
+
`aspectRatio` or `height` on the box**.
|
|
101
|
+
- **A `ChartFrame` whose content is taller than `minHeight` grows to fit** — `UCM-CHART-9`'s
|
|
102
|
+
regression test, unchanged, and now the only thing that decides the card's height.
|
|
103
|
+
- The `UCM-CHART-9` regression test (content taller than the floor grows the box) stays green,
|
|
104
|
+
unchanged.
|
|
105
|
+
|
|
106
|
+
No full suite.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Part B — Implementation map
|
|
111
|
+
|
|
112
|
+
> **TO BE FILLED BY THE ORCHESTRATOR** on `git pull`. Must carry `ChartFrame.jsx`'s signature
|
|
113
|
+
> (`:56-58`), the applied `sx` (`:138`), `warnOnChartFrameHeightMismatch` (`:27-35`), the
|
|
114
|
+
> `docs/CHART-LAYOUT.md` line to correct, the absolute working directory, the progress contract, and
|
|
115
|
+
> the preamble. **Do not dispatch while this placeholder stands.**
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Part C — Orchestrator-only
|
|
120
|
+
|
|
121
|
+
> **TO BE FILLED BY THE ORCHESTRATOR.** Review routing, register maintenance, registry publish
|
|
122
|
+
> verification, commit, and the execution directive with its self-address guard.
|