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
19 changes: 19 additions & 0 deletions .changeset/36692-report-editing-own-entry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

fix(console): report editing is its own entry, and report and dashboard editing exclude the design mode both ways

Clause-②: no
Metadata-protocol: none

The console's design mode no longer hosts the report builder, so the screen shows one Save/Cancel set at a time:

- The design mode's 「Add menu item → Reports」 lists only reports that exist; its 「New report…」 row is gone, with the hand-off that let the builder save into the menu. A new report is made from the reports index, then linked from the design mode.
- The reports index offers 「New report」 in its header, opening the report builder. It is offered to workspace admins, as the builder is, and not while the design mode is on.
- While the design mode is on, a dashboard's and a report's own 「Edit」 are not offered.
- While a dashboard or report editor is open, 「Design layout」 refuses with a prompt to save or cancel those changes first, so the design mode's 「Cancel」 can no longer end the mode under an editor left open.
- The report builder's own address reached with the design mode already on (the browser's Back) shows a prompt to finish designing the layout instead of the builder; the builder opens there once the mode is saved or cancelled.

The design mode's 「New dashboard…」 is unchanged. In `@object-ui/i18n`, `designMode.menu.newReport`, `designMode.menu.newReportLeft` and `report.builder.addsToMenu` are removed from every pack, and `designMode.editorOpen`, `console.reportIndex.newReport`, `report.builder.designModeOnTitle` and `report.builder.designModeOn` are added. Nothing to migrate.
116 changes: 9 additions & 107 deletions ui/packages/app-shell/src/layout/DesignModeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@
* place, and the mode saves at once, every other staged change with it
* (`saveAppMenuWithNewItem`); then the mode is left and the new dashboard
* opens for editing (`dashboardEditArrival`). 「Cancel」 writes nothing.
* In 「Reports」 the first row is 「New report…」: a report needs a data source
* and a measure, so the place stays held and the report builder opens; its
* Save creates the report and saves the mode the same way
* (`designModeReportSlot`), and its Close drops the place, writing nothing.
* 「Reports」 lists only reports that exist (objectstack#36692, the
* maintainer's ruling to keep report editing its own entry, as Twenty does):
* a new report is made from the reports index, then linked here.
*
* Every edit is staged with the mode (`useDesignModeChange`), under one key
* for the app's menu: the mode's 「Save」 writes it (`saveAppMenu`), its
Expand All @@ -69,7 +68,7 @@
*/

import * as React from 'react';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';
import { toast } from 'sonner';
import {
DndContext,
Expand Down Expand Up @@ -180,7 +179,6 @@ import {
} from './designModeMenuSave.js';
import { freeItemName, isNewMenuItemKind, saveAppMenuWithNewItem, type NewMenuItemKind } from './designModeMenuCreate.js';
import { dashboardEditArrival } from './designModeArrival.js';
import { offerNewReportSlot, withdrawNewReportSlot, type NewReportSlot } from './designModeReportSlot.js';

/**
* The group label's icon-mode hiding, as the sidebar's own labels declare it
Expand Down Expand Up @@ -503,83 +501,6 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
return true;
};

// objectstack#36364 (report half) — 「New report…」: a report cannot be
// made from a name (the spec wants `dataset` and `values`), so the place
// stays held and the report builder opens at `reports/new`. The builder
// saves through the slot offered here (`designModeReportSlot`): the report
// is created in the menu's package and its entry saved in the held place
// with every other staged change, in one act; nothing is written before.
// The builder's Close drops the place. Resolves `false` when nothing was
// saved (the mode has said why); the builder stays open for another try.
const [buildingReport, setBuildingReport] = React.useState(false);
const saveNewReport = async (name: string, label: string, body: Record<string, unknown>): Promise<boolean> => {
if (!addAt) return false;
// A report entry with no label shows its machine name (only an object,
// view or dashboard entry inherits its target's label), so the entry
// carries the name the reader gave the report.
const entry = { ...entryFor('report', name, newEntryId([...menu, ...(storedMenu ?? [])])), label };
const itemTexts = {
...texts,
itemPendingDraft: t('designMode.menu.newItemPendingDraft', {
defaultValue: 'A draft with this name is already pending. Try again.',
}),
itemLeft: t('designMode.menu.newReportLeft', {
defaultValue: 'The new report "{{name}}" could not be removed again; remove it in Studio.',
name: label,
}),
};
const saved = await saveWith(insertEntry(menu, addAt.parentId, addAt.index, entry), (navigation) =>
saveAppMenuWithNewItem(
{ appName, packageId, served, navigation, labels, item: { kind: 'report', name, label, body } },
itemTexts,
consoleAppMenuDoors(client as never),
),
);
if (!saved) return false;
setAddAt(null);
setBuildingReport(false);
return true;
};
// The builder's address the held place waits on.
const newReportPath = `${basePath}/reports/new`;
const saveNewReportRef = React.useRef(saveNewReport);
React.useLayoutEffect(() => {
saveNewReportRef.current = saveNewReport;
});
React.useEffect(() => {
if (!buildingReport) return;
const slot: NewReportSlot = {
path: newReportPath,
save: (name, label, body) => saveNewReportRef.current(name, label, body),
cancel: () => {
setBuildingReport(false);
setAddAt(null);
},
};
offerNewReportSlot(slot);
// Withdrawn when the place is no longer held, and when the menu unmounts
// (the design mode ended): the builder then saves on its own, off the menu.
return () => withdrawNewReportSlot(slot);
}, [buildingReport, newReportPath]);
// Leaving the builder another way than its Save or Close (a menu link, the
// browser's Back) drops the place too, so no held row waits for a builder
// that is gone. Read once the builder has been reached.
const { pathname } = useLocation();
const [reachedBuilder, setReachedBuilder] = React.useState(false);
const onBuilder = pathname === newReportPath || pathname.endsWith(newReportPath);
if (buildingReport && onBuilder && !reachedBuilder) setReachedBuilder(true);
if (!buildingReport && reachedBuilder) setReachedBuilder(false);
if (buildingReport && reachedBuilder && !onBuilder) {
setBuildingReport(false);
setReachedBuilder(false);
setAddAt(null);
}
const startNewReport = () => {
if (!addAt) return;
setBuildingReport(true);
navigate(newReportPath);
};

const renderLeaf = (entry: MenuEntry, depth: number) => {
const id = String(entry.id);
const place = placeOf(menu, id);
Expand Down Expand Up @@ -620,7 +541,7 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
const renderEntries = (entries: Menu, parentId: string | null, depth: number): React.ReactNode[] => {
const rows: React.ReactNode[] = [];
entries.forEach((entry, index) => {
if (addAt && addAt.parentId === parentId && addAt.index === index) rows.push(<Placeholder key="placeholder" depth={depth} buildingReport={buildingReport} />);
if (addAt && addAt.parentId === parentId && addAt.index === index) rows.push(<Placeholder key="placeholder" depth={depth} />);
if (isGroup(entry)) {
const gid = String(entry.id);
rows.push(
Expand All @@ -641,7 +562,7 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
rows.push(renderLeaf(entry, depth));
}
});
if (addAt && addAt.parentId === parentId && addAt.index >= entries.length) rows.push(<Placeholder key="placeholder" depth={depth} buildingReport={buildingReport} />);
if (addAt && addAt.parentId === parentId && addAt.index >= entries.length) rows.push(<Placeholder key="placeholder" depth={depth} />);
// Another package's group takes no own entry: no 「Add menu item」, no drop at its end.
if (foreignGroup(parentId)) return rows;
rows.push(
Expand Down Expand Up @@ -695,14 +616,13 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
</SortableContext>
</DndContext>
</SidebarGroupContent>
{addAt && !buildingReport && (
{addAt && (
<MenuItemPicker
packageId={packageId}
inMenu={menuTargets(menu)}
onClose={() => setAddAt(null)}
onPick={(kind, name, link) => pick(entryFor(kind, name, newEntryId([...menu, ...(storedMenu ?? [])]), link))}
onCreate={createItem}
onNewReport={startNewReport}
language={language}
/>
)}
Expand Down Expand Up @@ -794,14 +714,12 @@ function MenuLeaf({
);
}

function Placeholder({ depth, buildingReport }: { depth: number; buildingReport?: boolean }) {
function Placeholder({ depth }: { depth: number }) {
const { t } = useObjectTranslation();
return (
<li className="list-none" style={indent(depth)} data-testid="design-menu-placeholder">
<div className="mx-0.5 flex h-8 items-center rounded-md border border-dashed border-sidebar-border px-2 text-sm text-sidebar-foreground/60">
{buildingReport
? t('designMode.menu.newReport', { defaultValue: 'New report…' })
: t('designMode.menu.placeholder', { defaultValue: 'Choose a menu item…' })}
{t('designMode.menu.placeholder', { defaultValue: 'Choose a menu item…' })}
</div>
</li>
);
Expand Down Expand Up @@ -998,7 +916,6 @@ function MenuItemPicker({
onClose,
onPick,
onCreate,
onNewReport,
language,
}: {
packageId: string;
Expand All @@ -1007,8 +924,6 @@ function MenuItemPicker({
onPick: (kind: MenuTargetKind, name: string, link?: { label: string; url: string }) => void;
/** Create a new `kind` named `label`; `taken` is every name of that kind the picker lists. */
onCreate: (kind: NewMenuItemKind, label: string, taken: readonly string[]) => Promise<boolean>;
/** Build a new report for the held place, in the report builder. */
onNewReport: () => void;
language: string;
}) {
const { t } = useObjectTranslation();
Expand Down Expand Up @@ -1133,19 +1048,6 @@ function MenuItemPicker({
</button>
</li>
)}
{kind === 'report' && (
<li>
<button
type="button"
onClick={onNewReport}
className="flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium text-primary hover:bg-accent"
data-testid="design-menu-picker-new-report"
>
<Plus className="h-4 w-4 shrink-0" aria-hidden="true" />
<span className="flex-1 truncate">{t('designMode.menu.newReport', { defaultValue: 'New report…' })}</span>
</button>
</li>
)}
{loading ? (
<li className="px-2 py-2 text-sm text-muted-foreground">{t('designMode.menu.loading', { defaultValue: 'Loading…' })}</li>
) : offered.length === 0 ? (
Expand Down
5 changes: 5 additions & 0 deletions ui/packages/app-shell/src/layout/SidebarAppMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const APP_MENU_SEARCH_FROM = 8;
* (objectstack#36363: its changes are saved as this environment's
* customization), except where the customization door is walled off for this
* caller. Not drawn where no shell holds the mode, nor while the mode is on.
*
* objectstack#36692 — while a dashboard's or a report's own editor is open
* it stays drawn, and choosing it refuses, saying to save or cancel those
* changes first: the mode's `enter` refuses while an editor holds it out
* (`useHoldDesignModeOut`), so the screen never shows two Save/Cancel sets.
*/
function useEnterDesignMode(apps: Parameters<typeof matchAppBySegment>[0], activeAppName: string): (() => void) | null {
const entry = useStudioEntryGate(appStudioDesignPath(matchAppBySegment(apps, activeAppName), true));
Expand Down
Loading
Loading