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
11 changes: 11 additions & 0 deletions .changeset/33988-header-fold-needs-primary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

fix(console): a list page with no declared primary action keeps its header actions as buttons, whatever the length of the object's description

Clause-②: no
Metadata-protocol: none

On a list page the header folds its actions when they do not fit beside the title and the object's description: the primary action stays a labelled button and the others move into the `⋯` menu. The primary is declared: the page's New, else the list-toolbar action authored `variant: 'primary'`. A list with neither had nothing to keep labelled, so the folded header was the `⋯` alone, and a long description by itself moved the page's one action (for example a reader without create rights and a single `Launch Contract` toolbar action) into the menu at desktop width. Such a list is now offered no folded header: its actions stay buttons at every width and the description is truncated instead. The `/data` page follows the same rule: with no New to keep, Save as view stays a button. A list that declares a primary folds exactly as before. To keep a toolbar action labelled on a narrow header as well, author it `variant: 'primary'`.
4 changes: 3 additions & 1 deletion ui/packages/app-shell/src/layout/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export interface ConsolePageHeaderProps {
* The header measures its own width, not the viewport's. The page declares
* which action is primary by being the one that names it here; the header
* never guesses it from `actions`. A page that passes no `foldedActions`
* keeps `actions` at every width.
* keeps `actions` at every width, and a page with no primary to keep
* labelled passes none (objectstack#33988): a face of only the `⋯` would
* trade the page's actions for its description.
*/
foldedActions?: React.ReactNode;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import { MemoryRouter, Routes, Route } from 'react-router-dom';
let principal: Record<string, boolean> = {};
/** Controllable server-resolved effective API operations (#3391); `undefined` = unrestricted. */
let apiOperations: string[] | undefined;
/** Whether the reader is a workspace admin (draws "Save as view"); off by default. */
let workspaceAdmin = false;

vi.mock('@object-ui/permissions', async (importOriginal) => {
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
Expand All @@ -85,7 +87,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
vi.mock('@object-ui/auth', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: null }),
useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }),
useWorkspaceAdminStatus: () => ({ isAdmin: workspaceAdmin, isResolved: true }),
createAuthenticatedFetch: () => vi.fn(),
}));

Expand Down Expand Up @@ -182,6 +184,7 @@ function expectCreateEntry(expected: { rendered: boolean; disabled?: boolean })
beforeEach(() => {
principal = {};
apiOperations = undefined;
workspaceAdmin = false;
cleanup();
vi.stubGlobal(
'fetch',
Expand Down Expand Up @@ -373,3 +376,31 @@ describe('#5164 — /data and the object-list page agree on one declaration', ()
expect(newButton()).toBeTruthy();
});
});

/**
* objectstack#33988 — the header's folded face (objectui#12705) keeps New
* labelled and puts Save as view in a `⋯`. With no New there is nothing to keep
* labelled, so the page offers no folded face: a long description must never
* send the page's one action into the `⋯`. The header marks a page that offers
* the fold with `data-folded`; one that does not keeps `actions` at every
* width, so the attribute is absent.
*/
describe('objectstack#33988 — /data offers the fold only with a New to keep labelled', () => {
const cluster = () => document.querySelector('[data-testid="page-header-actions"]') as HTMLElement | null;

it('an admin who cannot create keeps "Save as view" as a button: no folded face is offered', () => {
workspaceAdmin = true;
principal = { create: false };
renderDataPage(objects());
expect(newButton()).toBeNull();
expect(cluster()?.querySelector('[data-testid="object-data-save-as-view"]')).toBeTruthy();
expect(cluster()?.hasAttribute('data-folded')).toBe(false);
});

it('CONTROL: with New drawn, the folded face is still offered', () => {
workspaceAdmin = true;
renderDataPage(objects());
expect(newButton()).toBeTruthy();
expect(cluster()?.getAttribute('data-folded')).toBe('false');
});
});
6 changes: 4 additions & 2 deletions ui/packages/app-shell/src/views/ObjectDataPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,11 @@ export function ObjectDataPage({ dataSource, objects }: any) {
</>
}
// objectui#12705 — too narrow for both actions and the description:
// New stays labelled and Save as view goes into a `⋯`.
// New stays labelled and Save as view goes into a `⋯`. With no New
// to keep labelled there is no folded face (objectstack#33988): it
// would send the page's one action into the `⋯` for the description.
foldedActions={
<>
newButton && <>
{newButton}
{isAdmin && (
<DropdownMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({
ImportWizard: ({ open }: { open: boolean }) => (open ? <div data-testid="import-wizard" /> : null),
}));

// `ObjectView` reaches a dynamic `import('@objectstack/lint')`: pay its load at
// collection, never inside a case's clocked window (`check:test-source-alias`).
import '@objectstack/lint';
import { ObjectView, declaredPrimaryToolbarAction } from './ObjectView';
import { ExpressionProvider } from '../providers/ExpressionProvider';

Expand Down Expand Up @@ -282,6 +285,47 @@ describe('the object list’s header folds its actions (objectui#12705)', () =>
});
});

/**
* objectstack#33988 — a list that declares no primary (no New, no toolbar
* action authored `variant: 'primary'`) is offered no folded face: that face
* would keep no labelled action, so a long description alone sent the page's
* one action into the `⋯` at desktop width (hotclm's 「Launch Contract」). The
* header keeps `actions` at every width and the description truncates instead.
*/
describe('a list with no declared primary keeps its actions labelled (objectstack#33988)', () => {
const LAUNCH = { name: 'launch_contract', label: 'Launch Contract', type: 'script', locations: ['list_toolbar'] };
/** The card's object: no New for the reader, one undeclared toolbar action, its English description. */
const CONTRACTS = {
name: 'demo_contract',
label: 'Contract',
pluralLabel: 'Contracts',
description:
'A contract from intake to archive: parties, commercial and legal terms, lifecycle status and the stamps each stage leaves.',
fields: { id: { type: 'text', label: 'Id' }, name: { type: 'text', label: 'Name' } },
actions: [LAUNCH],
};

// A 1366 px laptop and a 1440 px desktop, each less the 256 px sidebar, and
// a tablet-wide header between the phone header and the desktop.
it.each([1110, 1184, 700])('at a %i px header the action stays a button and the header does not fold', (width) => {
headerWidth = width;
principal = { create: false };
const { cluster, labelled, openMenu } = renderList(CONTRACTS);
expect(labelled()).toEqual(['Launch Contract']);
expect(openMenu()).toEqual(['Add to favorites']);
expect(cluster.hasAttribute('data-folded')).toBe(false);
});

it('CONTROL: authored `variant: primary`, the same list still folds at a 600 px header, keeping it labelled', () => {
headerWidth = 600;
principal = { create: false };
const { cluster, labelled, openMenu } = renderList({ ...CONTRACTS, actions: [{ ...LAUNCH, variant: 'primary' }] });
expect(cluster.getAttribute('data-folded')).toBe('true');
expect(labelled()).toEqual(['Launch Contract']);
expect(openMenu()).toEqual(['Add to favorites']);
});
});

describe('declaredPrimaryToolbarAction (objectui#12705)', () => {
it('is the `variant: primary` list-toolbar action with the lowest order, never the first by position', () => {
const late = { ...INVITE, name: 'late', order: 5 };
Expand Down
8 changes: 7 additions & 1 deletion ui/packages/app-shell/src/views/objectViewHeaderChrome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export function useObjectViewHeaderChrome({
// it before the header can fold, so no action in the folded face carries
// `autoTrigger`. Not offered on the environment list, whose toolbar is
// `EnvironmentListToolbar`, not this bar.
//
// objectstack#33988 — not offered either when the list declares no
// primary (no New, no toolbar action authored `variant: 'primary'`): that
// face would keep no labelled action, so a long description alone would
// send the page's one action into the `⋯`. Without a folded face the
// header keeps `actions` at every width and the description truncates.
const toolbarRowActions: UIActionSchema[] = listActions?.some((a: { locations?: readonly string[] }) => a.locations?.includes('list_toolbar'))
? toolbarActionsWithDeepLink
: [];
Expand Down Expand Up @@ -133,7 +139,7 @@ export function useObjectViewHeaderChrome({
maxVisible: 0,
mobileMaxVisible: 0,
};
const foldedHeaderActions = !isEnvironmentList ? (
const foldedHeaderActions = !isEnvironmentList && (showCreate || primaryToolbarAction) ? (
<>
{createButton}
{/* One inline slot at every width: `toolbarBar` keeps none below
Expand Down
Loading