Skip to content

Commit 4a50bbb

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-j9w929-wt
# Conflicts: # ui/packages/app-shell/src/views/listDraftStore.ts # ui/packages/app-shell/src/views/objectViewListRenderer.tsx
2 parents 75e68ba + 5e8e243 commit 4a50bbb

30 files changed

Lines changed: 841 additions & 387 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(console): a footer calculation is a part of the list's draft; a refused save of a package's view says why in the reader's words
7+
8+
Clause-②: yes (widening) — new keys in every `@object-ui/i18n` locale pack: `console.objectView.personalizedParts.summaries` and `console.objectView.saveRefused.packaged`; nothing removed or renamed
9+
Metadata-protocol: none
10+
11+
On a Console object list, picking, changing or removing a column's footer calculation (「+ 添加统计」) applies at once and writes nothing. It used to be saved at once: on the reader's own view straight into it, on a shared view as a draft of the view (`PUT /api/v1/meta/view/<name>?mode=draft`), which the server refuses on a view an app package ships.
12+
13+
- The calculation is a part of the list's draft, like the sort and the filter: **Discard** and **Save** appear, Save's menu names it (「统计」), and Discard takes it off. The draft lives as long as the others: kept on opening a record and coming back, dropped on another view, object or a reload.
14+
- **Save to this view** (on the reader's own view, or on a shared view an admin may edit) and **Save as my view** store it on the columns the saved view keeps.
15+
- **Save to this view** on a shared view is offered only once the Console has read that the view's package takes saves: not while that read is in flight (on a slow start the list draws seconds before it lands) nor for a package it lists read-only. A failed read, or a package the list leaves out, still offers it as before.
16+
- On a view the reader cannot change in place (one an app package ships, or a shared view of a reader who is no admin), the pick goes into the draft too and Save offers **Save as my view** alone.
17+
- The menu is offered on every column the saved view would carry: the columns the list draws and the fields the reader added.
18+
- When the server refuses to save a view an app package ships (`NOT_OVERRIDABLE`), the toast says in the reader's language that the view comes with an app package, cannot be changed directly and can be saved as the reader's own view. The server's text goes to the console only. Every other refusal is said as before.

‎content/docs/ui/views.mdx‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -620,25 +620,34 @@ reader's right-column and panel choices on it, are described in
620620
### A user's list state never writes the view
621621
622622
A header sort, a filter change, grouping, the search, Hide Fields, an added field, a
623-
column drag and the Display panel's layout and row color apply at once and are a **draft**:
624-
they are kept nowhere and never write the view metadata, so they work even where the
625-
tenant's metadata is read-only. While the list holds a draft, **Discard** and **Save** sit at
626-
the end of the condition row (one **Save** whose menu also holds Discard on a narrow list or
627-
a phone).
628-
629-
- **Save** names what is unsaved and keeps the sort, filters, columns, hidden fields, layout
630-
and row color: **Save to this view**, or **Save as my view**, which asks a name first (the
631-
view's name with "copy") and then opens the new view. Either says "Saved", and the buttons
632-
go while the conditions stay.
623+
column drag, a footer calculation picked under a column, and the Display panel's layout and
624+
row color apply at once and are a **draft**: they are kept nowhere and never write the view
625+
metadata, so they work even where the tenant's metadata is read-only. While the list holds a
626+
draft, **Discard** and **Save** sit at the end of the condition row (one **Save** whose menu
627+
also holds Discard on a narrow list or a phone).
628+
629+
- **Save** names what is unsaved and keeps the sort, filters, columns, hidden fields, footer
630+
calculations, layout and row color: **Save to this view**, or **Save as my view**, which
631+
asks a name first (the view's name with "copy") and then opens the new view. Either says
632+
"Saved", and the buttons go while the conditions stay. A view the user cannot change in
633+
place (one an app package ships, or a shared view they may not edit) offers **Save as my
634+
view** alone.
633635
- **Save to this view** on a view of the user's own saves it at once. On a shared view it is
634636
offered to a user who may edit the view (an administrator, on a stored view whose package
635-
takes saves). It asks once ("everyone who uses this view will see these changes"), then
637+
takes saves; while the Console has not yet read which packages take saves, it is not
638+
offered). It asks once ("everyone who uses this view will see these changes"), then
636639
saves the view and publishes it in the same step, so every user sees it on their next read,
637640
and says "Saved, visible to everyone". It never writes the user's row height or column
638641
widths into the view. When the view already has unpublished changes (a draft saved from
639642
the view settings, by anyone), nothing is saved: the Console says so and points to the view
640643
settings to publish or discard that draft first. Every other change to a shared view still
641644
goes to a draft that the view settings publish.
645+
- A footer calculation is offered on every column the saved view would carry: the columns
646+
the list draws and the fields the user added. Picking the view's own calculation again
647+
takes that column out of the draft.
648+
- When the server refuses to save a view an app package ships, the list says so in the
649+
user's language (it cannot be changed directly; save it as your own view), never the
650+
server's own text.
642651
- **Discard** puts the list back as its view declares it, the Display panel's layout and row
643652
color included, and removes the list's `uf_*` parameters from the address bar.
644653
- The draft survives opening a record and coming back. Opening another view or object,

‎ui/packages/app-shell/src/console/__tests__/AppContent.draftSaveKeepsList-35932.test.tsx‎

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
* mounts, so a remount of the route is read as a second mount.
2222
*
2323
* Pinned:
24-
* - an admin's footer pick on a shared view: no skeleton, no remount, the
25-
* list keeps the picked calculation while the refresh is on the wire and
26-
* after it lands;
27-
* - two successive picks: the second draft carries both;
28-
* - the writes are draft saves; a reader (not an admin) served the published
29-
* view draws it, without the admin's calculations.
24+
* - an admin's footer pick on a shared view, then the refresh pulse a draft
25+
* save announces: no skeleton, no remount, the list keeps the picked
26+
* calculation while the refresh is on the wire and after it lands. Since
27+
* objectstack#36194 the pick itself is a part of the list's draft and
28+
* writes nothing, so the pulse is announced here as a save announces it;
29+
* - two successive picks: the list draws both, and nothing is written;
30+
* - a reader (not an admin) served the published view draws it, without the
31+
* admin's calculations.
3032
* CONTROL: a whole-type invalidation of `view` (the provider dropping its
3133
* items, not refetching in place) still sends the route back to waiting.
3234
*
@@ -199,6 +201,7 @@ import '../../views/ObjectView.js';
199201
import { AppContent } from '../AppContent';
200202
import { MetadataProvider, useMetadata } from '../../providers/MetadataProvider';
201203
import { publishRuntimeMetadata } from '../../views/runtime-metadata-persistence.js';
204+
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';
202205

203206
interface Server {
204207
/** Hold every `/meta/view` list read until `releaseViews`, as a request on the wire. */
@@ -362,12 +365,8 @@ const pick = (field: string, summary: string) =>
362365
act(async () => {
363366
await list.props!.onColumnSummaryPick(field, summary);
364367
});
365-
const storedSummaries = (body: any) =>
366-
Object.fromEntries(
367-
((body?.config?.columns ?? body?.columns ?? []) as Array<string | { field: string; summary?: unknown }>)
368-
.filter((c): c is { field: string; summary?: unknown } => typeof c === 'object' && c.summary !== undefined)
369-
.map((c) => [c.field, c.summary]),
370-
);
368+
/** The refresh pulse every write of the persistence seam announces (`emitMetadataRefresh`). */
369+
const announceSave = () => act(() => emitMetadataRefresh());
371370

372371
beforeEach(() => {
373372
server.holdViews = false;
@@ -400,7 +399,9 @@ describe('objectstack#35932 — a shared view\'s draft save keeps the list on sc
400399
// The refresh the save announces re-reads `/meta/view`; held, as a request on the wire.
401400
server.holdViews = true;
402401
await pick('amount', 'sum');
403-
expect(saves).toHaveLength(1);
402+
// objectstack#36194 — the pick is the list's draft: nothing is written.
403+
expect(saves).toHaveLength(0);
404+
announceSave();
404405
await act(async () => {
405406
await new Promise((resolve) => setTimeout(resolve, 50));
406407
});
@@ -417,28 +418,25 @@ describe('objectstack#35932 — a shared view\'s draft save keeps the list on sc
417418
expect(summaryOf('amount')).toBe('sum');
418419
});
419420

420-
it('two successive picks: the second draft carries both', async () => {
421+
it('two successive picks: the list draws both, nothing is written', async () => {
421422
boot(true);
422423
await waitFor(() => expect(typeof list.props?.onColumnSummaryPick).toBe('function'), { timeout: 5000 });
423424

424425
server.holdViews = true;
425426
await pick('amount', 'sum');
427+
announceSave();
426428
await act(async () => {
427429
await new Promise((resolve) => setTimeout(resolve, 50));
428430
});
429431
await pick('closed_at', 'latest');
432+
announceSave();
430433
server.holdViews = false;
431434
act(() => server.releaseViews());
432435
await act(async () => {
433436
await new Promise((resolve) => setTimeout(resolve, 50));
434437
});
435438

436-
expect(saves.map((s) => [s.type, s.name, s.options?.mode])).toEqual([
437-
['view', VIEW, 'draft'],
438-
['view', VIEW, 'draft'],
439-
]);
440-
expect(storedSummaries(saves[0].body)).toEqual({ amount: 'sum' });
441-
expect(storedSummaries(saves[1].body)).toEqual({ amount: 'sum', closed_at: 'latest' });
439+
expect(saves).toEqual([]);
442440
expect(list.mounts).toBe(1);
443441
expect(summaryOf('amount')).toBe('sum');
444442
expect(summaryOf('closed_at')).toBe('latest');
@@ -448,15 +446,15 @@ describe('objectstack#35932 — a shared view\'s draft save keeps the list on sc
448446
boot(true);
449447
await waitFor(() => expect(typeof list.props?.onColumnSummaryPick).toBe('function'), { timeout: 5000 });
450448
await pick('amount', 'sum');
451-
expect(saves.map((s) => s.options?.mode)).toEqual(['draft']);
449+
expect(saves).toEqual([]);
452450
cleanup();
453451

454452
forgetList();
455453
boot(false);
456454
await waitFor(() => expect(list.props?.schema?.columns).toBeDefined(), { timeout: 5000 });
457455
expect(summaryOf('amount')).toBeUndefined();
458-
// Offered to an admin only.
459-
expect(list.props?.onColumnSummaryPick).toBeUndefined();
456+
// objectstack#36194 — a reader's pick is their own draft too.
457+
expect(typeof list.props?.onColumnSummaryPick).toBe('function');
460458
});
461459

462460
it('CONTROL: a whole-type invalidation of `view` still sends the route back to waiting', async () => {
@@ -486,6 +484,7 @@ describe('objectstack#35932 — the same, on an app with a bundle', () => {
486484

487485
appBundle.hold = true;
488486
await pick('amount', 'sum');
487+
announceSave();
489488
await settle();
490489
// The pulse dropped the bundle and its reload is on the wire.
491490
expect(appBundle.items).toBeNull();
@@ -502,18 +501,21 @@ describe('objectstack#35932 — the same, on an app with a bundle', () => {
502501
expect(summaryOf('amount')).toBe('sum');
503502
});
504503

505-
it('two successive picks, then Publish: both picks in the second draft, one mount throughout', async () => {
504+
it('two successive picks, then Publish: both picks drawn, one mount throughout', async () => {
506505
boot(true, { bundle: true });
507506
await waitFor(() => expect(typeof list.props?.onColumnSummaryPick).toBe('function'), { timeout: 5000 });
508507

509508
appBundle.hold = true;
510509
await pick('amount', 'sum');
510+
announceSave();
511511
await settle();
512512
await pick('closed_at', 'latest');
513+
announceSave();
513514
await settle();
514515
expect(skeletonUp()).toBe(false);
515-
expect(storedSummaries(saves[0].body)).toEqual({ amount: 'sum' });
516-
expect(storedSummaries(saves[1].body)).toEqual({ amount: 'sum', closed_at: 'latest' });
516+
expect(saves).toEqual([]);
517+
expect(summaryOf('amount')).toBe('sum');
518+
expect(summaryOf('closed_at')).toBe('latest');
517519

518520
appBundle.hold = false;
519521
act(() => releaseBundle());

‎ui/packages/app-shell/src/hooks/useStudioDesignGate.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ function usePackageListSession(): string {
142142
* previous organization) is never read as this one's.
143143
*/
144144
function usePackagePosture(packageId: string | null): StudioPosture | null {
145+
return usePackagePostureRead(packageId)?.posture ?? null;
146+
}
147+
148+
/**
149+
* {@link usePackagePosture} with the read itself: `undefined` while the
150+
* package list for `packageId` is not answered yet (or `packageId` is `null`),
151+
* else the answer, `posture: null` for a failed read and a package the list
152+
* leaves out.
153+
*/
154+
function usePackagePostureRead(packageId: string | null): { posture: StudioPosture | null } | undefined {
145155
const session = usePackageListSession();
146156
const [verdict, setVerdict] = useState<{
147157
packageId: string;
@@ -164,8 +174,8 @@ function usePackagePosture(packageId: string | null): StudioPosture | null {
164174
};
165175
}, [packageId, session]);
166176
return packageId !== null && verdict?.packageId === packageId && verdict.session === session
167-
? verdict.posture
168-
: null;
177+
? { posture: verdict.posture }
178+
: undefined;
169179
}
170180

171181
/**
@@ -208,6 +218,23 @@ export function usePackageRefusesSaves(packageId: string | null): boolean {
208218
return usePackagePosture(packageId) === 'view';
209219
}
210220

221+
/**
222+
* objectstack#36195 — {@link usePackageRefusesSaves} for a save that is not
223+
* offered on a guess: `unread` while the package list for `packageId` is still
224+
* being read, `refuses` when it carries the package read-only, else `takes`
225+
* (`null`, a failed read and a package the list leaves out keep the fail-open
226+
* answer, so the server's write gate refuses what it refuses). A list's
227+
* 「Save to this view」 on a shared view waits for the answer: on a slow boot
228+
* the list draws seconds before the package list lands, and a save offered in
229+
* that window is a save into a package's view the server refuses.
230+
*/
231+
export function usePackageSaveRead(packageId: string | null): 'unread' | 'refuses' | 'takes' {
232+
const read = usePackagePostureRead(packageId);
233+
if (packageId === null) return 'takes';
234+
if (read === undefined) return 'unread';
235+
return read.posture === 'view' ? 'refuses' : 'takes';
236+
}
237+
211238
const NO_REFUSING_PACKAGES: ReadonlySet<string> = new Set();
212239

213240
/**

‎ui/packages/app-shell/src/views/ListDraftActions.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ import { useObjectTranslation } from '@object-ui/i18n';
3434
import { ConditionDiscardButton, type ListViewProps } from '@object-ui/plugin-list';
3535
import { ChevronDown, CopyPlus, RotateCcw, Save } from 'lucide-react';
3636

37-
/** One part of a list that can differ from its view (`ListView`'s vocabulary). */
38-
export type ListPersonalizationPart = Parameters<NonNullable<ListViewProps['onPersonalizationChange']>>[0][number];
37+
/**
38+
* One part of a list that can differ from its view: `ListView`'s vocabulary,
39+
* plus the footer's calculations (objectstack#36194), a part only this page's
40+
* draft knows (the grid hands the pick to the host, which holds it).
41+
*/
42+
export type ListPersonalizationPart =
43+
| Parameters<NonNullable<ListViewProps['onPersonalizationChange']>>[0][number]
44+
| 'summaries';
3945

4046
/** The order the menu names the unsaved parts in: the toolbar's, then the Display panel's. */
4147
const LIST_DRAFT_PART_ORDER: readonly ListPersonalizationPart[] = [
@@ -44,6 +50,7 @@ const LIST_DRAFT_PART_ORDER: readonly ListPersonalizationPart[] = [
4450
'grouping',
4551
'columns',
4652
'hiddenFields',
53+
'summaries',
4754
'layout',
4855
'rowColor',
4956
'inlineEdit',
@@ -76,6 +83,7 @@ export function ListDraftActions({
7683
grouping: t('console.objectView.personalizedParts.grouping'),
7784
columns: t('console.objectView.personalizedParts.columns'),
7885
hiddenFields: t('console.objectView.personalizedParts.hiddenFields'),
86+
summaries: t('console.objectView.personalizedParts.summaries'),
7987
density: t('console.objectView.personalizedParts.density'),
8088
layout: t('console.objectView.personalizedParts.layout'),
8189
rowColor: t('console.objectView.personalizedParts.rowColor'),

0 commit comments

Comments
 (0)