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
12 changes: 12 additions & 0 deletions .changeset/37269-permission-set-review-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/app-shell': patch
---

fix(studio): a permission set's review link shows what its draft changes

Clause-②: no
Metadata-protocol: none

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.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The draft review (ADR-0033 Phase B) as an item page opens it: the sheet that
* shows a pending draft's change against the published item
* ({@link DraftReviewPanel}), and the `?review=1` arrival that opens it.
*
* One presentation for every item page that honours a review link: the generic
* item page (`ResourceEditPage`) and the permission set's matrix
* (`PermissionMatrixEditPage`, Studio's page and the routed one,
* objectstack#37269). Both producers of a review link write `?review=1` for any
* draft item: the Packages page's per-draft link and the chat's 「Review N
* change(s)」.
*/

import * as React from 'react';
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '@object-ui/components';
import { DraftReviewPanel } from './DraftReviewPanel.js';
import { t, type SupportedLocale } from './i18n.js';

export interface DraftReviewSheetProps {
open: boolean;
onOpenChange: (open: boolean) => void;
type: string;
name: string;
/** The published (effective) item: the baseline. `null` for an item never published. */
published: unknown;
/** The pending draft's body. */
draft: unknown;
locale?: SupportedLocale | string;
}

/** The generic draft↔published review, in a right-hand sheet over the item page. */
export function DraftReviewSheet({
open,
onOpenChange,
type,
name,
published,
draft,
locale,
}: DraftReviewSheetProps): React.ReactElement {
return (
<Sheet open={open} onOpenChange={onOpenChange}>
<SheetContent side="right" className="w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0">
<SheetHeader className="px-4 py-3 border-b">
<SheetTitle className="text-base">{t('designer.draftReview.title', locale)}</SheetTitle>
<SheetDescription className="text-xs">
{type} / {name} · {t('designer.canvas.reviewVsPublished', locale)}
</SheetDescription>
</SheetHeader>
<div className="flex-1 min-h-0 overflow-auto p-4">
<DraftReviewPanel published={published} draft={draft} locale={locale} />
</div>
</SheetContent>
</Sheet>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ import { HistoryPanel } from '../item-tools/ResourceHistoryPage.js';
import { useMetadataClient, useMetadataTypes, type RichMetadataTypeEntry } from './useMetadata.js';
// objectui#11773 — the package door's draft save sends the version it was built on.
import { readDraftForSave, useDraftSaveGuard } from './DraftConflictDialog.js';
import { DraftReviewSheet } from './DraftReviewSheet.js';
import { useDraftReviewArrival } from './useDraftReviewArrival.js';
// objectstack#26858 — the served verdict the RLS clause editors read at their paths.
import {
DraftVerdictBodyContext,
Expand Down Expand Up @@ -922,6 +924,55 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
[locale, catalogueResident],
);

// objectstack#37269 — a review link (`?review=1`: the Packages page's
// per-draft link, the chat's 「Review N change(s)」) opens the draft review
// here, the generic item page's (`useDraftReviewArrival`, `DraftReviewSheet`):
// a set's item page is this editor, on Studio's page and the routed one alike.
// Read on its own at the arrival, the pending draft and the published set, at
// the address the load reads (the page's package, else the route's, else the
// name alone, as the generic page reads it). The matrix's load is not asked
// again, so an unsaved edit it holds stays, and editing stays open under the
// sheet.
const [reviewRead, setReviewRead] = React.useState<{ published: unknown; draft: PermissionSetDraft } | null>(null);
const [reviewReading, setReviewReading] = React.useState(false);
const [reviewReadNonce, setReviewReadNonce] = React.useState(0);
const [reviewOpen, setReviewOpen] = React.useState(false);
React.useEffect(() => {
if (reviewReadNonce === 0) return undefined;
let cancelled = false;
Promise.all([
readDraftForSave<{ item?: PermissionSetDraft } | PermissionSetDraft>(client, type, name, layeredPackageId),
client.layered<PermissionSetDraft>(type, name, layeredPackageId ? { packageId: layeredPackageId } : {}),
]).then(
([pending, lay]) => {
if (cancelled) return;
const body = pendingDraftBody(pending.answer ?? null);
setReviewRead(body ? { published: lay?.effective ?? null, draft: body } : null);
setReviewReading(false);
},
// An unread published set is no baseline: nothing to compare, no review.
() => {
if (cancelled) return;
setReviewRead(null);
setReviewReading(false);
},
);
return () => {
cancelled = true;
};
// eslint-disable-next-line react-hooks/exhaustive-deps -- read once per arrival; the item is the nonce's
}, [reviewReadNonce]);
useDraftReviewArrival({
enabled: true,
loading: reviewReading,
hasDraft: reviewRead !== null,
reload: () => {
setReviewReading(true);
setReviewReadNonce((n) => n + 1);
},
open: () => setReviewOpen(true),
});

const [draft, setDraft] = React.useState<PermissionSetDraft>({
name,
objects: {},
Expand Down Expand Up @@ -2442,6 +2493,18 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
</SheetContent>
</Sheet>
)}
{/* objectstack#37269 — the draft review a `?review=1` link opens. */}
{reviewRead && (
<DraftReviewSheet
open={reviewOpen}
onOpenChange={setReviewOpen}
type={type}
name={name}
published={reviewRead.published}
draft={reviewRead.draft}
locale={locale}
/>
)}
{draftConflictDialog}
</>
);
Expand Down
76 changes: 25 additions & 51 deletions ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ import {
import { toast } from 'sonner';
import { Button } from '@object-ui/components';
import { Badge } from '@object-ui/components';
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetDescription,
} from '@object-ui/components';
import {
ResizableHandle,
ResizablePanel,
Expand Down Expand Up @@ -96,7 +89,9 @@ import {
type ItemToolTab,
} from '../item-tools/ItemToolTabs.js';
import { MetadataTypeActions } from './MetadataTypeActions.js';
import { DraftReviewPanel, computeDraftChangeCount } from './DraftReviewPanel.js';
import { computeDraftChangeCount } from './DraftReviewPanel.js';
import { DraftReviewSheet } from './DraftReviewSheet.js';
import { useDraftReviewArrival } from './useDraftReviewArrival.js';
import {
SchemaForm,
DRAWER_METADATA_ID_SCOPE,
Expand Down Expand Up @@ -684,7 +679,7 @@ function MetadataResourceEditPageImpl({
embedded,
}: MetadataResourceEditPageImplProps) {
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const [searchParams] = useSearchParams();
// ADR-0048 — the owning package of the item being edited, carried on the
// edit URL as `?package=` (emitted by the metadata list links). Scopes the
// layered/draft read so a same-name collision resolves to the right
Expand Down Expand Up @@ -1628,30 +1623,17 @@ function MetadataResourceEditPageImpl({
// The draft review is the header's status chip (decision 8), opened here.
const [reviewOpen, setReviewOpen] = React.useState(false);

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

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

{/* ADR-0033 Phase B — generic draft↔published review/diff. Available for
ANY type whenever a pending draft exists; opened by the chat's
"Review N change(s)" affordance (?review=1) or the toolbar button. */}
<Sheet open={reviewOpen} onOpenChange={setReviewOpen}>
<SheetContent side="right" className="w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0">
<SheetHeader className="px-4 py-3 border-b">
<SheetTitle className="text-base">{t('designer.draftReview.title', locale)}</SheetTitle>
<SheetDescription className="text-xs">
{type} / {name} · {t('designer.canvas.reviewVsPublished', locale)}
</SheetDescription>
</SheetHeader>
<div className="flex-1 min-h-0 overflow-auto p-4">
<DraftReviewPanel
published={layered?.effective ?? null}
draft={draft}
locale={locale}
/>
</div>
</SheetContent>
</Sheet>
"Review N change(s)" affordance (?review=1) or the header's chip. */}
<DraftReviewSheet
open={reviewOpen}
onOpenChange={setReviewOpen}
type={type}
name={name}
published={layered?.effective ?? null}
draft={draft}
locale={locale}
/>

<MetadataDetailDrawer
target={relatedTarget}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The `?review=1` arrival of an item page (ADR-0033 Phase B): the link the
* chat's 「Review N change(s)」 and the Packages page's per-draft link write
* for any draft item. It opens the page's draft review (`DraftReviewSheet`).
* Shared by the generic item page (`ResourceEditPage`) and the permission
* set's matrix (`PermissionMatrixEditPage`, objectstack#37269), so a review
* link reads the same on both.
*/

import * as React from 'react';
import { useSearchParams } from 'react-router-dom';

/** The query a review link carries: `?review=1`. */
export const DRAFT_REVIEW_PARAM = 'review';
export const DRAFT_REVIEW_VALUE = '1';

export interface DraftReviewArrivalInput {
/** Off (a create draft) ⇒ the address's `?review=1` is left alone. */
enabled: boolean;
/** The read `reload` started is still in flight. */
loading: boolean;
/** The read found a pending draft. */
hasDraft: boolean;
/** Read the item afresh: the draft may have been written after the page mounted. */
reload: () => void;
/** Open the review. */
open: () => void;
}

/**
* ADR-0033 Phase B — a `?review=1` arrival. The draft may have been written
* after the page mounted (the AI drafted it), so the page first reads the item
* afresh; once that read settles it opens the review when a draft is pending,
* and drops `?review=1` from the address (replacing the history entry), so a
* refresh or Back does not open it again. The same-item-already-open case is
* covered too: the fresh read is asked whatever the page already holds.
*/
export function useDraftReviewArrival({ enabled, loading, hasDraft, reload, open }: DraftReviewArrivalInput): void {
const [searchParams, setSearchParams] = useSearchParams();
const reviewParam = searchParams.get(DRAFT_REVIEW_PARAM);
// The latest callbacks and query, for the arrival effect below; refreshed
// in an effect of their own, which runs before it.
const latest = React.useRef({ reload, open, searchParams, setSearchParams });
React.useEffect(() => {
latest.current = { reload, open, searchParams, setSearchParams };
});
const reloadAskedRef = React.useRef(false);
React.useEffect(() => {
if (reviewParam !== DRAFT_REVIEW_VALUE || !enabled) return;
if (!reloadAskedRef.current) {
reloadAskedRef.current = true;
latest.current.reload();
return; // wait for the fresh read to settle before reading hasDraft
}
if (!loading) {
if (hasDraft) latest.current.open();
const next = new URLSearchParams(latest.current.searchParams);
next.delete(DRAFT_REVIEW_PARAM);
latest.current.setSearchParams(next, { replace: true });
reloadAskedRef.current = false;
}
}, [reviewParam, enabled, loading, hasDraft]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,47 @@ describe('the sharing chip asks before it leaves a dirty matrix (objectstack#369
expect(window.confirm).not.toHaveBeenCalled();
});
});

// objectstack#37269 — a review link (`?review=1`) on a set's page opens the
// draft review the generic item page opens (`DraftReviewSheet`): the set's
// pending draft against the published set, with `?review=1` dropped once it is
// open and the matrix still editable under it.
describe('a review link opens the draft review on the matrix (objectstack#37269)', () => {
const reviewPanel = () => screen.findByTestId('draft-review-panel', undefined, { timeout: 8000 });
const SET_ADDRESS = `/studio/${CUSTOM_PKG}/metadata/permission/${SET}?package=${CUSTOM_PKG}`;

it('`?review=1` shows what the draft changes against the published set, then leaves the address', async () => {
clientImpl = makeClient([SET], draftOf('studio'));
mount(CUSTOM_PKG, '&review=1');
const panel = await reviewPanel();
// BODY is the published set; the draft relabels it, and nothing else.
expect(within(panel).getByText('label')).toBeInTheDocument();
expect(within(panel).getByText('Sales rep (AI)')).toBeInTheDocument();
expect(within(panel).queryByText('objects')).toBeNull();
expect(screen.getByText(en('designer.draftReview.title'))).toBeInTheDocument();
// Read at the page's package, as the matrix's own load reads it.
expect(clientImpl.layered).toHaveBeenCalledWith('permission', SET, { packageId: CUSTOM_PKG });
await waitFor(() => expect(where()).toBe(SET_ADDRESS));
});

it('editing stays: the review closes onto the matrix, whose rows still take an edit', async () => {
clientImpl = makeClient([SET], draftOf('studio'));
mount(CUSTOM_PKG, '&review=1');
await reviewPanel();
fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' });
await waitFor(() => expect(screen.queryByTestId('draft-review-panel')).toBeNull());
const bulk = await screen.findByTestId('perm-bulk-crm_lead');
for (const button of within(bulk).getAllByRole('button')) expect(button).toBeEnabled();
});

it('CONTROL: without `?review=1` a set with a pending draft opens no review', async () => {
clientImpl = makeClient([SET], draftOf('studio'));
mount(CUSTOM_PKG);
await screen.findByTestId('perm-row-crm_lead', undefined, { timeout: 8000 });
expect(screen.queryByTestId('draft-review-panel')).toBeNull();
expect(screen.queryByText(en('designer.draftReview.title'))).toBeNull();
// The matrix's own load is the one draft read: no review read was asked.
expect(clientImpl.getDraft).toHaveBeenCalledTimes(1);
expect(where()).toBe(SET_ADDRESS);
});
});
Loading
Loading