Skip to content
Merged
15 changes: 15 additions & 0 deletions .changeset/30046-studio-view-dropdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(app-shell): Studio Interfaces picks an object's list view from the header title, object / view ▾, the way the running list does, and the open view stays in the address

Clause-②: no
Metadata-protocol: none

- **The view switcher is in the header's title.** An `object` entry's header reads object / view ▾. The switcher is the running list's own dropdown (`ObjectViewTitleSwitcher`): the object's list views by label, a view only drafted in this package included, a search box, and New view, which opens the Create View dialog. Studio does not offer the reader's own features there: no ☆, no 📌, no recent views, no Save as my view. It shows when the object has one list view too, so New view is always one click away. A read-only package switches views and offers no New view.
- **The Properties panel no longer holds a view picker, Add view or "Back to …".** It keeps the open view's settings, and its title is the view's name as the switcher gives it (the label the object's served `listViews` carry). A view with no label is named "Default view" or by its key; the header names the object before it.
- **The open view is in the address.** Switching writes `?view=<object>.<key>` beside `?surface=` and `?nav=`; the entry's own view writes none. A reload or a shared link opens that view again, a view only drafted in this package included. A link naming a view of another object is not taken. A pending edit is still sent before a switch, and an edit that cannot be sent still asks first.
- **`ObjectViewTitleSwitcher`: the pin is optional.** `onPinnedViewChange`, `pinnedViewId` and `recentViewIds` may be left out; without `onPinnedViewChange` no row draws 📌 and no Pinned section is listed. The running list passes all three, so it is unchanged.
- **`@object-ui/i18n` (studio namespace):** adds `engine.studio.inspector.listView.defaultView`; removes `defaultTitle`, `namedTitle`, `addView`, `backToEntry`, `switchView` and `switchViewDraft`, which only the removed panel controls read.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ const OBJECTS_READERS: Record<string, { kind: Kind; why: string }> = {
'packages/app-shell/src/views/metadata-admin/AssignedUsersSection.tsx': { kind: 'off', why: 'the metadata admin' },
'packages/app-shell/src/views/metadata-admin/previews/ScreenPreview.tsx': { kind: 'off', why: "the metadata admin's form-screen preview" },
'packages/app-shell/src/views/studio-design/ObjectListViewInspector.tsx': { kind: 'off', why: 'Studio' },
'packages/app-shell/src/views/studio-design/ObjectListViewTitle.tsx': {
kind: 'off',
why: "Studio: the object's view labels New view refuses to reuse, the read the list-view panel made before the switcher moved into the header (objectstack#30046)",
},
'packages/app-shell/src/views/studio-design/studio-canvas-preview.tsx': { kind: 'off', why: 'Studio' },
'packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx': {
kind: 'off',
Expand Down
33 changes: 33 additions & 0 deletions ui/packages/app-shell/src/views/objectViewTitleSwitcher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,36 @@ describe('objectstack#27594 — the title switcher dropdown', () => {
expect(within(menu).queryByTestId('list-view-switcher-manage')).toBeNull();
});
});

describe('objectstack#30046 — a host with no reader of its own hands no pin and no recent views', () => {
function mountStudio(props: Partial<ObjectViewTitleSwitcherProps> = {}) {
const onViewChange = vi.fn();
render(
<ObjectViewTitleSwitcher
views={VIEWS}
activeViewId="all"
activeLabel="All Leads"
favorites={null}
onViewChange={onViewChange}
t={t}
{...props}
/>,
);
fireEvent.click(screen.getByTestId('list-view-switcher'));
return { menu: screen.getByTestId('list-view-switcher-menu'), onViewChange };
}

it('no row draws 📌, and a pinned id handed without the pin door draws no Pinned section', () => {
const { menu } = mountStudio({ pinnedViewId: 'mine' });
expect(within(menu).queryAllByTestId('view-switcher-pin')).toHaveLength(0);
expect(within(menu).queryByTestId('list-view-switcher-pinned')).toBeNull();
expect(within(menu).queryByTestId('list-view-switcher-recent')).toBeNull();
expect(sectionIds('list-view-switcher-all')).toEqual(['all', 'board', 'mine', 'saved_a', 'saved_b']);
});

it('a row still switches the view', () => {
const { menu, onViewChange } = mountStudio();
fireEvent.click(within(within(menu).getByTestId('view-switcher-row-board')).getAllByRole('button')[0]);
expect(onViewChange).toHaveBeenCalledWith('board');
});
});
52 changes: 29 additions & 23 deletions ui/packages/app-shell/src/views/objectViewTitleSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ export interface ObjectViewTitleSwitcherProps {
description?: string;
onViewChange: (viewId: string) => void;
/** The reader's pinned view for this object, if any. */
pinnedViewId: string | null;
/** Pin a view (it opens by default), or `null` to unpin. */
onPinnedViewChange: (viewId: string | null) => void;
/** The views the reader opened lately, most recent first. */
recentViewIds: readonly string[];
pinnedViewId?: string | null;
/**
* Pin a view (it opens by default), or `null` to unpin. Absent ⇒ no row
* offers 📌 and no Pinned section is listed: a host with no reader of its
* own (the Studio, objectstack#30046) has no default to pin.
*/
onPinnedViewChange?: (viewId: string | null) => void;
/** The views the reader opened lately, most recent first; absent ⇒ no Recent section. */
recentViewIds?: readonly string[];
/** The ☆ of each row; absent off an app route, where no row offers one. */
favorites: ListViewFavorites | null;
viewTypeIcons?: Record<string, ComponentType<{ className?: string }>>;
Expand Down Expand Up @@ -123,9 +127,9 @@ export function ObjectViewTitleSwitcher({
count,
description,
onViewChange,
pinnedViewId,
pinnedViewId = null,
onPinnedViewChange,
recentViewIds,
recentViewIds = [],
favorites,
viewTypeIcons = VIEW_TYPE_ICONS,
onAddView,
Expand All @@ -144,7 +148,7 @@ export function ObjectViewTitleSwitcher({
const all = useMemo(() => authoredFirst(views), [views]);
const shared = all.filter((v) => !v.personal);
const mine = all.filter((v) => v.personal);
const pinned = pinnedViewId ? byId.get(pinnedViewId) : undefined;
const pinned = pinnedViewId && onPinnedViewChange ? byId.get(pinnedViewId) : undefined;
const recent = recentViewIds
.filter((id) => id !== pinned?.id)
.map((id) => byId.get(id))
Expand Down Expand Up @@ -227,21 +231,23 @@ export function ObjectViewTitleSwitcher({
<Star className={cn('h-3.5 w-3.5', starred && 'fill-current text-amber-500')} />
</button>
)}
<button
type="button"
data-testid="view-switcher-pin"
aria-label={pinLabel}
title={pinLabel}
aria-pressed={isPinned}
onClick={() => onPinnedViewChange(isPinned ? null : view.id)}
className={cn(
'flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground max-sm:h-11 max-sm:w-11',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
isPinned ? 'text-foreground' : reveal,
)}
>
<Pin className={cn('h-3.5 w-3.5', isPinned && 'fill-current')} />
</button>
{onPinnedViewChange && (
<button
type="button"
data-testid="view-switcher-pin"
aria-label={pinLabel}
title={pinLabel}
aria-pressed={isPinned}
onClick={() => onPinnedViewChange(isPinned ? null : view.id)}
className={cn(
'flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground max-sm:h-11 max-sm:w-11',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
isPinned ? 'text-foreground' : reveal,
)}
>
<Pin className={cn('h-3.5 w-3.5', isPinned && 'fill-current')} />
</button>
)}
{view.personal && onRenamePersonalView && (
<button
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,25 @@ async function openOpportunities(): Promise<void> {
await waitFor(() => expect(setting('startDateField')).toHaveTextContent('Close date'), { timeout: 8000 });
}

/** Whether the header's view switcher (the title's ▾) offers New view; closes it again. */
async function newViewOffered(): Promise<boolean> {
fireEvent.click(within(header()).getByTestId('list-view-switcher'));
const menu = await screen.findByTestId('list-view-switcher-menu');
const offered = within(menu).queryByTestId('list-view-switcher-new') !== null;
fireEvent.keyDown(menu, { key: 'Escape' });
await waitFor(() => expect(screen.queryByTestId('list-view-switcher-menu')).toBeNull());
return offered;
}

const canvasSchema = () => JSON.parse(screen.getByTestId('object-view-schema').textContent ?? '{}') as Record<string, unknown>;

describe('Customize an object leaf’s list view into the pair (objectstack#28562)', () => {
it('the panel is read-only until Customize; the first edit writes the view’s draft into the pair, declaring the override', async () => {
mount();
await openOpportunities();
expect(setting('startDateField')).toBeDisabled();
// A new view would be a new item of the base: not offered.
expect(screen.getByRole('button', { name: t('engine.studio.inspector.listView.addView', 'en') })).toBeDisabled();
// A new view would be a new item of the base: the header's view switcher offers none.
expect(await newViewOffered()).toBe(false);

await customize();
expect(srv.ensure).toEqual([]);
Expand All @@ -591,7 +601,7 @@ describe('Customize an object leaf’s list view into the pair (objectstack#2856
expect(saved!.opts).toMatchObject({ ifNoneMatch: '*' });
expect(srv.base.get('view/opportunity.default')).toStrictEqual(BASE_ROWS['view/opportunity.default']);
await within(header()).findByTestId('studio-override-chip', undefined, { timeout: 8000 });
expect(screen.getByRole('button', { name: t('engine.studio.inspector.listView.addView', 'en') })).toBeDisabled();
expect(await newViewOffered()).toBe(false);
});

it('Restore brings back the base’s columns', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#27836 — "Add view" in an `object` leaf's list-view panel: the
* type first, then the fields that type requires, picked by label; the view is
* created in the package draft and the panel shows it.
* objectstack#27836 — New view, from an `object` leaf's view switcher (the
* header's title, objectstack#30046): the type first, then the fields that
* type requires, picked by label; the view is created in the package draft and
* the panel shows it.
*
* The REAL hook (`useObjectListViewDraft`), the REAL panel and the REAL Create
* View dialog over a REAL `MetadataClient`, whose transport judges every view
* PUT with the installed spec's `view` schema and answers the write door's 422
* on refusal.
* The REAL hook (`useObjectListViewDraft`), the REAL title switcher
* (`ObjectListViewTitle`), the REAL panel and the REAL Create View dialog over
* a REAL `MetadataClient`, whose transport judges every view PUT with the
* installed spec's `view` schema and answers the write door's 422 on refusal.
*
* Pinned:
* - a kanban and a calendar are created, each under its own name, with the
* picked fields, in the package draft (`If-None-Match: *`), and the spec
* accepts them; the panel then edits the new view, and the default grid is
* not written;
* - "Back to …" shows the view the nav entry opens again;
* - the switcher lists the new view, and picking the nav entry's view there
* shows that one again;
* - a name a view already holds is refused: nothing is written, the dialog
* stays open, and the panel says why.
*/
Expand Down Expand Up @@ -121,6 +123,7 @@ vi.mock('sonner', async (importOriginal) => {
});

import { ObjectListViewInspector, useObjectListViewDraft } from './ObjectListViewInspector';
import { ObjectListViewTitle } from './ObjectListViewTitle';
import type { Surface } from './navSurface';
import { tFormat } from '../metadata-admin/i18n';

Expand All @@ -143,7 +146,14 @@ const LEAF: Surface = { type: 'object', name: 'acme_task', label: 'Tasks' };

function Host() {
const listView = useObjectListViewDraft({ client, packageId: PKG, leaf: LEAF, publishNonce: 0 });
return <ObjectListViewInspector listView={listView} readOnly={false} locale="en" />;
return (
<>
<h1>
<ObjectListViewTitle listView={listView} objectText="Tasks" locale="en" canCreate />
</h1>
<ObjectListViewInspector listView={listView} readOnly={false} locale="en" />
</>
);
}

async function settle() {
Expand All @@ -159,7 +169,15 @@ async function openPanel(): Promise<void> {
</MetadataCtx.Provider>,
);
await settle();
await waitFor(() => expect(screen.getByTestId('list-view-add-view')).toBeEnabled());
}

/** Opens the switcher (the title's ▾) and reads its rows, by label. */
async function openSwitcher(): Promise<string[]> {
if (!screen.queryByTestId('list-view-switcher-menu')) fireEvent.click(screen.getByTestId('list-view-switcher'));
const menu = await screen.findByTestId('list-view-switcher-menu');
return Array.from(menu.querySelectorAll('[data-testid^="view-switcher-row-"]')).map(
(row) => row.querySelector('button')?.textContent ?? '',
);
}

/** The view item name the panel shows beneath its title. */
Expand All @@ -174,7 +192,8 @@ const submitButton = () => screen.getByTestId('create-view-submit') as HTMLButto

/** "Add view", pick `type`, pick each required field by its label, name the view `label`, and press Create. */
async function addView(type: string, picks: Array<[key: string, label: string]>, label: string) {
fireEvent.click(screen.getByTestId('list-view-add-view'));
await openSwitcher();
fireEvent.click(await screen.findByTestId('list-view-switcher-new'));
await waitFor(() => expect(typeCard(type)?.disabled).toBe(false));
fireEvent.click(typeCard(type)!);
for (const [key, option] of picks) {
Expand Down Expand Up @@ -221,7 +240,7 @@ describe('ObjectListViewInspector — "Add view" creates a view of the chosen ty
await waitFor(() => expect(screen.queryByTestId('create-view-submit')).toBeNull());
await waitFor(() => expect(shownView()).toBe('acme_task.pipeline_board'));
expect(screen.getByTestId('list-view-kanban-card')).toBeInTheDocument();
expect(screen.getByTestId('list-view-back-to-entry')).toBeInTheDocument();
expect(screen.getByTestId('list-view-switcher')).toHaveTextContent('Pipeline board');
});

it('a calendar: born with its start-date and title fields, picked by label', async () => {
Expand All @@ -236,15 +255,17 @@ describe('ObjectListViewInspector — "Add view" creates a view of the chosen ty
await waitFor(() => expect(shownView()).toBe('acme_task.due_dates'));
});

it('"Back to …" shows the view the nav entry opens again', async () => {
it('the switcher lists the new view, and picking the entry\'s view there shows that one again', async () => {
await openPanel();
await addView('kanban', [['groupByField', 'Status']], 'Pipeline board');
await waitFor(() => expect(shownView()).toBe('acme_task.pipeline_board'));

fireEvent.click(screen.getByTestId('list-view-back-to-entry'));
const rows = await openSwitcher();
expect(rows).toContain('Pipeline board');
expect(rows).toContain('Default view');
fireEvent.click(screen.getByTestId(`view-switcher-row-${DEFAULT_VIEW}`).querySelector('button')!);
await settle();
expect(shownView()).toBe(DEFAULT_VIEW);
expect(screen.queryByTestId('list-view-back-to-entry')).toBeNull();
});

it('a name a view already holds: nothing is written, the dialog stays open, and the panel says why', async () => {
Expand Down
Loading
Loading