Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/36194-footer-calculation-draft.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

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

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
Metadata-protocol: none

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.

- 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.
- **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.
- **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.
- 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.
- The menu is offered on every column the saved view would carry: the columns the list draws and the fields the reader added.
- 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.
31 changes: 20 additions & 11 deletions content/docs/ui/views.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -620,25 +620,34 @@ reader's right-column and panel choices on it, are described in
### A user's list state never writes the view

A header sort, a filter change, grouping, the search, Hide Fields, an added field, a
column drag and the Display panel's layout and row color apply at once and are a **draft**:
they are kept nowhere and never write the view metadata, so they work even where the
tenant's metadata is read-only. While the list holds a draft, **Discard** and **Save** sit at
the end of the condition row (one **Save** whose menu also holds Discard on a narrow list or
a phone).

- **Save** names what is unsaved and keeps the sort, filters, columns, hidden fields, layout
and row color: **Save to this view**, or **Save as my view**, which asks a name first (the
view's name with "copy") and then opens the new view. Either says "Saved", and the buttons
go while the conditions stay.
column drag, a footer calculation picked under a column, and the Display panel's layout and
row color apply at once and are a **draft**: they are kept nowhere and never write the view
metadata, so they work even where the tenant's metadata is read-only. While the list holds a
draft, **Discard** and **Save** sit at the end of the condition row (one **Save** whose menu
also holds Discard on a narrow list or a phone).

- **Save** names what is unsaved and keeps the sort, filters, columns, hidden fields, footer
calculations, layout and row color: **Save to this view**, or **Save as my view**, which
asks a name first (the view's name with "copy") and then opens the new view. Either says
"Saved", and the buttons go while the conditions stay. A view the user cannot change in
place (one an app package ships, or a shared view they may not edit) offers **Save as my
view** alone.
- **Save to this view** on a view of the user's own saves it at once. On a shared view it is
offered to a user who may edit the view (an administrator, on a stored view whose package
takes saves). It asks once ("everyone who uses this view will see these changes"), then
takes saves; while the Console has not yet read which packages take saves, it is not
offered). It asks once ("everyone who uses this view will see these changes"), then
saves the view and publishes it in the same step, so every user sees it on their next read,
and says "Saved, visible to everyone". It never writes the user's row height or column
widths into the view. When the view already has unpublished changes (a draft saved from
the view settings, by anyone), nothing is saved: the Console says so and points to the view
settings to publish or discard that draft first. Every other change to a shared view still
goes to a draft that the view settings publish.
- A footer calculation is offered on every column the saved view would carry: the columns
the list draws and the fields the user added. Picking the view's own calculation again
takes that column out of the draft.
- When the server refuses to save a view an app package ships, the list says so in the
user's language (it cannot be changed directly; save it as your own view), never the
server's own text.
- **Discard** puts the list back as its view declares it, the Display panel's layout and row
color included, and removes the list's `uf_*` parameters from the address bar.
- The draft survives opening a record and coming back. Opening another view or object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
* mounts, so a remount of the route is read as a second mount.
*
* Pinned:
* - an admin's footer pick on a shared view: no skeleton, no remount, the
* list keeps the picked calculation while the refresh is on the wire and
* after it lands;
* - two successive picks: the second draft carries both;
* - the writes are draft saves; a reader (not an admin) served the published
* view draws it, without the admin's calculations.
* - an admin's footer pick on a shared view, then the refresh pulse a draft
* save announces: no skeleton, no remount, the list keeps the picked
* calculation while the refresh is on the wire and after it lands. Since
* objectstack#36194 the pick itself is a part of the list's draft and
* writes nothing, so the pulse is announced here as a save announces it;
* - two successive picks: the list draws both, and nothing is written;
* - a reader (not an admin) served the published view draws it, without the
* admin's calculations.
* CONTROL: a whole-type invalidation of `view` (the provider dropping its
* items, not refetching in place) still sends the route back to waiting.
*
Expand Down Expand Up @@ -199,6 +201,7 @@ import '../../views/ObjectView.js';
import { AppContent } from '../AppContent';
import { MetadataProvider, useMetadata } from '../../providers/MetadataProvider';
import { publishRuntimeMetadata } from '../../views/runtime-metadata-persistence.js';
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';

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

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

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

server.holdViews = true;
await pick('amount', 'sum');
announceSave();
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 50));
});
await pick('closed_at', 'latest');
announceSave();
server.holdViews = false;
act(() => server.releaseViews());
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 50));
});

expect(saves.map((s) => [s.type, s.name, s.options?.mode])).toEqual([
['view', VIEW, 'draft'],
['view', VIEW, 'draft'],
]);
expect(storedSummaries(saves[0].body)).toEqual({ amount: 'sum' });
expect(storedSummaries(saves[1].body)).toEqual({ amount: 'sum', closed_at: 'latest' });
expect(saves).toEqual([]);
expect(list.mounts).toBe(1);
expect(summaryOf('amount')).toBe('sum');
expect(summaryOf('closed_at')).toBe('latest');
Expand All @@ -448,15 +446,15 @@ describe('objectstack#35932 — a shared view\'s draft save keeps the list on sc
boot(true);
await waitFor(() => expect(typeof list.props?.onColumnSummaryPick).toBe('function'), { timeout: 5000 });
await pick('amount', 'sum');
expect(saves.map((s) => s.options?.mode)).toEqual(['draft']);
expect(saves).toEqual([]);
cleanup();

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

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

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

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

appBundle.hold = true;
await pick('amount', 'sum');
announceSave();
await settle();
await pick('closed_at', 'latest');
announceSave();
await settle();
expect(skeletonUp()).toBe(false);
expect(storedSummaries(saves[0].body)).toEqual({ amount: 'sum' });
expect(storedSummaries(saves[1].body)).toEqual({ amount: 'sum', closed_at: 'latest' });
expect(saves).toEqual([]);
expect(summaryOf('amount')).toBe('sum');
expect(summaryOf('closed_at')).toBe('latest');

appBundle.hold = false;
act(() => releaseBundle());
Expand Down
31 changes: 29 additions & 2 deletions ui/packages/app-shell/src/hooks/useStudioDesignGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ function usePackageListSession(): string {
* previous organization) is never read as this one's.
*/
function usePackagePosture(packageId: string | null): StudioPosture | null {
return usePackagePostureRead(packageId)?.posture ?? null;
}

/**
* {@link usePackagePosture} with the read itself: `undefined` while the
* package list for `packageId` is not answered yet (or `packageId` is `null`),
* else the answer, `posture: null` for a failed read and a package the list
* leaves out.
*/
function usePackagePostureRead(packageId: string | null): { posture: StudioPosture | null } | undefined {
const session = usePackageListSession();
const [verdict, setVerdict] = useState<{
packageId: string;
Expand All @@ -164,8 +174,8 @@ function usePackagePosture(packageId: string | null): StudioPosture | null {
};
}, [packageId, session]);
return packageId !== null && verdict?.packageId === packageId && verdict.session === session
? verdict.posture
: null;
? { posture: verdict.posture }
: undefined;
}

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

/**
* objectstack#36195 — {@link usePackageRefusesSaves} for a save that is not
* offered on a guess: `unread` while the package list for `packageId` is still
* being read, `refuses` when it carries the package read-only, else `takes`
* (`null`, a failed read and a package the list leaves out keep the fail-open
* answer, so the server's write gate refuses what it refuses). A list's
* 「Save to this view」 on a shared view waits for the answer: on a slow boot
* the list draws seconds before the package list lands, and a save offered in
* that window is a save into a package's view the server refuses.
*/
export function usePackageSaveRead(packageId: string | null): 'unread' | 'refuses' | 'takes' {
const read = usePackagePostureRead(packageId);
if (packageId === null) return 'takes';
if (read === undefined) return 'unread';
return read.posture === 'view' ? 'refuses' : 'takes';
}

const NO_REFUSING_PACKAGES: ReadonlySet<string> = new Set();

/**
Expand Down
12 changes: 10 additions & 2 deletions ui/packages/app-shell/src/views/ListDraftActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ import { useObjectTranslation } from '@object-ui/i18n';
import { ConditionDiscardButton, type ListViewProps } from '@object-ui/plugin-list';
import { ChevronDown, CopyPlus, RotateCcw, Save } from 'lucide-react';

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

/** The order the menu names the unsaved parts in: the toolbar's, then the Display panel's. */
const LIST_DRAFT_PART_ORDER: readonly ListPersonalizationPart[] = [
Expand All @@ -44,6 +50,7 @@ const LIST_DRAFT_PART_ORDER: readonly ListPersonalizationPart[] = [
'grouping',
'columns',
'hiddenFields',
'summaries',
'layout',
'rowColor',
'inlineEdit',
Expand Down Expand Up @@ -76,6 +83,7 @@ export function ListDraftActions({
grouping: t('console.objectView.personalizedParts.grouping'),
columns: t('console.objectView.personalizedParts.columns'),
hiddenFields: t('console.objectView.personalizedParts.hiddenFields'),
summaries: t('console.objectView.personalizedParts.summaries'),
density: t('console.objectView.personalizedParts.density'),
layout: t('console.objectView.personalizedParts.layout'),
rowColor: t('console.objectView.personalizedParts.rowColor'),
Expand Down
Loading
Loading