Skip to content
Draft
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/36907-studio-new-dashboard-design-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(studio): New on a Studio dashboard list opens the app's design mode, ready to add a dashboard to its menu

Clause-②: no
Metadata-protocol: none

Studio redesign (epic #36890): a new dashboard is made where it hangs in an app's menu, never outside every menu.

- **New on a Studio dashboard list** opens the package's app with Design layout already on and the 「Add menu item」 picker open on its Dashboards, 「New dashboard…」 first. The app is picked the same way as for opening a dashboard: the app you came from when it is one of the package's, otherwise the package's first app. For an installed app, what you save there goes to its customization package, as before. For a customization package (`<base>.custom`) that has no app of its own, the base package's app opens.
- **After Create** the dashboard is in the menu where the picker put it, at the end of the menu's top level, and opens for editing, as a dashboard made in Design layout always has. Its × goes back to the Studio list you left. Closing the picker instead leaves you in Design layout, with nothing added.
- **When there is no New.** On a phone-width window the dashboard list offers no New: Design layout is never on there. A package with no app to open offers no New either, and the list says why.
- **Nothing enters Design layout by itself.** The way in is a one-time instruction carried by the click, never the address: a reload, a shared link or Back does not turn it on. If a dashboard's or a report's own editor is open at that moment, Design layout refuses with the usual message and nothing else happens.
- **The report list is unchanged:** its New still opens the app's New report page.
- **A note on an earlier entry,** customization packages' dashboards and reports opening in their base package's app: the app you came from also counts when it is not one of the base's apps, as long as its menu opens that dashboard or report. That is the same rule as for every package.
- New Studio string `engine.list.dashboardNewNoApp`, in English and Chinese.
5 changes: 5 additions & 0 deletions ui/packages/app-shell/src/layout/ConsoleLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { useHomePath } from '../hooks/useHomePath.js';
import { AppHeader } from './AppHeader.js';
import { DesignModeProvider, useDesignModeController } from './designMode.js';
import { DesignModeBar } from './DesignModeBar.js';
import { useDesignModeArrival } from './useDesignModeArrival.js';
import { useResponsiveSidebar } from '../hooks/useResponsiveSidebar.js';
import { usePhoneNavDrawerHistory } from './usePhoneNavDrawerHistory.js';
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
Expand Down Expand Up @@ -234,6 +235,10 @@ export function ConsoleLayout({
// objectstack#36362 — the app's design mode, held here so it stays on from
// page to page of the app; never on a phone, which has no 「Design layout」.
const designMode = useDesignModeController({ appName: activeAppName, appBasePath, enabled: !phone });
// objectstack#36907 — a Studio dashboard list's 「New」 arrives with the
// mode asked to enter and the 「Add menu item」 picker on its dashboards;
// read once and cleared, so Back or a reload enters nothing.
useDesignModeArrival(designMode, !phone);
// objectstack#30043 — the page in view, handed to the dock as its
// `context.surface` (cloud#1610's shape): the object of a list, the object
// and record id of a record page, the dashboard, report or page. Read off the
Expand Down
47 changes: 41 additions & 6 deletions ui/packages/app-shell/src/layout/DesignModeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
* 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.
*
* The mode may arrive asking this menu to open first (objectstack#36907, a
* Studio dashboard list's 「New」, `useDesignModeOpening`): the picker then
* opens at once, on its 「Dashboards」, for an entry at the end of the top
* level, as that level's 「Add menu item」 would. A dashboard created from it
* opens with the Studio list it came from (`?studio=`), so its × goes back
* there; closing the picker drops that, and later adds are plain.
*
* Every edit is staged with the mode (`useDesignModeChange`), under one key
* for the app's menu: the mode's 「Save」 writes it (`saveAppMenu`), its
* 「Cancel」 drops it. The menu drawn is the staged one, so it survives a page
Expand Down Expand Up @@ -144,7 +151,7 @@ import {
fetchListedPackageManifests,
listedCustomizationPairOf,
} from '../views/studio-design/packages-io.js';
import { useDesignModeChange } from './designMode.js';
import { useDesignModeChange, useDesignModeOpening } from './designMode.js';
import {
MENU_TARGET_KINDS,
canMoveBy,
Expand Down Expand Up @@ -181,6 +188,7 @@ import {
} from './designModeMenuSave.js';
import { freeItemName, isNewMenuItemKind, saveAppMenuWithNewItem, type NewMenuItemKind } from './designModeMenuCreate.js';
import { dashboardEditArrival } from './designModeArrival.js';
import { withStudioReturn } from '../views/studio-design/studioAddress.js';

/**
* The group label's icon-mode hiding, as the sidebar's own labels declare it
Expand Down Expand Up @@ -452,10 +460,32 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
const startAdd = (at: AddAt) => {
setAddAt({ parentId: at.parentId, index: Math.min(at.index, ownEndOf(menu, at.parentId)) });
};

// objectstack#36907 — what the mode arrived asking to open: the picker on
// its 「Dashboards」, at the end of the top level, taken once. `arrivedFrom`
// is the Studio list it came from, kept while that picker is open.
const arrivalOpening = useDesignModeOpening();
const [pickerKind, setPickerKind] = React.useState<MenuTargetKind | null>(null);
const [arrivedFrom, setArrivedFrom] = React.useState<string | null>(null);
const takeArrival = arrivalOpening.take;
React.useEffect(() => {
if (!arrivalOpening.opening) return;
const taken = takeArrival();
if (!taken) return;
startAdd({ parentId: null, index: menu.length });
setPickerKind(taken.column);
setArrivedFrom(taken.studioReturn);
// eslint-disable-next-line react-hooks/exhaustive-deps -- answered once per opening
}, [arrivalOpening.opening, takeArrival]);
const closePicker = () => {
setAddAt(null);
setPickerKind(null);
setArrivedFrom(null);
};
const pick = (entry: MenuEntry) => {
if (!addAt) return;
update(insertEntry(menu, addAt.parentId, addAt.index, entry));
setAddAt(null);
closePicker();
};

// objectstack#36364 — a new dashboard, in the held place: created, put in
Expand Down Expand Up @@ -498,8 +528,9 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
),
);
if (!saved) return false;
setAddAt(null);
navigate(resolveHref(entry as unknown as NavigationItem, basePath).href, { state: dashboardEditArrival(name) });
const href = resolveHref(entry as unknown as NavigationItem, basePath).href;
closePicker();
navigate(arrivedFrom ? withStudioReturn(href, arrivedFrom) : href, { state: dashboardEditArrival(name) });
return true;
};

Expand Down Expand Up @@ -622,7 +653,8 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
<MenuItemPicker
packageId={packageId}
inMenu={menuTargets(menu)}
onClose={() => setAddAt(null)}
initialKind={pickerKind}
onClose={closePicker}
onPick={(kind, name, link) => pick(entryFor(kind, name, newEntryId([...menu, ...(storedMenu ?? [])]), link))}
onCreate={createItem}
language={language}
Expand Down Expand Up @@ -915,13 +947,16 @@ function useTargetRows(packageId: string, language: string): { rows: TargetRow[]
function MenuItemPicker({
packageId,
inMenu,
initialKind = null,
onClose,
onPick,
onCreate,
language,
}: {
packageId: string;
inMenu: ReadonlySet<string>;
/** The kind the picker opens on (objectstack#36907); `null`: the list of kinds. */
initialKind?: MenuTargetKind | null;
onClose: () => void;
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. */
Expand All @@ -930,7 +965,7 @@ function MenuItemPicker({
}) {
const { t } = useObjectTranslation();
const { rows, loading } = useTargetRows(packageId, language);
const [kind, setKind] = React.useState<MenuTargetKind | null>(null);
const [kind, setKind] = React.useState<MenuTargetKind | null>(initialKind);
const [query, setQuery] = React.useState('');
const [link, setLink] = React.useState({ label: '', url: '' });
/** The kind being named for creation (objectstack#36364), `null` while picking. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
import { MemoryRouter, useLocation } from 'react-router-dom';
import { MemoryRouter, useLocation, useNavigate } from 'react-router-dom';
import { SidebarProvider } from '@object-ui/components';
import { NavigationRenderer } from '@object-ui/layout';
import type { NavigationItem } from '@object-ui/types';
Expand Down Expand Up @@ -140,7 +140,9 @@ vi.mock('../../views/studio-design/packages-io', async (importOriginal) => ({
}));
vi.mock('../../utils/getIcon', () => ({ getIcon: () => () => null }));

import { DesignModeProvider, useDesignMode, useDesignModeController } from '../designMode';
import { DesignModeProvider, useDesignMode, useDesignModeController, useHoldDesignModeOut } from '../designMode';
import { useDesignModeArrival } from '../useDesignModeArrival';
import { designModeAddDashboardArrival } from '../designModeArrival';
import { DesignModeBar } from '../DesignModeBar';
import DesignModeMenu from '../DesignModeMenu';
import { closestCenter, type CollisionDetection } from '@dnd-kit/core';
Expand Down Expand Up @@ -1308,3 +1310,190 @@ describe('the design-mode menu save and drag, hardened (objectstack#36538)', ()
});
});
});

/*
* objectstack#36907 — a Studio dashboard list's 「New」 arrives in the app with
* `designModeAddDashboardArrival` in the navigation state. The shell
* (`useDesignModeArrival`, as `ConsoleLayout` calls it) reads it once, clears
* it from the history entry, and enters the mode with the picker open on its
* 「Dashboards」; where `enter` refuses, nothing more happens and the mode
* says why; on a phone, nothing at all.
*/
const STUDIO_LIST = '/studio/com.acme.crm/metadata/dashboard?package=com.acme.crm';

/** The shell's hold on the mode, as `ConsoleLayout` wires it, the arrival read included. */
function ArrivalHarness({ enabled = true, editorOpen = false }: { enabled?: boolean; editorOpen?: boolean }) {
const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled });
useDesignModeArrival(mode, enabled);
return (
<DesignModeProvider value={mode}>
{mode.active && <DesignModeBar mode={mode} />}
{editorOpen && <OpenEditor />}
<SidebarProvider>
{mode.active && (
<DesignModeMenu
app={{ name: 'crm', navigation: servedNav.current ?? NAVIGATION, _packageId: 'com.acme.crm' }}
basePath="/apps/crm"
resolveTargetLabel={(target) => (target.kind === 'object' ? OBJECT_LABELS[target.objectName] : undefined)}
/>
)}
</SidebarProvider>
<ArriveAgain />
</DesignModeProvider>
);
}

/** A dashboard's or a report's own editor, open: it holds the mode out (objectstack#36692). */
function OpenEditor() {
useHoldDesignModeOut(true);
return null;
}

/** The address and the navigation state on screen, as `JSON`. */
function Here() {
const { pathname, search, state } = useLocation();
return <span data-testid="here" data-at={`${pathname}${search}`} data-state={JSON.stringify(state ?? null)} />;
}

/** A second arrival into the app on screen: Studio's New, taken again. */
function ArriveAgain() {
const navigate = useNavigate();
return (
<button type="button" onClick={() => navigate('/apps/crm', { state: designModeAddDashboardArrival(STUDIO_LIST) })}>
arrive again
</button>
);
}

const here = () => {
const el = screen.getByTestId('here');
return { at: el.getAttribute('data-at'), state: JSON.parse(el.getAttribute('data-state') ?? 'null') };
};

function arrive(props: { enabled?: boolean; editorOpen?: boolean } = {}, entry: { pathname: string; state: unknown } = {
pathname: '/apps/crm',
state: designModeAddDashboardArrival(STUDIO_LIST),
}) {
return render(
<MemoryRouter initialEntries={[entry]}>
<ArrivalHarness {...props} />
<Here />
</MemoryRouter>,
);
}

describe("the arrival from a Studio dashboard list's New (objectstack#36907)", () => {
it('enters the mode with the picker open on 「Dashboards」, 「New dashboard…」 first, for an entry at the end of the top level', async () => {
listed.dashboard = [{ name: 'revenue', label: 'Revenue' }];
try {
arrive();
await flush();
expect(screen.getByTestId('design-mode-bar')).toBeInTheDocument();
const picker = await screen.findByTestId('design-menu-picker');
const rows = within(within(picker).getByTestId('design-menu-picker-rows')).getAllByRole('button').map((b) => b.textContent);
expect(rows).toEqual(['New dashboard…', 'Revenue']);
expect(order()).toEqual(['home', ['sales', ['leads', 'accounts']], ['insights', []], '…']);
expect(toastError).not.toHaveBeenCalled();
} finally {
listed.dashboard = [];
}
});

it('is read once: the history entry is cleared, so a reload of it, or Back to it, enters nothing', async () => {
arrive();
await flush();
expect(here()).toEqual({ at: '/apps/crm', state: null });
expect(screen.getByTestId('design-mode-bar')).toBeInTheDocument();
cleanup();

// The same entry, reloaded: what the history holds now carries no arrival.
arrive({}, { pathname: '/apps/crm', state: null });
await flush();
expect(screen.queryByTestId('design-mode-bar')).toBeNull();
expect(screen.queryByTestId('design-menu-picker')).toBeNull();
});

it('「Create」 in it: the dashboard hangs at the end of the top level and opens for editing, with × back to the Studio list', async () => {
arrive();
await flush();
const picker = await screen.findByTestId('design-menu-picker');
fireEvent.click(within(picker).getByTestId('design-menu-picker-new-dashboard'));
const naming = await screen.findByTestId('design-menu-new-dashboard');
fireEvent.change(within(naming).getByTestId('design-menu-new-name'), { target: { value: 'Payment analysis' } });
fireEvent.click(within(naming).getByTestId('design-menu-new-create'));
await flush();
await flush();
await flush();

expect(written.map(([verb, type, name]) => `${verb} ${type} ${name}`)).toEqual([
'save dashboard payment_analysis',
'publish dashboard payment_analysis',
'save app crm',
'publish app crm',
]);
const navigation = (written[2][3] as { navigation: Array<{ id: string }> }).navigation;
expect(navigation.at(-1)).toEqual({ id: 'nav_item_1', type: 'dashboard', dashboardName: 'payment_analysis' });
expect(screen.queryByTestId('design-mode-bar')).toBeNull();
const landed = here();
expect(landed.at!.split('?')[0]).toBe('/apps/crm/dashboard/payment_analysis');
expect(new URLSearchParams(landed.at!.split('?')[1]).get('studio')).toBe(STUDIO_LIST);
expect(landed.state).toEqual({ designModeNewDashboard: 'payment_analysis' });
});

it("closing that picker drops the Studio list: a dashboard made from another 「Add menu item」 opens without it", async () => {
arrive();
await flush();
fireEvent.keyDown(await screen.findByTestId('design-menu-picker'), { key: 'Escape' });
await flush();
expect(screen.queryByTestId('design-menu-picker')).toBeNull();
const picker = await openDashboards();
fireEvent.click(within(picker).getByTestId('design-menu-picker-new-dashboard'));
const naming = await screen.findByTestId('design-menu-new-dashboard');
fireEvent.change(within(naming).getByTestId('design-menu-new-name'), { target: { value: 'Payment analysis' } });
fireEvent.click(within(naming).getByTestId('design-menu-new-create'));
await flush();
await flush();
await flush();
expect(here().at).toBe('/apps/crm/dashboard/payment_analysis');
});

it('where an editor of its own holds the mode out, entering refuses and says why; the arrival does nothing more and is cleared', async () => {
render(
<MemoryRouter initialEntries={['/apps/crm/dashboard/ops']}>
<ArrivalHarness editorOpen />
<Here />
</MemoryRouter>,
);
fireEvent.click(screen.getByText('arrive again'));
await flush();
expect(toastError).toHaveBeenCalledWith('Save or cancel your dashboard or report changes before designing the layout.');
expect(screen.queryByTestId('design-mode-bar')).toBeNull();
expect(screen.queryByTestId('design-menu-picker')).toBeNull();
expect(here()).toEqual({ at: '/apps/crm', state: null });
expect(written).toEqual([]);
});

it('the same refusal when the editor opens in the very commit the arrival lands in', async () => {
arrive({ editorOpen: true });
await flush();
expect(toastError).toHaveBeenCalledWith('Save or cancel your dashboard or report changes before designing the layout.');
expect(screen.queryByTestId('design-mode-bar')).toBeNull();
expect(here()).toEqual({ at: '/apps/crm', state: null });
});

it('on a phone the mode is never on: the arrival enters nothing, says nothing, and is cleared', async () => {
arrive({ enabled: false });
await flush();
expect(screen.queryByTestId('design-mode-bar')).toBeNull();
expect(screen.queryByTestId('design-menu-picker')).toBeNull();
expect(toastError).not.toHaveBeenCalled();
expect(here()).toEqual({ at: '/apps/crm', state: null });
});

it('CONTROL — the menu door enters the mode with no picker open', async () => {
start();
await flush();
expect(screen.getByTestId('design-mode-bar')).toBeInTheDocument();
expect(screen.queryByTestId('design-menu-picker')).toBeNull();
});
});
Loading
Loading