Skip to content

Commit 4d90362

Browse files
committed
fix(app-shell): creating an item or opening one from Pending changes asks before it drops a held Studio edit
A Data, Automations or Interfaces pillar now asks the shared departure question before its New dialog opens while its autosave holds an edit, and the Data pillar asks before a Pending changes request opens another object in the same pillar. Declined, the held edit stays. Claude-Session: https://claude.ai/code/session_01JQwxbZTZSxa584VWULEuMZ Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 94e29cd commit 4d90362

1 file changed

Lines changed: 41 additions & 15 deletions

File tree

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx‎

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,12 +4161,19 @@ export function InterfacesPillar({
41614161
const [createError, setCreateError] = React.useState<string | null>(null);
41624162
const [reportBinding, setReportBinding] = React.useState<ReportBinding>(NO_REPORT_BINDING);
41634163
const [pageKind, setPageKind] = React.useState<PageSourceKind>(DEFAULT_PAGE_SOURCE_KIND);
4164-
const openCreate = React.useCallback((kind: InterfaceCreateKind) => {
4165-
setCreateError(null);
4166-
setReportBinding(NO_REPORT_BINDING);
4167-
setPageKind(DEFAULT_PAGE_SOURCE_KIND);
4168-
setCreateKind(kind);
4169-
}, []);
4164+
const openCreate = React.useCallback(
4165+
(kind: InterfaceCreateKind) => {
4166+
// objectstack#26845 — the created item opens at once, and its load
4167+
// replaces the buffer a held widget lives in: asked before the dialog
4168+
// opens, so Cancel costs nothing and the create itself asks nothing.
4169+
if (!confirmDropUnsavedWork(leafHeld !== null, locale)) return;
4170+
setCreateError(null);
4171+
setReportBinding(NO_REPORT_BINDING);
4172+
setPageKind(DEFAULT_PAGE_SOURCE_KIND);
4173+
setCreateKind(kind);
4174+
},
4175+
[leafHeld, locale],
4176+
);
41704177
// objectui#12455 — the "+" kind picker's other kinds: the entry is added
41714178
// where "Add nav item" adds one (the end of the top level, an id minted the
41724179
// way `AppNavCanvas` mints it), born with no label (objectui#11196) and, for
@@ -5500,15 +5507,10 @@ export function DataPillar({
55005507
// they had since selected, which is the regression the mount-time ref exists
55015508
// to prevent — so the id is marked spent as soon as the loaded rail has been
55025509
// consulted, whether or not it held a match.
5510+
//
5511+
// Applied below `objHeld`, which it asks about (objectstack#26845).
55035512
const requestedSurface = useRequestedSurface();
55045513
const appliedRequestRef = React.useRef(0);
5505-
React.useEffect(() => {
5506-
if (!requestedSurface || !objectsLoaded) return;
5507-
if (requestedSurface.id === appliedRequestRef.current) return;
5508-
appliedRequestRef.current = requestedSurface.id;
5509-
const match = resolveSurfaceDeepLink(objects, requestedSurface.target, 'object');
5510-
if (match) setCurrent(match);
5511-
}, [requestedSurface, objects, objectsLoaded]);
55125514
const [objDraft, setObjDraft] = React.useState<Record<string, unknown>>({});
55135515
// objectui#11272 — the object `objDraft` was loaded for, `object:NAME`:
55145516
// written where the load below installs it, and nowhere else.
@@ -6062,6 +6064,26 @@ export function DataPillar({
60626064
const fieldCopilotMark =
60636065
objLoaded && fieldSel?.kind === 'field' ? copilotDraftMarkOf(objDraftChanges, ['fields', fieldSel.id]) : null;
60646066
useHeldEditReport(onHeldEditChange, objHeld?.clause ?? null);
6067+
// The live request's apply (see `requestedSurface` above). objectstack#26845
6068+
// — another object's load replaces the buffer a held edit lives in, so it
6069+
// asks first, as the rail does; declined, the request is spent and the held
6070+
// edit stays. A request for the open object drops nothing and asks nothing.
6071+
React.useEffect(() => {
6072+
if (!requestedSurface || !objectsLoaded) return;
6073+
if (requestedSurface.id === appliedRequestRef.current) return;
6074+
appliedRequestRef.current = requestedSurface.id;
6075+
const match = resolveSurfaceDeepLink(objects, requestedSurface.target, 'object');
6076+
if (!match) return;
6077+
if (match.name !== current?.name && !confirmDropUnsavedWork(objHeld !== null, locale)) return;
6078+
setCurrent(match);
6079+
}, [requestedSurface, objects, objectsLoaded, current, objHeld, locale]);
6080+
// objectstack#26845 — a created object opens at once, and its load replaces
6081+
// the buffer a held edit lives in: asked before the dialog opens, so Cancel
6082+
// costs nothing and the create itself asks nothing.
6083+
const openCreateObject = () => {
6084+
if (!confirmDropUnsavedWork(objHeld !== null, locale)) return;
6085+
openCreateDialog();
6086+
};
60656087
// objectui#12725 — the header's draft line reads the badge's ledger.
60666088
const objDraftStatus = useStudioItemDraftStatus(
60676089
current ? { type: 'object', name: current.name } : null,
@@ -6310,7 +6332,7 @@ export function DataPillar({
63106332
testId="studio-rail-data"
63116333
heading={t('engine.studio.data.objects', locale)}
63126334
count={objects.length}
6313-
onAdd={readOnly ? undefined : openCreateDialog}
6335+
onAdd={readOnly ? undefined : openCreateObject}
63146336
addLabel={t('engine.studio.data.newObject', locale)}
63156337
addTestId="studio-rail-add"
63166338
search={{ value: query, onChange: setQuery, placeholder: t('engine.studio.data.searchObjects', locale) }}
@@ -6435,7 +6457,7 @@ export function DataPillar({
64356457
<button
64366458
type="button"
64376459
data-testid="empty-state-new-object"
6438-
onClick={openCreateDialog}
6460+
onClick={openCreateObject}
64396461
className="mt-2 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90"
64406462
>
64416463
<Plus className="h-3.5 w-3.5" /> {t('engine.studio.data.newObject', locale)}
@@ -7657,6 +7679,10 @@ export function AutomationsPillar({
76577679
const openCreateFlow =
76587680
!readOnly && packageId !== null
76597681
? () => {
7682+
// objectstack#26845 — the created flow opens at once, and its load
7683+
// replaces the buffer a held step lives in: asked before the dialog
7684+
// opens, so Cancel costs nothing and the create itself asks nothing.
7685+
if (!confirmDropUnsavedWork(flowHeld !== null, locale)) return;
76607686
setError(null);
76617687
setNewTrigger('');
76627688
setNewTriggerObject('');

0 commit comments

Comments
 (0)