Skip to content

Commit d5ae7a4

Browse files
fix(studio): a permission set's review link opens the draft review on its matrix page (#37347)
Fixes #37269 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到的变化:在软件包页点某个权限集草稿的链接,或在聊天里点「审阅 N 处改动」,打开权限集矩阵页时会弹出审阅面板,列出这份草稿相对已发布版本改了什么;Studio 的权限集页也一样,矩阵照常可以编辑。 - 为什么做:属于「Studio 重构」专题;以前这两个入口打开的矩阵页上看不到任何改动,审阅链接等于失效。 - 出错会怎样:最坏情况是审阅链接打开后面板不弹出或内容不对:权限集之外,其他类型的审阅也改走同一段共享代码(已有测试钉住,行为不变);矩阵编辑不受影响。纯界面改动,直接撤回即可。 - 要你做什么:无。 ## What changes A review link (`?review=1`) on a permission-set draft now opens the draft review on the set's matrix page, the same review sheet the generic item page opens. - **Shared presentation, not a second one.** The generic item page's review sheet (`ResourceEditPage`'s `Sheet` around `DraftReviewPanel`) moves into `DraftReviewSheet`, and its `?review=1` arrival effect into `useDraftReviewArrival` (read afresh, open once the read settles and a draft is pending, then drop `?review=1` with a history replace). `ResourceEditPage` now uses both; its behaviour is unchanged and its existing pins (`ResourceEditPage.detailTabs-36901`) pass on the shared hook. - **The matrix honours `?review=1`.** `PermissionMatrixEditPage` uses the same hook and sheet. That covers Studio's `StudioPermissionSetPage` (which embeds the matrix, package leg) and the routed matrix on the cross-package leg, where both producers' links land (`/studio/~all/metadata/permission/NAME?review=1`, through Setup's metadata redirect). - At the arrival the matrix reads the pending draft and the published set on their own, at the matrix's layered address (`layeredPackageId`: the page's package, else the route's `?package=`), else by name alone, as the generic page reads a draft. The matrix's own load is not asked again, so an unsaved matrix edit is kept, and the matrix stays editable under the sheet and after it closes. - No pending draft: no review opens, and `?review=1` still leaves the address. No published set readable: no review (nothing to compare against). - Without `?review=1` the matrix reads exactly what it read before. - **Address.** `?review=1` is dropped the way the generic page drops it; `AreaItemOpen` decides its page once per item (`StudioMetadataArea.tsx`), so dropping the query does not move the set off its matrix page. No routing changed. - **Not changed:** the two producers (`PackagesPage.tsx`, `AppContent.tsx`), the flow and object review links, `StudioMetadataArea.tsx`, server, spec and routes. No locale key added. Changeset: `.changeset/37269-permission-set-review-link.md` (`@object-ui/app-shell` patch). ### Read first (by risk) 1. `ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx`, the new block above `const [draft, setDraft]`: the arrival's own draft and published read, and the sheet added to `dialogsEl`. 2. `ui/packages/app-shell/src/views/metadata-admin/useDraftReviewArrival.ts`: the arrival effect moved out of `ResourceEditPage`; callbacks are read through a ref refreshed in an effect that runs before the arrival effect. 3. `ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx`: the inline effect and sheet replaced by the shared hook and component. ### Two-minute verification On a showcase dev server, open Setup, then Packages, then a package with a pending permission-set draft, and click that draft's link. Expected: Studio opens the set's matrix with a right-hand sheet titled "Draft review" listing the changed keys, and the address no longer carries `review=1`. ## Tests New pins, all at head of this branch: - `StudioPermissionSetPage.fullScreen-36905.test.tsx`, new top-level `describe` (the real Studio page and matrix): - `?review=1` shows the draft's change against the published set (only `label` differs), read at the page's package, then leaves the address; - editing stays: Escape closes the review onto the matrix, whose bulk buttons are enabled; - CONTROL: without `?review=1`, a set with a pending draft opens no review, and the matrix's load is the only draft read. - `permissionReviewLinks-37269.test.tsx` (new; the real `PackageDetailSheet`, the real `StudioMetadataArea` on the cross-package leg, the real matrix registered as the type's `EditPage`): - the Packages page's per-draft link (href asserted, then clicked) reaches the matrix with the review shown, the matrix cells enabled, the draft read by name; - the chat's 「Review N change(s)」 (`setupMetadataStudioPath(item, 'review=1')`, as `DraftReviewNavigator` calls it) reaches the same; - CONTROL: the same page without `?review=1` opens no review and reads no draft; - a set with no pending draft opens no review, and `?review=1` still leaves the address. - Unchanged and green: the flow and object review links (`StudioMetadataArea.routes-28561`), the generic page's review (`ResourceEditPage.detailTabs-36901`), the redirect tables (`setupMetadataRedirect`, `AppContent.setupMetadataStudio-28578`). <details><summary>Runs (head f781168)</summary> - `@object-ui/app-shell` `type-check` (both programs, `tsc --noEmit` and `tsconfig.test.json`): os-verify-lock `VERDICT command-exit 0` (at the feature commit; the later refactor commit only moved the hook to its own module, and `eslint` on the moved files is clean). - The new pins plus every suite that reads `?review=1` or the review panel (11 files): `Test Files 11 passed (11)`, `Tests 281 passed (281)`, `VERDICT command-exit 0`. - Every `ResourceEditPage.*`, `PermissionMatrixEditor.*` and `StudioPermissionSetPage.*` suite (113 files): `Test Files 113 passed (113)`, `Tests 664 passed (664)`, `VERDICT command-exit 0`. - `eslint` on the changed files: 0 errors; no warning on a changed line. </details> <details><summary>Ablations (one per pin, each through scripts/ablation-replace.mjs, restored to the HEAD blob with git diff HEAD empty)</summary> | Mutation | Result | | --- | --- | | matrix arrival off (`enabled: true` to `false` in `PermissionMatrixEditor.tsx`) | 5 red: both Studio review pins, both producer pins, the no-draft address pin; both CONTROLs green | | arrival ignores the param (`useDraftReviewArrival.ts`) | 3 red: both CONTROLs (Studio, cross-package leg), plus one detailTabs case | | generic page arrival off (`ResourceEditPage.tsx`) | 2 red: detailTabs `?review=1 opens the review and is consumed`, and its CONTROL | | `?review=1` kept in the address (`useDraftReviewArrival.ts`) | 6 red: the generic page's two, the Studio address pin, both producer pins, the no-draft address pin | | area never asks the generic page (`StudioMetadataArea.tsx`) | 2 red: the object CONTROL and the flow review case in `routes-28561` | Each leg ran the four suites (`StudioPermissionSetPage.fullScreen-36905`, `permissionReviewLinks-37269`, `ResourceEditPage.detailTabs-36901`, `StudioMetadataArea.routes-28561`; 76 tests) under the lock; each mutation landed (anchor 1 to 0) and was restored to its HEAD blob. </details> ## Acceptance notes - The matrix offers no chip to reopen the review once it is closed (the generic page has its header chip). The card asks for the arrival only; a reopen affordance on the matrix header would be a separate UX change. - On the cross-package leg the matrix shows the published set (it has no package to read a draft at), while the review sheet shows the pending draft read by name. That is the matrix's existing behaviour on that leg; the sheet is what says what the draft changes. - The arrival reads afresh at every `?review=1`, as the generic page does; unlike the generic page it does not reload the editor, so a same-item arrival keeps unsaved matrix edits. ## Verification Local, on `f781168f` (exit code read before any pipe): - `pnpm check:test-source-alias`: exit 0. - `pnpm --dir ui check:i18n-keys`: exit 0. - `node scripts/pm/overlap-check.mjs`: exit 0 (`VERDICT clean`; no open PR shares a file). With `--pr=37341,37338`: exit 0, both merge cleanly. The `claude/issue-37236-*` and `claude/issue-37237-*` branches share no file with this diff. - `node scripts/pm/dispatch-gates.mjs --commands` derived 39 commands. At the time of writing 28 had run locally: 27 exit 0 (the changeset gates, `check:nul-bytes`, `check:cross-package-test-inputs`, `check:adr-anchors`, `check:published-files`, `check:sdui-manifest` among them), and `check:query-options-erasure` hit the local 300 s wrapper timeout (exit 124): NOT MEASURED locally, left to CI. The rest, and `pnpm --dir ui exec vitest run scripts/` (this diff touches no script), are left to CI. CI: in progress at the time of writing. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYnq7io51czLb81MZMd)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 80da086 commit d5ae7a4

7 files changed

Lines changed: 505 additions & 51 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(studio): a permission set's review link shows what its draft changes
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A review link on a permission-set draft opened the set's matrix page with nothing on it saying what the draft changed. Two places write such a link: the Packages page's list of a package's pending drafts, and the chat's 「Review N change(s)」 button. Both now open the matrix with the draft review the other metadata pages show: a side sheet listing what the pending draft adds, changes and removes against the published set. Studio's permission-set page opens it the same way. The matrix stays editable under the sheet and after it closes, and the link's `?review=1` leaves the address once the review is open, so a refresh or Back does not open it again.
11+
12+
A set with no pending draft opens no review, and a permission-set page opened without a review link reads and shows exactly what it did before. The review links of flows, objects and every other type are unchanged. No locale keys, props or entry exports change.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The draft review (ADR-0033 Phase B) as an item page opens it: the sheet that
5+
* shows a pending draft's change against the published item
6+
* ({@link DraftReviewPanel}), and the `?review=1` arrival that opens it.
7+
*
8+
* One presentation for every item page that honours a review link: the generic
9+
* item page (`ResourceEditPage`) and the permission set's matrix
10+
* (`PermissionMatrixEditPage`, Studio's page and the routed one,
11+
* objectstack#37269). Both producers of a review link write `?review=1` for any
12+
* draft item: the Packages page's per-draft link and the chat's 「Review N
13+
* change(s)」.
14+
*/
15+
16+
import * as React from 'react';
17+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '@object-ui/components';
18+
import { DraftReviewPanel } from './DraftReviewPanel.js';
19+
import { t, type SupportedLocale } from './i18n.js';
20+
21+
export interface DraftReviewSheetProps {
22+
open: boolean;
23+
onOpenChange: (open: boolean) => void;
24+
type: string;
25+
name: string;
26+
/** The published (effective) item: the baseline. `null` for an item never published. */
27+
published: unknown;
28+
/** The pending draft's body. */
29+
draft: unknown;
30+
locale?: SupportedLocale | string;
31+
}
32+
33+
/** The generic draft↔published review, in a right-hand sheet over the item page. */
34+
export function DraftReviewSheet({
35+
open,
36+
onOpenChange,
37+
type,
38+
name,
39+
published,
40+
draft,
41+
locale,
42+
}: DraftReviewSheetProps): React.ReactElement {
43+
return (
44+
<Sheet open={open} onOpenChange={onOpenChange}>
45+
<SheetContent side="right" className="w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0">
46+
<SheetHeader className="px-4 py-3 border-b">
47+
<SheetTitle className="text-base">{t('designer.draftReview.title', locale)}</SheetTitle>
48+
<SheetDescription className="text-xs">
49+
{type} / {name} · {t('designer.canvas.reviewVsPublished', locale)}
50+
</SheetDescription>
51+
</SheetHeader>
52+
<div className="flex-1 min-h-0 overflow-auto p-4">
53+
<DraftReviewPanel published={published} draft={draft} locale={locale} />
54+
</div>
55+
</SheetContent>
56+
</Sheet>
57+
);
58+
}

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ import { HistoryPanel } from '../item-tools/ResourceHistoryPage.js';
9393
import { useMetadataClient, useMetadataTypes, type RichMetadataTypeEntry } from './useMetadata.js';
9494
// objectui#11773 — the package door's draft save sends the version it was built on.
9595
import { readDraftForSave, useDraftSaveGuard } from './DraftConflictDialog.js';
96+
import { DraftReviewSheet } from './DraftReviewSheet.js';
97+
import { useDraftReviewArrival } from './useDraftReviewArrival.js';
9698
// objectstack#26858 — the served verdict the RLS clause editors read at their paths.
9799
import {
98100
DraftVerdictBodyContext,
@@ -922,6 +924,55 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
922924
[locale, catalogueResident],
923925
);
924926

927+
// objectstack#37269 — a review link (`?review=1`: the Packages page's
928+
// per-draft link, the chat's 「Review N change(s)」) opens the draft review
929+
// here, the generic item page's (`useDraftReviewArrival`, `DraftReviewSheet`):
930+
// a set's item page is this editor, on Studio's page and the routed one alike.
931+
// Read on its own at the arrival, the pending draft and the published set, at
932+
// the address the load reads (the page's package, else the route's, else the
933+
// name alone, as the generic page reads it). The matrix's load is not asked
934+
// again, so an unsaved edit it holds stays, and editing stays open under the
935+
// sheet.
936+
const [reviewRead, setReviewRead] = React.useState<{ published: unknown; draft: PermissionSetDraft } | null>(null);
937+
const [reviewReading, setReviewReading] = React.useState(false);
938+
const [reviewReadNonce, setReviewReadNonce] = React.useState(0);
939+
const [reviewOpen, setReviewOpen] = React.useState(false);
940+
React.useEffect(() => {
941+
if (reviewReadNonce === 0) return undefined;
942+
let cancelled = false;
943+
Promise.all([
944+
readDraftForSave<{ item?: PermissionSetDraft } | PermissionSetDraft>(client, type, name, layeredPackageId),
945+
client.layered<PermissionSetDraft>(type, name, layeredPackageId ? { packageId: layeredPackageId } : {}),
946+
]).then(
947+
([pending, lay]) => {
948+
if (cancelled) return;
949+
const body = pendingDraftBody(pending.answer ?? null);
950+
setReviewRead(body ? { published: lay?.effective ?? null, draft: body } : null);
951+
setReviewReading(false);
952+
},
953+
// An unread published set is no baseline: nothing to compare, no review.
954+
() => {
955+
if (cancelled) return;
956+
setReviewRead(null);
957+
setReviewReading(false);
958+
},
959+
);
960+
return () => {
961+
cancelled = true;
962+
};
963+
// eslint-disable-next-line react-hooks/exhaustive-deps -- read once per arrival; the item is the nonce's
964+
}, [reviewReadNonce]);
965+
useDraftReviewArrival({
966+
enabled: true,
967+
loading: reviewReading,
968+
hasDraft: reviewRead !== null,
969+
reload: () => {
970+
setReviewReading(true);
971+
setReviewReadNonce((n) => n + 1);
972+
},
973+
open: () => setReviewOpen(true),
974+
});
975+
925976
const [draft, setDraft] = React.useState<PermissionSetDraft>({
926977
name,
927978
objects: {},
@@ -2442,6 +2493,18 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
24422493
</SheetContent>
24432494
</Sheet>
24442495
)}
2496+
{/* objectstack#37269 — the draft review a `?review=1` link opens. */}
2497+
{reviewRead && (
2498+
<DraftReviewSheet
2499+
open={reviewOpen}
2500+
onOpenChange={setReviewOpen}
2501+
type={type}
2502+
name={name}
2503+
published={reviewRead.published}
2504+
draft={reviewRead.draft}
2505+
locale={locale}
2506+
/>
2507+
)}
24452508
{draftConflictDialog}
24462509
</>
24472510
);

‎ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx‎

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ import {
4848
import { toast } from 'sonner';
4949
import { Button } from '@object-ui/components';
5050
import { Badge } from '@object-ui/components';
51-
import {
52-
Sheet,
53-
SheetContent,
54-
SheetHeader,
55-
SheetTitle,
56-
SheetDescription,
57-
} from '@object-ui/components';
5851
import {
5952
ResizableHandle,
6053
ResizablePanel,
@@ -96,7 +89,9 @@ import {
9689
type ItemToolTab,
9790
} from '../item-tools/ItemToolTabs.js';
9891
import { MetadataTypeActions } from './MetadataTypeActions.js';
99-
import { DraftReviewPanel, computeDraftChangeCount } from './DraftReviewPanel.js';
92+
import { computeDraftChangeCount } from './DraftReviewPanel.js';
93+
import { DraftReviewSheet } from './DraftReviewSheet.js';
94+
import { useDraftReviewArrival } from './useDraftReviewArrival.js';
10095
import {
10196
SchemaForm,
10297
DRAWER_METADATA_ID_SCOPE,
@@ -684,7 +679,7 @@ function MetadataResourceEditPageImpl({
684679
embedded,
685680
}: MetadataResourceEditPageImplProps) {
686681
const navigate = useNavigate();
687-
const [searchParams, setSearchParams] = useSearchParams();
682+
const [searchParams] = useSearchParams();
688683
// ADR-0048 — the owning package of the item being edited, carried on the
689684
// edit URL as `?package=` (emitted by the metadata list links). Scopes the
690685
// layered/draft read so a same-name collision resolves to the right
@@ -1628,30 +1623,17 @@ function MetadataResourceEditPageImpl({
16281623
// The draft review is the header's status chip (decision 8), opened here.
16291624
const [reviewOpen, setReviewOpen] = React.useState(false);
16301625

1631-
// ADR-0033 Phase B — `?review=1` arrival (from the chat's "Review N change(s)"
1632-
// affordance). The AI may have drafted this item *after* the page mounted, so
1633-
// we first force a fresh fetch, then — once the draft is loaded — open the
1634-
// generic review/diff sheet and consume the query param (so a refresh/back
1635-
// doesn't re-trigger it). The same-item-already-open case is covered by the
1636-
// reload bump (the load effect keys off `reloadKey`, not the search string).
1637-
const reviewParam = searchParams.get('review');
1638-
const reviewBumpedRef = React.useRef(false);
1639-
React.useEffect(() => {
1640-
if (reviewParam !== '1' || createMode) return;
1641-
if (!reviewBumpedRef.current) {
1642-
reviewBumpedRef.current = true;
1643-
setReloadKey((k) => k + 1);
1644-
return; // wait for the reload to settle before reading hasDraft
1645-
}
1646-
if (!loading) {
1647-
if (hasDraft) setReviewOpen(true);
1648-
const next = new URLSearchParams(searchParams);
1649-
next.delete('review');
1650-
setSearchParams(next, { replace: true });
1651-
reviewBumpedRef.current = false;
1652-
}
1653-
// eslint-disable-next-line react-hooks/exhaustive-deps
1654-
}, [reviewParam, createMode, loading, hasDraft]);
1626+
// ADR-0033 Phase B — `?review=1` arrival (the chat's "Review N change(s)"
1627+
// and the Packages page's per-draft link): read the item afresh, then open
1628+
// the review once the draft is loaded, and drop the query param
1629+
// (`useDraftReviewArrival`, shared with the permission set's matrix).
1630+
useDraftReviewArrival({
1631+
enabled: !createMode,
1632+
loading,
1633+
hasDraft,
1634+
reload: () => setReloadKey((k) => k + 1),
1635+
open: () => setReviewOpen(true),
1636+
});
16551637

16561638
// Inspector tabs: properties form vs raw JSON source view. Source view
16571639
// is for power users who need to edit fields the form doesn't expose
@@ -3981,24 +3963,16 @@ function MetadataResourceEditPageImpl({
39813963

39823964
{/* ADR-0033 Phase B — generic draft↔published review/diff. Available for
39833965
ANY type whenever a pending draft exists; opened by the chat's
3984-
"Review N change(s)" affordance (?review=1) or the toolbar button. */}
3985-
<Sheet open={reviewOpen} onOpenChange={setReviewOpen}>
3986-
<SheetContent side="right" className="w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0">
3987-
<SheetHeader className="px-4 py-3 border-b">
3988-
<SheetTitle className="text-base">{t('designer.draftReview.title', locale)}</SheetTitle>
3989-
<SheetDescription className="text-xs">
3990-
{type} / {name} · {t('designer.canvas.reviewVsPublished', locale)}
3991-
</SheetDescription>
3992-
</SheetHeader>
3993-
<div className="flex-1 min-h-0 overflow-auto p-4">
3994-
<DraftReviewPanel
3995-
published={layered?.effective ?? null}
3996-
draft={draft}
3997-
locale={locale}
3998-
/>
3999-
</div>
4000-
</SheetContent>
4001-
</Sheet>
3966+
"Review N change(s)" affordance (?review=1) or the header's chip. */}
3967+
<DraftReviewSheet
3968+
open={reviewOpen}
3969+
onOpenChange={setReviewOpen}
3970+
type={type}
3971+
name={name}
3972+
published={layered?.effective ?? null}
3973+
draft={draft}
3974+
locale={locale}
3975+
/>
40023976

40033977
<MetadataDetailDrawer
40043978
target={relatedTarget}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The `?review=1` arrival of an item page (ADR-0033 Phase B): the link the
5+
* chat's 「Review N change(s)」 and the Packages page's per-draft link write
6+
* for any draft item. It opens the page's draft review (`DraftReviewSheet`).
7+
* Shared by the generic item page (`ResourceEditPage`) and the permission
8+
* set's matrix (`PermissionMatrixEditPage`, objectstack#37269), so a review
9+
* link reads the same on both.
10+
*/
11+
12+
import * as React from 'react';
13+
import { useSearchParams } from 'react-router-dom';
14+
15+
/** The query a review link carries: `?review=1`. */
16+
export const DRAFT_REVIEW_PARAM = 'review';
17+
export const DRAFT_REVIEW_VALUE = '1';
18+
19+
export interface DraftReviewArrivalInput {
20+
/** Off (a create draft) ⇒ the address's `?review=1` is left alone. */
21+
enabled: boolean;
22+
/** The read `reload` started is still in flight. */
23+
loading: boolean;
24+
/** The read found a pending draft. */
25+
hasDraft: boolean;
26+
/** Read the item afresh: the draft may have been written after the page mounted. */
27+
reload: () => void;
28+
/** Open the review. */
29+
open: () => void;
30+
}
31+
32+
/**
33+
* ADR-0033 Phase B — a `?review=1` arrival. The draft may have been written
34+
* after the page mounted (the AI drafted it), so the page first reads the item
35+
* afresh; once that read settles it opens the review when a draft is pending,
36+
* and drops `?review=1` from the address (replacing the history entry), so a
37+
* refresh or Back does not open it again. The same-item-already-open case is
38+
* covered too: the fresh read is asked whatever the page already holds.
39+
*/
40+
export function useDraftReviewArrival({ enabled, loading, hasDraft, reload, open }: DraftReviewArrivalInput): void {
41+
const [searchParams, setSearchParams] = useSearchParams();
42+
const reviewParam = searchParams.get(DRAFT_REVIEW_PARAM);
43+
// The latest callbacks and query, for the arrival effect below; refreshed
44+
// in an effect of their own, which runs before it.
45+
const latest = React.useRef({ reload, open, searchParams, setSearchParams });
46+
React.useEffect(() => {
47+
latest.current = { reload, open, searchParams, setSearchParams };
48+
});
49+
const reloadAskedRef = React.useRef(false);
50+
React.useEffect(() => {
51+
if (reviewParam !== DRAFT_REVIEW_VALUE || !enabled) return;
52+
if (!reloadAskedRef.current) {
53+
reloadAskedRef.current = true;
54+
latest.current.reload();
55+
return; // wait for the fresh read to settle before reading hasDraft
56+
}
57+
if (!loading) {
58+
if (hasDraft) latest.current.open();
59+
const next = new URLSearchParams(latest.current.searchParams);
60+
next.delete(DRAFT_REVIEW_PARAM);
61+
latest.current.setSearchParams(next, { replace: true });
62+
reloadAskedRef.current = false;
63+
}
64+
}, [reviewParam, enabled, loading, hasDraft]);
65+
}

‎ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.fullScreen-36905.test.tsx‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,47 @@ describe('the sharing chip asks before it leaves a dirty matrix (objectstack#369
549549
expect(window.confirm).not.toHaveBeenCalled();
550550
});
551551
});
552+
553+
// objectstack#37269 — a review link (`?review=1`) on a set's page opens the
554+
// draft review the generic item page opens (`DraftReviewSheet`): the set's
555+
// pending draft against the published set, with `?review=1` dropped once it is
556+
// open and the matrix still editable under it.
557+
describe('a review link opens the draft review on the matrix (objectstack#37269)', () => {
558+
const reviewPanel = () => screen.findByTestId('draft-review-panel', undefined, { timeout: 8000 });
559+
const SET_ADDRESS = `/studio/${CUSTOM_PKG}/metadata/permission/${SET}?package=${CUSTOM_PKG}`;
560+
561+
it('`?review=1` shows what the draft changes against the published set, then leaves the address', async () => {
562+
clientImpl = makeClient([SET], draftOf('studio'));
563+
mount(CUSTOM_PKG, '&review=1');
564+
const panel = await reviewPanel();
565+
// BODY is the published set; the draft relabels it, and nothing else.
566+
expect(within(panel).getByText('label')).toBeInTheDocument();
567+
expect(within(panel).getByText('Sales rep (AI)')).toBeInTheDocument();
568+
expect(within(panel).queryByText('objects')).toBeNull();
569+
expect(screen.getByText(en('designer.draftReview.title'))).toBeInTheDocument();
570+
// Read at the page's package, as the matrix's own load reads it.
571+
expect(clientImpl.layered).toHaveBeenCalledWith('permission', SET, { packageId: CUSTOM_PKG });
572+
await waitFor(() => expect(where()).toBe(SET_ADDRESS));
573+
});
574+
575+
it('editing stays: the review closes onto the matrix, whose rows still take an edit', async () => {
576+
clientImpl = makeClient([SET], draftOf('studio'));
577+
mount(CUSTOM_PKG, '&review=1');
578+
await reviewPanel();
579+
fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' });
580+
await waitFor(() => expect(screen.queryByTestId('draft-review-panel')).toBeNull());
581+
const bulk = await screen.findByTestId('perm-bulk-crm_lead');
582+
for (const button of within(bulk).getAllByRole('button')) expect(button).toBeEnabled();
583+
});
584+
585+
it('CONTROL: without `?review=1` a set with a pending draft opens no review', async () => {
586+
clientImpl = makeClient([SET], draftOf('studio'));
587+
mount(CUSTOM_PKG);
588+
await screen.findByTestId('perm-row-crm_lead', undefined, { timeout: 8000 });
589+
expect(screen.queryByTestId('draft-review-panel')).toBeNull();
590+
expect(screen.queryByText(en('designer.draftReview.title'))).toBeNull();
591+
// The matrix's own load is the one draft read: no review read was asked.
592+
expect(clientImpl.getDraft).toHaveBeenCalledTimes(1);
593+
expect(where()).toBe(SET_ADDRESS);
594+
});
595+
});

0 commit comments

Comments
 (0)