@@ -378,6 +378,28 @@ export type NewViewPayload = Parameters<CreateViewDialogProps['onCreate']>[0];
378378/** Why "Add view" saved nothing: a view already holds the name, or the save failed. */
379379export type ViewCreateRefusal = { taken : string } | { error : unknown } ;
380380
381+ /**
382+ * objectstack#28562 (ADR-0146 D2) — where a read-only base's list view is
383+ * customized: read in the base's paired customization package, written there
384+ * as an override of the base's view. The Interfaces pillar passes it on a
385+ * read-only base only; without it the view is read and written at `packageId`.
386+ */
387+ export interface ListViewCustomization {
388+ /**
389+ * The package the view's draft is read in when a load runs: the pair when
390+ * the package list lists one, else `null` (the view is then read at
391+ * `packageId`, where no pair draft can be). Asked at load time, so a pair
392+ * the first save creates is never a reason to reload the buffer it saved.
393+ */
394+ readAt : ( ) => string | null ;
395+ /**
396+ * The write: the package the save addresses (the ensure door's answer) and
397+ * the body it sends (the view, declaring the override). Rejects with the
398+ * door's refusal, and then nothing is saved.
399+ */
400+ writeTarget : ( viewId : string , row : Row ) => Promise < { packageId : string ; body : Row } > ;
401+ }
402+
381403/**
382404 * The open leaf's list-view buffer, held by the Interfaces pillar so the
383405 * canvas and the panel read one copy (the folded layout unmounts the panel
@@ -391,6 +413,7 @@ export function useObjectListViewDraft({
391413 publishNonce,
392414 draftOnlyObjects,
393415 onDraftSaved,
416+ customization = null ,
394417} : {
395418 client : MetadataClient ;
396419 packageId : string ;
@@ -403,6 +426,12 @@ export function useObjectListViewDraft({
403426 */
404427 draftOnlyObjects ?: DraftOnlyObjects | null ;
405428 onDraftSaved ?: ( ) => void ;
429+ /**
430+ * objectstack#28562 — on a read-only base, where the view is customized
431+ * ({@link ListViewCustomization}). Read through a ref: only its presence is
432+ * a reason to load again.
433+ */
434+ customization ?: ListViewCustomization | null ;
406435} ) : ObjectListViewDraft {
407436 const metadata = useMetadata ( ) ;
408437 const { user, activeOrganization } = useAuth ( ) ;
@@ -494,6 +523,16 @@ export function useObjectListViewDraft({
494523 React . useEffect ( ( ) => {
495524 draftOnlyRef . current = draftOnlyObjects ;
496525 } , [ draftOnlyObjects ] ) ;
526+ // objectstack#28562 — read when a load or a save runs; `customizing` is
527+ // the one fact of it a load is keyed on.
528+ const customizationRef = React . useRef ( customization ) ;
529+ React . useLayoutEffect ( ( ) => {
530+ customizationRef . current = customization ;
531+ } ) ;
532+ const customizing = customization !== null ;
533+ // objectstack#28562 — the view and package the installed buffer's draft
534+ // read was asked at: the address its pin describes.
535+ const readAtRef = React . useRef < { viewId : string ; at : string } | null > ( null ) ;
497536
498537 React . useEffect ( ( ) => {
499538 setFailure ( null ) ;
@@ -505,8 +544,10 @@ export function useObjectListViewDraft({
505544 ( async ( ) => {
506545 try {
507546 // objectui#11773 — read at the address the save below writes, so the
508- // version it serves pins that save.
509- const draftRead = await readDraftForSave < Row > ( client , 'view' , viewId , packageId ) ;
547+ // version it serves pins that save. objectstack#28562 — on a
548+ // read-only base that is the pair, when one is listed.
549+ const readAt = customizationRef . current ?. readAt ( ) ?? packageId ;
550+ const draftRead = await readDraftForSave < Row > ( client , 'view' , viewId , readAt ) ;
510551 if ( cancelled ) return ;
511552 const draftResp = draftRead . answer ;
512553 // A served draft is the whole document, taken as-is (objectui#10765);
@@ -558,7 +599,8 @@ export function useObjectListViewDraft({
558599 ? publishedRow
559600 : undefined ;
560601 // objectui#11773 — the next save is pinned to what the draft read served.
561- recordRead ( 'view' , viewId , packageId , draftRead . pin ) ;
602+ recordRead ( 'view' , viewId , readAt , draftRead . pin ) ;
603+ readAtRef . current = { viewId, at : readAt } ;
562604 setBuffer ( {
563605 for : listViewBufferKey ( viewId ) ,
564606 row,
@@ -574,7 +616,7 @@ export function useObjectListViewDraft({
574616 return ( ) => {
575617 cancelled = true ;
576618 } ;
577- } , [ client , viewId , objectName , packageId , publishNonce , reloadNonce , recordRead ] ) ;
619+ } , [ client , viewId , objectName , packageId , publishNonce , reloadNonce , recordRead , customizing ] ) ;
578620
579621 const edit = React . useCallback ( ( row : Row ) => {
580622 setBuffer ( ( b ) => ( { ...b , row, dirty : true } ) ) ;
@@ -618,7 +660,24 @@ export function useObjectListViewDraft({
618660 if ( ! viewId || ! row || notList ) return ;
619661 setSaving ( true ) ;
620662 try {
621- const outcome = await guardedSave ( 'view' , viewId , row , { mode : 'draft' , packageId, surface : 'studio' } ) ;
663+ // objectstack#28562 — a customization is written where the ensure
664+ // door says, with its declaration; a refused door saves nothing.
665+ const custom = customizationRef . current ;
666+ const target = custom ? await custom . writeTarget ( viewId , row ) : { packageId, body : row } ;
667+ // The buffer was read at another package (the base, before its pair
668+ // was listed): the pair is taken to hold no draft of the view, so a
669+ // draft there is a conflict the author is asked about, never one
670+ // this save overwrites. Its receipt pins the saves after it.
671+ const readAt = readAtRef . current ;
672+ if ( custom && ! ( readAt ?. viewId === viewId && readAt . at === target . packageId ) ) {
673+ recordRead ( 'view' , viewId , target . packageId , { ifNoneMatch : '*' } ) ;
674+ readAtRef . current = { viewId, at : target . packageId } ;
675+ }
676+ const outcome = await guardedSave ( 'view' , viewId , target . body , {
677+ mode : 'draft' ,
678+ packageId : target . packageId ,
679+ surface : 'studio' ,
680+ } ) ;
622681 // objectui#11773 — the author chose the saved version; the load replaces the buffer.
623682 if ( outcome === 'reloaded' ) return ;
624683 // objectui#11204 — clean only if nothing was edited while it was in flight.
@@ -632,7 +691,7 @@ export function useObjectListViewDraft({
632691 setSaving ( false ) ;
633692 }
634693 } ,
635- [ guardedSave , viewId , row , notList , packageId , onDraftSaved ] ,
694+ [ guardedSave , recordRead , viewId , row , notList , packageId , onDraftSaved ] ,
636695 ) ;
637696
638697 const current = buffer . for === targetKey && targetKey !== '' ;
@@ -1057,6 +1116,7 @@ function KanbanCardSection({
10571116export function ObjectListViewInspector ( {
10581117 listView,
10591118 readOnly,
1119+ canCreate = ! readOnly ,
10601120 locale,
10611121 selection,
10621122 onSelectionChange,
@@ -1065,6 +1125,12 @@ export function ObjectListViewInspector({
10651125} : {
10661126 listView : ObjectListViewDraft ;
10671127 readOnly : boolean ;
1128+ /**
1129+ * objectstack#28562 — whether "Add view" is offered; `!readOnly` by default.
1130+ * A read-only base's view is customized in its pair, while a new view would
1131+ * be a new item in the base, which it does not take.
1132+ */
1133+ canCreate ?: boolean ;
10681134 locale : string ;
10691135 /**
10701136 * objectstack#27836 — called as "Add view" opens its dialog: the host sends
@@ -1320,7 +1386,7 @@ export function ObjectListViewInspector({
13201386 variant = "outline"
13211387 size = "sm"
13221388 className = "h-7 gap-1 text-xs"
1323- disabled = { readOnly || fieldState . loading || ! ! fieldState . error }
1389+ disabled = { ! canCreate || fieldState . loading || ! ! fieldState . error }
13241390 onClick = { ( ) => {
13251391 onAddViewOpen ?.( ) ;
13261392 setAddOpen ( true ) ;
0 commit comments