Skip to content

Commit 994c7d6

Browse files
fix(app-shell): the approval request's "As submitted" summary draws the submitted file fields, and each file opens (#32963)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoShPRwR7m6qzdXdZvptvrJg)_ Fixes #32854 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:审批申请页「提交时的内容」现在会画出提交时的附件字段(`file` 单个与多个、`image`、`avatar`、`video`、`audio`),每个文件是可点开的链接,图片是可点开的缩略图;其余对象/列表型字段(地址、位置、json、多选、多值引用等)按一条写明的规则继续不画。 - **为什么改**:原来所有对象或数组值一律跳过,报销单的「电子发票」(多文件字段)在审批页看不到,审批人看不到自己要批的发票。 - **风险与回滚**:只改前端一个摘要组件,不改服务端、不加下载通道(链接走平台已有的 `/api/v1/storage/files/ID`,权限由该端点自己判);附件行不占 6 行上限。回滚即 revert 本 PR。 - **先看**:`snapshotSummaryPlan.ts`(附件分支在对象跳过之前)、`RecordSnapshotSummary.tsx`(头注释里的规则与附件区块)、`RecordSnapshotSummary.test.tsx`(新增 pin)。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/app-shell/src/views/approval-decision/RecordSnapshotSummary.test.tsx`,预期 36/36 通过;或打开一张带电子发票的报销审批,「提交时的内容」下方出现「电子发票」及每个文件的链接。 - **需要你做的**:无,席位落地。 - **席位意见**:席位(domain:ui#4)审过。附件类字段(文件、图片、头像、音视频)用记录页同一个字段单元格画出,打开走平台已有的下载接口,由接口判权限,没有新增下载通道;不占 6 行上限。其它对象或列表值按 PR 写明的规则不画,审批人点开记录可看全。只改审批页摘要,不碰服务端,没有新增文案键。CI 全绿后按队列落地。 ## What changes `planSnapshotSummary` gains an `attachments` list. A declared field whose type is in the spec's media family `FILE_REFERENCE_TYPES` (imported from `@objectstack/spec/data`, not copied) is routed there before the object/list skip, when it holds a file. `RecordSnapshotSummary` draws those fields full width after the business rows, under the same "As submitted" heading, each through the field's own cell (`getCellRenderer`, the record page's face): `FileCellRenderer` for `file` / `video` / `audio`, `ImageCellRenderer` for `image` / `avatar`. No new widget, no new download channel, no server change; `ui/packages/fields/**` is read only. ### The rule: object and list values, kind by kind | Kind | Drawn? | How / why | |---|---|---| | `file`, `multiple: true` | drawn | one link per file, each opening the platform download endpoint (`FileValueAffordance`, `target=_blank`) | | `file`, single | drawn | one link that opens the file; a stored bare id already passed the old skip as a grid row, it now moves to the attachment block | | `image`, `avatar` | drawn | thumbnail from the download endpoint; a click opens the image lightbox (the record page's cell) | | `video`, `audio` | drawn | same link face as `file` (the registry maps them to `FileCellRenderer`) | | any of the above, empty (`null`, blank id, empty list, empty object) | left out | nothing was submitted; the scalar rule's "empty gets no row" applied to attachments | | `address`, `location` / `geolocation` | left out | a multi-line block or a map; a one-line glance row would cut it | | `json` / `object`, `composite`, `record`, `repeater`, `grid`, `vector` | left out | structured faces (key lists, tables) that a glance row cannot hold | | `multiselect`, `checkboxes`, `tags` (list values) | left out | a chip list a truncated row would cut; the record shows it whole | | multi-value reference (`lookup` / `user` with `multiple`) | left out | a list of record ids, a chip list a truncated row would cut; the record shows it whole | | any other object or list value | left out | the rule is by value shape: only the media family is drawn | **Row cap:** attachments are not counted against `SNAPSHOT_SUMMARY_ROWS` (6) and are never cut by it, because the attachment is what the approver decides on. The lead and the six business rows are chosen exactly as before. Every existing filter still applies first: undeclared keys, `hidden: true`, framework-managed columns, and fields the reader may not read (`withoutDeniedFields`) get no attachment row. **What the snapshot holds (measured):** the approvals service stores the flow's `$record` (the engine's write result, file fields in stored form, the bare `sys_file` id) and serves it redacted per reader, with no file expansion. `readFileValue` turns a bare id into `/api/v1/storage/files/ID`, the stable endpoint that judges access and redirects to a signed URL, and reads the expanded `{ id, name, url }` and refused `{ id, metadataRefused }` forms too. So the value carries what opening needs; no server change. ## Why The plan skipped every object or array value (`value == null || typeof value === 'object'`), and a multi-file field's value is an array, so the e-invoices field never showed on the approval page while the same claim's own page showed both files. ## Tests `RecordSnapshotSummary.test.tsx`, new blocks `planSnapshotSummary: object and list values (objectstack#32854)` and `RecordSnapshotSummary: attachments are drawn and open (objectstack#32854)`: - `multiple` file: each file drawn as a link with the download href and `target=_blank`, after the five business rows, outside a cap of 2 in the plan pin, never the lead. - single file (stored id and expanded form), `image`, `avatar`, `video`, `audio`: one pin each (plan + render). - CONTROL: address, location, json, multiselect and a multi-value lookup stay out (plan and render), and the scalar rows are unchanged. - CONTROL: empty, hidden and undeclared attachment fields take no row. - The eight existing plan assertions gained `attachments: []`; their rows, lead and summed values are unchanged. ## Acceptance notes - Ablation (on-disk proof via `scripts/ablation-replace.mjs`, anchor 1 to 0, restored blob equals HEAD): restoring the object skip ahead of the attachment arm turns 8 pins red, every multi-file, expanded-object and list-valued attachment pin; the string-id pins stay green because a bare-id string already passed the old skip as a scalar row. - The surface grep for `ruling|Ruling-ref|maintainer|⛔` hits the summary header's name-guess ban and the two #27502 ruling records (the "As submitted" heading); attachments sit under that same heading, so both hold. - No i18n key added (labels are the declared field labels; the file name fallback is the cell's existing `fields.file.fileFallback`), so Clause-② stays `no`. ## Verification Head `499a94e2` (one `origin/main` merge before opening; nothing merged touches this surface or its dependencies' sources). <details><summary>Tests</summary> - `pnpm --dir ui exec vitest run packages/app-shell/src/views/approval-decision/RecordSnapshotSummary.test.tsx`: 36/36 passed. - Every test that imports the changed modules (6 app-shell files + the console's `servedPageSummary-12483` and `servedPageSummaryAmount-12534`): 8 files, 105/105 passed before the merge; the 6 app-shell files 81/81 after it. - `pnpm --filter @object-ui/app-shell run type-check`: exit 0. - eslint on the three changed source files: exit 0. - `pnpm --dir ui run check:new-line-citations`: 0 new citations. </details> <details><summary>Gates</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 36 families; all 36 ran locally with exit 0, including `node scripts/check-sdui-manifest.mjs` and its `--self-test`, and `pnpm --dir ui exec vitest run scripts/` (171 files passed, 2 skipped). `--ran` reconciliation: 36 derived, 36 run, 0 NOT-MEASURED (a derived zero, every line carries its exit code). The full farm is CI's. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (changed files linted; the repo-wide run is CI's) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (the 维护者速读 section is in Chinese by the dispatch rule) - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibxxCyVEdcKEJFrY3XH)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qibxxCyVEdcKEJFrY3XH <!-- signed: domain:ui#4 · os-tesla · session_01L9qibvZYR36KAJUv44oXZw --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4db1992 commit 994c7d6

4 files changed

Lines changed: 212 additions & 10 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/app-shell': patch
3+
---
4+
5+
fix(app-shell): an approval request's "As submitted" summary draws the submitted file fields, and each file opens
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The summary used to leave out every field whose value is an object or a list, so a `file` field with `multiple: true` (an expense claim's e-invoices) never showed, and the approver could not see the files they were approving. Now a field whose type is in the spec's media family (`file`, single or `multiple`, `image`, `avatar`, `video`, `audio`) is drawn through its own field cell after the business rows: each file is a link to the platform's download endpoint, each image a thumbnail that opens. These attachment rows are not counted against the six-row cap. Every other object or list value (an address, a location, `json`, a composite, a repeater, a multi-value option list or reference) is still left out, by a rule stated in `RecordSnapshotSummary.tsx`'s header. The scalar rows are unchanged.

‎ui/packages/app-shell/src/views/approval-decision/RecordSnapshotSummary.test.tsx‎

Lines changed: 142 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('planSnapshotSummary (objectui#12483)', () => {
4444
FIELDS,
4545
undefined,
4646
);
47-
expect(plan).toEqual({ lead: 'amount', rows: ['name', 'budget'], summed: null });
47+
expect(plan).toEqual({ lead: 'amount', rows: ['name', 'budget'], attachments: [], summed: null });
4848
});
4949

5050
it('a reference the service resolved is a row', () => {
@@ -53,9 +53,9 @@ describe('planSnapshotSummary (objectui#12483)', () => {
5353

5454
it('the first non-zero declared currency leads, else the first declared currency; a name never does', () => {
5555
expect(planSnapshotSummary({ fee: 0, amount: 7 }, FIELDS, undefined).lead).toBe('amount');
56-
expect(planSnapshotSummary({ fee: 0, amount: 0 }, FIELDS, undefined)).toEqual({ lead: 'fee', rows: ['amount'], summed: null });
56+
expect(planSnapshotSummary({ fee: 0, amount: 0 }, FIELDS, undefined)).toEqual({ lead: 'fee', rows: ['amount'], attachments: [], summed: null });
5757
// `budget` is a key the sheet's name guess matches, declared `number`.
58-
expect(planSnapshotSummary({ budget: 900 }, FIELDS, undefined)).toEqual({ lead: null, rows: ['budget'], summed: null });
58+
expect(planSnapshotSummary({ budget: 900 }, FIELDS, undefined)).toEqual({ lead: null, rows: ['budget'], attachments: [], summed: null });
5959
});
6060

6161
it('a hidden field is dropped before the row cut, so the next one takes its slot', () => {
@@ -142,14 +142,14 @@ const OTHER_LINE = { name: 'other_line', fields: { amount: { type: 'currency', l
142142
describe('planSnapshotSummary: a `sum` over a currency field is the amount (objectui#12534)', () => {
143143
it('leads once the summarized definition is given; before, it is a row and the plan names that one object', () => {
144144
expect(planSnapshotSummary({ name: 'N', total: 40 }, ROLLUPS, undefined))
145-
.toEqual({ lead: null, rows: ['name', 'total'], summed: 'line' });
145+
.toEqual({ lead: null, rows: ['name', 'total'], attachments: [], summed: 'line' });
146146
expect(planSnapshotSummary({ name: 'N', total: 40 }, ROLLUPS, undefined, LINE))
147-
.toEqual({ lead: 'total', rows: ['name'], summed: 'line' });
147+
.toEqual({ lead: 'total', rows: ['name'], attachments: [], summed: 'line' });
148148
});
149149

150150
it('CONTROL: a summary that is not a `sum` is a row and asks for no definition', () => {
151151
expect(planSnapshotSummary({ lines: 3, peak: 9 }, ROLLUPS, undefined, LINE))
152-
.toEqual({ lead: null, rows: ['lines', 'peak'], summed: null });
152+
.toEqual({ lead: null, rows: ['lines', 'peak'], attachments: [], summed: null });
153153
});
154154

155155
it('CONTROL: a `sum` over a field the summarized object does not declare `currency` is a row', () => {
@@ -165,7 +165,7 @@ describe('planSnapshotSummary: a `sum` over a currency field is the amount (obje
165165
it('the order is unchanged across both kinds: the first non-zero amount, else the first one', () => {
166166
// A non-zero currency ahead of the roll-up leads, and no definition is asked for.
167167
expect(planSnapshotSummary({ amount: 7, total: 40 }, ROLLUPS, undefined))
168-
.toEqual({ lead: 'amount', rows: ['total'], summed: null });
168+
.toEqual({ lead: 'amount', rows: ['total'], attachments: [], summed: null });
169169
expect(planSnapshotSummary({ amount: 0, total: 40 }, ROLLUPS, undefined, LINE).lead).toBe('total');
170170
expect(planSnapshotSummary({ total: 0, amount: 5 }, ROLLUPS, undefined, LINE).lead).toBe('amount');
171171
expect(planSnapshotSummary({ total: 0, amount: 0 }, ROLLUPS, undefined, LINE).lead).toBe('total');
@@ -175,7 +175,7 @@ describe('planSnapshotSummary: a `sum` over a currency field is the amount (obje
175175

176176
it('only the first `sum`\'s object is read: a `sum` over another object stays a row', () => {
177177
const plan = planSnapshotSummary({ other: 9, total: 40 }, ROLLUPS, undefined, OTHER_LINE);
178-
expect(plan).toEqual({ lead: 'other', rows: ['total'], summed: 'other_line' });
178+
expect(plan).toEqual({ lead: 'other', rows: ['total'], attachments: [], summed: 'other_line' });
179179
expect(planSnapshotSummary({ other: 0, total: 40 }, ROLLUPS, undefined, OTHER_LINE).lead).toBe('other');
180180
});
181181
});
@@ -273,3 +273,137 @@ describe('RecordSnapshotSummary — a declared deadline is judged against the sn
273273
expect(cell?.querySelector('.text-red-600')).not.toBeNull();
274274
});
275275
});
276+
277+
/**
278+
* Object and list values (objectstack#32854): an attachment, a field whose
279+
* type is in the spec's media family `FILE_REFERENCE_TYPES`, is drawn through
280+
* its own cell, openable, after the rows and outside the row cut; every other
281+
* object or list value is left out. The rule is in `RecordSnapshotSummary.tsx`'s
282+
* header.
283+
*/
284+
const ID_A = 'fil_a1b2c3';
285+
const ID_B = 'fil_d4e5f6';
286+
const CLAIM: Record<string, Record<string, unknown>> = {
287+
title: { type: 'text', label: 'Title' },
288+
amount: { type: 'currency', label: 'Amount' },
289+
category: { type: 'text', label: 'Category' },
290+
reason: { type: 'text', label: 'Reason' },
291+
invoice_no: { type: 'text', label: 'Invoice number' },
292+
status: { type: 'text', label: 'Status' },
293+
invoices: { type: 'file', label: 'E-invoices', multiple: true },
294+
receipt: { type: 'file', label: 'Receipt' },
295+
photo: { type: 'image', label: 'Photo' },
296+
badge: { type: 'avatar', label: 'Badge' },
297+
clip: { type: 'video', label: 'Clip' },
298+
memo: { type: 'audio', label: 'Memo' },
299+
private_scan: { type: 'file', label: 'Private scan', hidden: true },
300+
address: { type: 'address', label: 'Address' },
301+
spot: { type: 'location', label: 'Spot' },
302+
extra: { type: 'json', label: 'Extra' },
303+
labels: { type: 'multiselect', label: 'Labels', options: [{ label: 'A', value: 'a' }] },
304+
watchers: { type: 'lookup', reference: 'sys_user', label: 'Watchers', multiple: true },
305+
};
306+
const LEFT_OUT = {
307+
address: { street: '1 Main St', city: 'Springfield' },
308+
spot: { latitude: 1, longitude: 2 },
309+
extra: { a: 1 },
310+
labels: ['a'],
311+
watchers: ['u_1', 'u_2'],
312+
};
313+
314+
describe('planSnapshotSummary: object and list values (objectstack#32854)', () => {
315+
it('a `multiple` file field is an attachment, outside the row cut and never the lead', () => {
316+
const plan = planSnapshotSummary(
317+
{ amount: 120, title: 'Trip', category: 'Travel', reason: 'Visit', invoice_no: 'F-1', status: 'open', invoices: [ID_A, ID_B] },
318+
CLAIM, undefined, null, 2,
319+
);
320+
expect(plan).toEqual({ lead: 'amount', rows: ['title', 'category'], attachments: ['invoices'], summed: null });
321+
});
322+
323+
it.each([
324+
['file (single, stored id)', 'receipt', ID_A],
325+
['file (single, expanded)', 'receipt', { id: ID_A, name: 'r.pdf', url: '/api/v1/storage/files/fil_a1b2c3' }],
326+
['image', 'photo', ID_A],
327+
['avatar', 'badge', ID_A],
328+
['video', 'clip', [ID_A]],
329+
['audio', 'memo', ID_A],
330+
])('a %s field is an attachment', (_kind, key, value) => {
331+
expect(planSnapshotSummary({ title: 'T', [key]: value }, CLAIM, undefined)).toEqual(
332+
{ lead: null, rows: ['title'], attachments: [key], summed: null },
333+
);
334+
});
335+
336+
it('CONTROL: every other object or list value is left out, a row and an attachment alike', () => {
337+
expect(planSnapshotSummary({ title: 'T', ...LEFT_OUT }, CLAIM, undefined)).toEqual(
338+
{ lead: null, rows: ['title'], attachments: [], summed: null },
339+
);
340+
});
341+
342+
it('CONTROL: an empty, hidden or undeclared attachment takes no row', () => {
343+
const plan = planSnapshotSummary(
344+
{ title: 'T', invoices: [], receipt: ' ', photo: {}, clip: null, private_scan: ID_A, legacy_file: [ID_B] },
345+
CLAIM, undefined,
346+
);
347+
expect(plan).toEqual({ lead: null, rows: ['title'], attachments: [], summed: null });
348+
});
349+
});
350+
351+
describe('RecordSnapshotSummary: attachments are drawn and open (objectstack#32854)', () => {
352+
const claim = { name: 'expense_claim', fields: CLAIM };
353+
const draw = async (snapshot: Record<string, unknown>) => {
354+
mount({ expense_claim: claim }, { objectName: 'expense_claim', snapshot });
355+
return screen.findByTestId('record-snapshot-summary');
356+
};
357+
const linksOf = (el: Element | null | undefined) =>
358+
[...(el?.querySelectorAll('a[data-slot="file-download-link"]') ?? [])].map((a) => ({
359+
href: a.getAttribute('href'),
360+
target: a.getAttribute('target'),
361+
name: a.textContent,
362+
}));
363+
364+
it('a `multiple` file field draws each file as a link that opens it, after the six rows', async () => {
365+
const summary = await draw({
366+
amount: 120, title: 'Trip', category: 'Travel', reason: 'Visit', invoice_no: 'F-1', status: 'open',
367+
invoices: [ID_A, { id: ID_B, name: 'invoice-2.pdf', url: '/api/v1/storage/files/fil_d4e5f6' }],
368+
});
369+
expect([...summary.querySelectorAll('[data-summary-field]')].map((r) => r.getAttribute('data-summary-field')))
370+
.toEqual(['title', 'category', 'reason', 'invoice_no', 'status']);
371+
const row = summary.querySelector('[data-summary-attachment="invoices"]');
372+
expect(row?.firstElementChild?.textContent).toBe('E-invoices');
373+
expect(linksOf(row)).toEqual([
374+
{ href: `/api/v1/storage/files/${ID_A}`, target: '_blank', name: 'File' },
375+
{ href: '/api/v1/storage/files/fil_d4e5f6', target: '_blank', name: 'invoice-2.pdf' },
376+
]);
377+
});
378+
379+
it('a single file field draws its file as a link that opens it', async () => {
380+
const summary = await draw({ title: 'Trip', receipt: { id: ID_A, name: 'receipt.pdf', url: '/api/v1/storage/files/fil_a1b2c3' } });
381+
expect(linksOf(summary.querySelector('[data-summary-attachment="receipt"]'))).toEqual([
382+
{ href: `/api/v1/storage/files/${ID_A}`, target: '_blank', name: 'receipt.pdf' },
383+
]);
384+
});
385+
386+
it.each([['video', 'clip'], ['audio', 'memo']])('the %s field draws its file as a link that opens it', async (_kind, key) => {
387+
const summary = await draw({ title: 'Trip', [key]: [ID_A] });
388+
expect(linksOf(summary.querySelector(`[data-summary-attachment="${key}"]`))).toEqual([
389+
{ href: `/api/v1/storage/files/${ID_A}`, target: '_blank', name: 'File' },
390+
]);
391+
});
392+
393+
it.each([['image', 'photo'], ['avatar', 'badge']])('an %s field draws its thumbnail from the download endpoint', async (_kind, key) => {
394+
const summary = await draw({ title: 'Trip', [key]: ID_A });
395+
const img = summary.querySelector(`[data-summary-attachment="${key}"] img`);
396+
expect(img?.getAttribute('src')).toBe(`/api/v1/storage/files/${ID_A}`);
397+
});
398+
399+
it('CONTROL: a left-out kind draws nothing, and the scalar rows are unchanged', async () => {
400+
const summary = await draw({ title: 'Trip', status: 'open', ...LEFT_OUT });
401+
expect([...summary.querySelectorAll('[data-summary-field]')].map((r) => r.textContent)).toEqual(['TitleTrip', 'Statusopen']);
402+
expect(summary.querySelectorAll('[data-summary-attachment]')).toHaveLength(0);
403+
});
404+
405+
it('a snapshot holding only an attachment still draws the section', async () => {
406+
const summary = await draw({ invoices: [ID_A] });
407+
expect(linksOf(summary.querySelector('[data-summary-attachment="invoices"]'))).toHaveLength(1);
408+
});
409+
});

‎ui/packages/app-shell/src/views/approval-decision/RecordSnapshotSummary.tsx‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444
* `withoutDeniedFields` with the reader's field permissions, as every surface
4545
* that draws a display value from a whole row does (objectui#10594).
4646
*
47+
* ## Object and list values: attachments are drawn, the rest is left out
48+
*
49+
* A field whose value is an object or a list is drawn only when it is an
50+
* attachment, and by this rule alone:
51+
*
52+
* - **Attachments are drawn**: a declared field whose type is in the spec's
53+
* media family `FILE_REFERENCE_TYPES` (`file`, single or `multiple`,
54+
* `image`, `avatar`, `video`, `audio`), whichever form the snapshot holds
55+
* (the stored `sys_file` id, the expanded `{ id, name, url }` object, a list
56+
* of either). Each is drawn through the field's own cell, the record page's:
57+
* a file is a link to the platform's download endpoint, an image a
58+
* thumbnail that opens. The summary adds no download channel; the endpoint
59+
* judges the reader's access. Attachments are drawn full width after the
60+
* rows and are never cut by `SNAPSHOT_SUMMARY_ROWS`, because they are what
61+
* the approver decides on. An empty one (no id, an empty list) gets no row.
62+
* - **Every other object or list value is left out**, whatever its type: an
63+
* address, a location, `json` / `object`, `composite`, `record`,
64+
* `repeater`, `grid`, `vector`, a multi-value option list (`multiselect`,
65+
* `checkboxes`, `tags`) and a multi-value reference. Their faces are
66+
* blocks, maps or chip lists that a one-line glance row cannot hold without
67+
* cutting them, and the record itself, a click away, draws them whole.
68+
*
4769
* Until the object's definition answers, or when it cannot (no definition, a
4870
* refused read), nothing is drawn: without the declarations there is no
4971
* declared label, no face and no `hidden` to honour.
@@ -175,7 +197,7 @@ function DeclaredSummary({ target, fields, shown, display }: {
175197
const childFields = summed === null ? null : declaredFields(child.item, summed);
176198
const summarized = summed !== null && childFields ? { name: summed, fields: childFields } : null;
177199
const plan = planSnapshotSummary(shown, fields, display, summarized);
178-
const keys = plan.lead ? [plan.lead, ...plan.rows] : plan.rows;
200+
const keys = [...(plan.lead ? [plan.lead] : []), ...plan.rows, ...plan.attachments];
179201
if (keys.length === 0) return null;
180202

181203
const declaredLabel = (key: string) => {
@@ -212,6 +234,16 @@ function DeclaredSummary({ target, fields, shown, display }: {
212234
))}
213235
</div>
214236
)}
237+
{plan.attachments.length > 0 && (
238+
<div className="space-y-2 text-sm">
239+
{plan.attachments.map((key) => (
240+
<div key={key} className="min-w-0" data-summary-attachment={key}>
241+
<div className="text-[11px] text-muted-foreground">{labelOf.get(key)}</div>
242+
<FieldFace objectName={target} def={{ ...(fields[key] as FieldDef), name: key }} value={shown[key]} snapshot={shown} fields={fields} />
243+
</div>
244+
))}
245+
</div>
246+
)}
215247
</section>
216248
);
217249
}

‎ui/packages/app-shell/src/views/approval-decision/snapshotSummaryPlan.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* in `RecordSnapshotSummary.tsx`'s header.
1414
*/
1515

16+
import { FILE_REFERENCE_TYPES } from '@objectstack/spec/data';
1617
import { isExpandableFieldType } from '@object-ui/core';
1718
import { isSystemManagedField, type SummaryFieldMetadata } from '@object-ui/types';
1819

@@ -26,6 +27,13 @@ type FieldDefs = Readonly<Record<string, FieldDef | undefined>>;
2627
export interface SnapshotSummaryPlan {
2728
lead: string | null;
2829
rows: string[];
30+
/**
31+
* The attachment fields the snapshot holds, in snapshot order: declared
32+
* fields whose type is a `FILE_REFERENCE_TYPES` member (the spec's media
33+
* family, `file` single and `multiple` included). Drawn after the rows and
34+
* never cut by `max`: an attachment is what the approver decides on.
35+
*/
36+
attachments: string[];
2937
/**
3038
* The object a `sum` summary ahead of the amount rolls up, whose definition
3139
* decides whether that summary is the amount (objectui#12534); null when no
@@ -45,6 +53,17 @@ function declaredSum(def: FieldDef | undefined): SummaryOperations | null {
4553
return ops?.function === 'sum' ? ops : null;
4654
}
4755

56+
/**
57+
* Does an attachment field's stored value hold a file: a non-empty id or URL,
58+
* a non-empty list, or an object with any member (the expanded or refused
59+
* form). Each entry is the field cell's to read.
60+
*/
61+
function holdsAttachment(value: unknown): boolean {
62+
if (typeof value === 'string') return value.trim() !== '';
63+
if (Array.isArray(value)) return value.length > 0;
64+
return !!value && typeof value === 'object' && Object.keys(value).length > 0;
65+
}
66+
4867
/** How many business-field rows the summary draws below the amount. */
4968
export const SNAPSHOT_SUMMARY_ROWS = 6;
5069

@@ -71,11 +90,18 @@ export function planSnapshotSummary(
7190
max: number = SNAPSHOT_SUMMARY_ROWS,
7291
): SnapshotSummaryPlan {
7392
const candidates: string[] = [];
93+
const attachments: string[] = [];
7494
for (const [key, value] of Object.entries(snapshot)) {
7595
const def = fields[key];
7696
if (!def || typeof def !== 'object') continue; // not a field of this object
7797
if (def.hidden === true) continue; // hidden from the default UI
7898
if (isSystemManagedField(key, def as { system?: boolean })) continue; // bookkeeping
99+
if (typeof def.type === 'string' && FILE_REFERENCE_TYPES.has(def.type)) {
100+
if (holdsAttachment(value)) attachments.push(key);
101+
continue;
102+
}
103+
// Every other object or list value is left out (the rule is in
104+
// `RecordSnapshotSummary.tsx`'s header).
79105
if (value == null || typeof value === 'object') continue;
80106
if (String(value).trim() === '') continue;
81107
if (!display?.[key] && isExpandableFieldType(def)) continue; // an unresolved reference id
@@ -106,7 +132,7 @@ export function planSnapshotSummary(
106132
}
107133
lead ??= leadZero;
108134

109-
return { lead, rows: candidates.filter((key) => key !== lead).slice(0, max), summed };
135+
return { lead, rows: candidates.filter((key) => key !== lead).slice(0, max), attachments, summed };
110136
}
111137

112138
/**

0 commit comments

Comments
 (0)