Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 92c2a69

Browse files
feat(app-shell): Publish opens the pending-changes sheet to confirm, Changes opens it to review (objectui#12517) (#12595)
Fixes #12517 Clause-②: no ## What changed **Target 3 — one sheet, one component, one prop.** `DraftChangesPanel` takes `posture`, either `review` (the default) or `confirm`. The Studio keeps one `changesPosture` state beside `changesOpen`. Publish sets `confirm` and Changes sets `review`, each before opening, and the single `DraftChangesPanel` mount passes it. The Home page, `DraftPreviewBar` and `CommitTimeline` pass nothing and keep the review behaviour. Publish is still review-then-confirm (objectui#2261): the header click only opens the sheet, and only the footer's Publish all publishes. **Target 1 — Publish opens to confirm.** When the list first arrives on each open, every row is expanded, a summary line above the list counts what the publish carries (for example `4 items · 2 object · 1 app · 1 page`), and focus moves to Publish all. The line is built from the panel's existing per-type grouping, the one that draws the `OBJECT · 2` headings, so there is no second classification. A row the author collapses stays collapsed while the rows classify. The seed runs in a layout effect, so no frame shows the list collapsed first. **Target 2 — Changes opens to review.** Rows stay collapsed, focus lands on the list, and Publish all is in the footer, unfocused. There is no summary line. **Constraints kept.** With nothing pending, Publish stays disabled and described by `publish-none-reason` (objectui#12303); on a read-only package the reason still rides its wrapper. `studio-changes-count` and the other test ids are unchanged. The objectui#12510 pin `DraftChangesPanel.accessibleNames-12510` stays green. New language-pack keys under `preview.changes`: `summaryItems` (with plural forms) and `summaryType`, in all ten locales. ## Deviations - The type segments show the raw canonical type, the same token the group headings show (`2 object`), not a localized plural noun. The panel has no type-label table, and it sits on the console's eager graph, so it cannot import the metadata-admin one. - Publish all does not exist until the list loads, so focus starts on the list and moves to Publish all when the list arrives, unless the author has already moved it. - The confirm posture reads each draft's detail at open (two reads per row), because every row is expanded. The review posture still reads lazily on expand. ## Screenshots These are on the never-merged evidence branch `claude/issue-12517-evidence`, at a writable package with four drafts of three types, 1280 px wide. - Publish, confirm posture, dark: https://github.com/objectstack-ai/objectui/blob/a4de5c7d69509c1521ed0f5047f8671417d2da9d/docs/design/studio-redesign/findings/12517/12517-publish-confirm-dark.png?raw=true - Publish, confirm posture, light: https://github.com/objectstack-ai/objectui/blob/a4de5c7d69509c1521ed0f5047f8671417d2da9d/docs/design/studio-redesign/findings/12517/12517-publish-confirm-light.png?raw=true - Changes, review posture, dark: https://github.com/objectstack-ai/objectui/blob/a4de5c7d69509c1521ed0f5047f8671417d2da9d/docs/design/studio-redesign/findings/12517/12517-changes-review-dark.png?raw=true - Changes, review posture, light: https://github.com/objectstack-ai/objectui/blob/a4de5c7d69509c1521ed0f5047f8671417d2da9d/docs/design/studio-redesign/findings/12517/12517-changes-review-light.png?raw=true Read from the DOM at capture, in both themes: confirm showed `data-posture=confirm`, four `aria-expanded=true` and active element `draft-changes-publish`; review showed `data-posture=review`, four `aria-expanded=false` and active element `draft-changes-list`. ## Test evidence (head 737592f) - `pnpm exec vitest run packages/app-shell/src/views/studio-design/StudioDesignSurface.`: 82 files, 560 tests passed. - `pnpm exec vitest run` over every `DraftChangesPanel*`, `DraftPreviewBar*` and `CommitTimeline*` test, plus `packages/i18n/`: 98 files passed, 1413 tests passed, 13 skipped. - Full `pnpm --filter @object-ui/app-shell test`, once, on ad97f9d: 1427 files passed, 1 skipped; 13553 tests passed, 9 skipped; exit 0. One ru locale value and a merge of main came after this run. On 737592f only the two targeted batches above were re-run. - `type-check` for `@object-ui/app-shell` and `@object-ui/i18n`, build, `check:i18n-keys`, `check:i18n-drift`, `check:i18n-designer-parity`, `check:new-line-citations` and `check-changeset-presence` all exit 0. eslint on the touched files: 0 errors. - New pins: `DraftChangesPanel.posture-12517.test.tsx` (confirm, review, and a CONTROL for a host that passes no posture) and `StudioDesignSurface.publishPosture-12517.test.tsx` (which door passes which posture, and that nothing pending still leaves Publish disabled with its reason). Each was ablated once and went red: seeding moved back to a passive effect, the seed removed, and Publish set to review. Each was restored with `git diff HEAD` empty. ## Acceptance notes - For a NEW object, the drill-in lists `_packageId` under Also changed. That is a framework key shown as the author's edit, the same shape as the read-decoration keys stripped earlier. It is reported to the seat, not fixed here. - In dark mode the New and Update badges keep their light fills. This is pre-existing polish, not in this card's scope. --- _Generated by [Claude Code](https://claude.ai/code/session_01MxLBRTq32u4PebqJCjFXW7)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7b5e558 commit 92c2a69

15 files changed

Lines changed: 487 additions & 6 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': minor
3+
'@object-ui/i18n': minor
4+
---
5+
6+
The Studio's Publish and Changes buttons no longer open the pending-changes sheet the same way.
7+
8+
- **Publish opens it to confirm.** Every pending item is expanded, so the fields and keys each one adds, changes or removes are on screen. A summary line above the list counts what the publish carries, by type (for example "3 items · 1 object · 1 app · 1 page"). Focus lands on Publish all. The header button still publishes nothing by itself; only Publish all in the sheet does.
9+
- **Changes opens it to review.** Items stay collapsed and focus lands on the list. Publish all is still in the footer, unfocused.
10+
11+
Every other place that opens the sheet (the Home page, the draft preview bar and the history timeline) keeps the review behaviour. With nothing pending, Publish stays disabled and says why, as before.
12+
13+
New language-pack keys under `preview.changes`: `summaryItems` (with its plural forms) and `summaryType`, in every shipped locale.

‎packages/app-shell/src/preview/DraftChangesPanel.tsx‎

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* publish action itself still belongs to the caller.
2525
*/
2626

27-
import { useCallback, useEffect, useRef, useState } from 'react';
27+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2828
import { ChevronDown, ChevronRight, Equal, FilePlus2, FilePen, Loader2, Rocket, ShieldAlert } from 'lucide-react';
2929
import { toast } from 'sonner';
3030
import {
@@ -471,15 +471,28 @@ export interface DraftChangesPanelProps {
471471
onPublish?: () => void | Promise<void>;
472472
/** Disables the confirm button and shows a spinner while the caller publishes. */
473473
publishing?: boolean;
474+
/**
475+
* How the sheet opens (objectui#12517). `review` — the default, and what
476+
* every host but the Studio's Publish gets: rows collapsed, focus on the
477+
* list. `confirm` — the host's Publish opened it: every row expanded to
478+
* show what changes, a per-type summary line above the list, and focus on
479+
* the footer's Publish all once it renders. Read on each open; a posture
480+
* never changes what the footer button does (objectui#2261: only it
481+
* publishes).
482+
*/
483+
posture?: DraftChangesPosture;
474484
}
475485

486+
export type DraftChangesPosture = 'review' | 'confirm';
487+
476488
export function DraftChangesPanel({
477489
open,
478490
onOpenChange,
479491
packageId,
480492
include,
481493
onPublish,
482494
publishing = false,
495+
posture = 'review',
483496
}: DraftChangesPanelProps) {
484497
const { t, language } = useObjectTranslation();
485498
const [entries, setEntries] = useState<DraftChangeEntry[] | null>(null);
@@ -514,6 +527,38 @@ export function DraftChangesPanel({
514527
});
515528
}, []);
516529

530+
/**
531+
* objectui#12517 — the posture's two openings. Each open starts collapsed;
532+
* the confirm posture expands every row ONCE, when the list first arrives,
533+
* so a row the author then collapses stays collapsed while the type reads
534+
* below re-map the entries. Focus lands on the list at open (the Publish
535+
* all button does not exist until the list loads) and moves to Publish all
536+
* on that same arrival — only if the author has not moved it meanwhile.
537+
* Layout effects, so the frame that first paints the list already paints
538+
* it expanded: a passive effect let one collapsed frame through first.
539+
*/
540+
const listRef = useRef<HTMLDivElement>(null);
541+
const publishRef = useRef<HTMLButtonElement>(null);
542+
const settledRef = useRef(false);
543+
// The list as it stood when the sheet opened: the previous open's, until
544+
// this open's load replaces it. Only a list newer than that one settles.
545+
const entriesAtOpenRef = useRef<DraftChangeEntry[] | null>(null);
546+
useLayoutEffect(() => {
547+
if (!open) return;
548+
settledRef.current = false;
549+
entriesAtOpenRef.current = entries;
550+
setExpanded(new Set());
551+
// Keyed on the open transition alone: `entries` is read, not watched.
552+
}, [open]);
553+
useLayoutEffect(() => {
554+
if (!open || settledRef.current || entries === null || entries === entriesAtOpenRef.current) return;
555+
settledRef.current = true;
556+
if (posture !== 'confirm') return;
557+
setExpanded(new Set(entries.map(entryKey)));
558+
const button = publishRef.current;
559+
if (button && document.activeElement === listRef.current) button.focus();
560+
}, [open, posture, entries]);
561+
517562
const markCompared = (key: string, isUnchanged: boolean) => {
518563
setUnchanged((prev) => {
519564
if (prev.has(key) === isUnchanged) return prev;
@@ -652,6 +697,13 @@ export function DraftChangesPanel({
652697
side="right"
653698
className="flex w-[420px] flex-col sm:max-w-[420px]"
654699
data-testid="draft-changes-panel"
700+
data-posture={posture}
701+
onOpenAutoFocus={(event) => {
702+
// objectui#12517 — the list, not the first tabbable (the close
703+
// button): see the posture effect above for where focus goes next.
704+
event.preventDefault();
705+
listRef.current?.focus();
706+
}}
655707
>
656708
<SheetHeader>
657709
<SheetTitle>
@@ -663,9 +715,24 @@ export function DraftChangesPanel({
663715
})}
664716
</SheetDescription>
665717
</SheetHeader>
718+
{posture === 'confirm' && entries && entries.length > 0 && !error ? (
719+
// objectui#12517 — what the publish carries, counted off the same
720+
// per-type grouping the headings below read.
721+
<p data-testid="draft-changes-summary" className="mt-3 px-4 text-xs font-medium text-foreground">
722+
{[
723+
t('preview.changes.summaryItems', { count: entries.length, defaultValue: '{{count}} items' }),
724+
...[...byType.entries()].map(([type, items]) =>
725+
t('preview.changes.summaryType', { n: items.length, type, defaultValue: '{{n}} {{type}}' }),
726+
),
727+
].join(' · ')}
728+
</p>
729+
) : null}
666730
<div
731+
ref={listRef}
732+
tabIndex={-1}
733+
aria-label={t('preview.changes.title', { defaultValue: 'Pending changes' })}
667734
data-testid="draft-changes-list"
668-
className="mt-4 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-6"
735+
className="mt-4 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-6 outline-none"
669736
>
670737
{error ? (
671738
<p className="text-sm text-destructive">
@@ -854,6 +921,7 @@ export function DraftChangesPanel({
854921
})}
855922
</p>
856923
<Button
924+
ref={publishRef}
857925
size="sm"
858926
onClick={() => void onPublish()}
859927
disabled={publishing}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
* objectui#12517 — the pending-changes sheet opens in one of two postures.
11+
*
12+
* `confirm` (the Studio's Publish): every row expanded, a per-type summary
13+
* line above the list, focus on the footer's Publish all. `review` (the
14+
* Studio's Changes, and the default every other host gets): rows collapsed,
15+
* focus on the list, the footer button present but not focused, no summary.
16+
*
17+
* The CONTROL is the mount the Home page, `DraftPreviewBar` and
18+
* `CommitTimeline` use: no `posture` prop at all. It must read exactly as the
19+
* review posture does.
20+
*/
21+
22+
import '@testing-library/jest-dom/vitest';
23+
import * as React from 'react';
24+
import { afterEach, describe, expect, it, vi } from 'vitest';
25+
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
26+
27+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
28+
...(await importOriginal<Record<string, unknown>>()),
29+
useObjectTranslation: () => ({
30+
// Interpolating, so the summary line reads as an author would see it.
31+
t: (_k: string, o?: Record<string, unknown> & { defaultValue?: string }) =>
32+
(o?.defaultValue ?? _k).replace(/\{\{(\w+)\}\}/g, (_m, name: string) => String(o?.[name] ?? '')),
33+
language: 'en',
34+
}),
35+
}));
36+
37+
import { DraftChangesPanel, type DraftChangesPosture } from '../DraftChangesPanel';
38+
39+
// Three drafts of two types: the summary line has something to count.
40+
const DRAFT_ROWS = [
41+
{ type: 'object', name: 'st_ticket', packageId: 'com.x', label: 'Ticket' },
42+
{ type: 'object', name: 'st_queue', packageId: 'com.x', label: 'Queue' },
43+
{ type: 'page', name: 'st_home', packageId: 'com.x', label: 'Home' },
44+
];
45+
46+
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
47+
const url = String(input);
48+
const ok = (body: unknown) => ({ ok: true, status: 200, json: async () => body });
49+
if (url.includes('/_drafts')) return ok({ drafts: DRAFT_ROWS });
50+
if (/\/meta\/object(\?|$)/.test(url)) return ok([{ name: 'st_queue' }]);
51+
if (/\/meta\/page(\?|$)/.test(url)) return ok([]);
52+
if (url.includes('state=draft')) return ok({ name: 'x', label: 'Draft label' });
53+
return { ok: false, status: 404, json: async () => ({}) };
54+
});
55+
56+
afterEach(() => {
57+
cleanup();
58+
vi.unstubAllGlobals();
59+
fetchMock.mockClear();
60+
});
61+
62+
function Host({ posture, open = true }: { posture?: DraftChangesPosture; open?: boolean }) {
63+
return (
64+
<DraftChangesPanel
65+
open={open}
66+
onOpenChange={() => {}}
67+
packageId="com.x"
68+
onPublish={() => {}}
69+
{...(posture ? { posture } : {})}
70+
/>
71+
);
72+
}
73+
74+
async function renderHost(posture?: DraftChangesPosture) {
75+
vi.stubGlobal('fetch', fetchMock as unknown as typeof fetch);
76+
const utils = render(<Host posture={posture} />);
77+
// Every row classified: each badge has replaced its spinner.
78+
await waitFor(() => expect(screen.getAllByText(/^(New|Update)$/)).toHaveLength(DRAFT_ROWS.length));
79+
return utils;
80+
}
81+
82+
const toggles = () => screen.getAllByTestId('draft-entry-toggle');
83+
84+
function expectReviewPosture() {
85+
for (const toggle of toggles()) expect(toggle).toHaveAttribute('aria-expanded', 'false');
86+
expect(screen.queryAllByTestId('draft-entry-detail')).toHaveLength(0);
87+
expect(screen.getByTestId('draft-changes-list')).toHaveFocus();
88+
// The footer is there — review never hides the way to publish — but unfocused.
89+
const publish = screen.getByTestId('draft-changes-publish');
90+
expect(publish).toBeInTheDocument();
91+
expect(publish).not.toHaveFocus();
92+
expect(screen.queryByTestId('draft-changes-summary')).toBeNull();
93+
}
94+
95+
describe('objectui#12517 — the pending-changes sheet opens in a posture', () => {
96+
it('confirm: every row expanded, the summary line counted by type, focus on Publish all', async () => {
97+
// No frame shows a collapsed row: the expansion lands in the commit that
98+
// first renders the list, not in a passive effect after it is painted
99+
// (under load the observer below fired in that gap, and so would a paint).
100+
let collapsedSeen = 0;
101+
const observer = new MutationObserver(() => {
102+
collapsedSeen += document.querySelectorAll('[data-testid="draft-entry-toggle"][aria-expanded="false"]').length;
103+
});
104+
observer.observe(document.body, { subtree: true, childList: true, attributes: true });
105+
await renderHost('confirm');
106+
observer.disconnect();
107+
expect(collapsedSeen).toBe(0);
108+
expect(screen.getByTestId('draft-changes-panel')).toHaveAttribute('data-posture', 'confirm');
109+
for (const toggle of toggles()) expect(toggle).toHaveAttribute('aria-expanded', 'true');
110+
await waitFor(() => expect(screen.getAllByTestId('draft-entry-detail')).toHaveLength(DRAFT_ROWS.length));
111+
expect(screen.getByTestId('draft-changes-publish')).toHaveFocus();
112+
expect(screen.getByTestId('draft-changes-summary')).toHaveTextContent(/^3 items · 2 object · 1 page$/);
113+
});
114+
115+
it('review: rows collapsed, focus on the list, Publish all present but not focused', async () => {
116+
await renderHost('review');
117+
expect(screen.getByTestId('draft-changes-panel')).toHaveAttribute('data-posture', 'review');
118+
expectReviewPosture();
119+
});
120+
121+
it('CONTROL: a host that passes no posture (Home, DraftPreviewBar, CommitTimeline) gets review', async () => {
122+
await renderHost(undefined);
123+
expect(screen.getByTestId('draft-changes-panel')).toHaveAttribute('data-posture', 'review');
124+
expectReviewPosture();
125+
});
126+
127+
it('confirm: a row the author collapses stays collapsed while the rows classify', async () => {
128+
vi.stubGlobal('fetch', fetchMock as unknown as typeof fetch);
129+
render(<Host posture="confirm" />);
130+
await waitFor(() => expect(toggles()).toHaveLength(DRAFT_ROWS.length));
131+
await waitFor(() => expect(toggles()[0]).toHaveAttribute('aria-expanded', 'true'));
132+
fireEvent.click(toggles()[0]);
133+
await waitFor(() => expect(screen.getAllByText(/^(New|Update)$/)).toHaveLength(DRAFT_ROWS.length));
134+
expect(toggles()[0]).toHaveAttribute('aria-expanded', 'false');
135+
expect(toggles()[1]).toHaveAttribute('aria-expanded', 'true');
136+
});
137+
138+
it('the posture is read on each open: Publish then Changes opens collapsed the second time', async () => {
139+
vi.stubGlobal('fetch', fetchMock as unknown as typeof fetch);
140+
const { rerender } = render(<Host posture="confirm" />);
141+
await waitFor(() => expect(screen.getByTestId('draft-changes-publish')).toHaveFocus());
142+
for (const toggle of toggles()) expect(toggle).toHaveAttribute('aria-expanded', 'true');
143+
144+
rerender(<Host posture="confirm" open={false} />);
145+
await waitFor(() => expect(screen.queryByTestId('draft-changes-panel')).toBeNull());
146+
await act(async () => {
147+
rerender(<Host posture="review" />);
148+
});
149+
await waitFor(() => expect(screen.getAllByText(/^(New|Update)$/)).toHaveLength(DRAFT_ROWS.length));
150+
expectReviewPosture();
151+
});
152+
});

0 commit comments

Comments
 (0)