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
10 changes: 10 additions & 0 deletions .changeset/37520-pageshell-row-hairline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(studio): a metadata page's title row with no buttons of its own draws no hairline before the AI assistant

Clause-②: no
Metadata-protocol: none

Under Studio, the AI assistant (or, with no assistant served, the right panel's show / hide button) ends every page's title row behind a thin divider that separates it from the page's own buttons. On a metadata list or item page with no stats and no buttons, that divider stood alone at the start of the group with nothing before it. It is now drawn only when the row has stats or buttons of its own, or while Save is shown, as the item header and the metadata directory already did. Outside Studio nothing changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* is read from the `/meta/diagnostics` envelope exactly as the page reads it.
*/

import * as React from 'react';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, screen, cleanup, fireEvent } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
Expand All @@ -31,6 +32,7 @@ vi.mock('./useMetadata', async (importActual) => {
});

import { MetadataDiagnosticsPage } from './DiagnosticsPage';
import { StudioTitleRowProvider } from '../studio-design/studioTitleRow';

afterEach(cleanup);

Expand Down Expand Up @@ -105,3 +107,51 @@ describe('MetadataDiagnosticsPage header tone (objectui#12721)', () => {
expect(screen.getByTestId('diagnostics-header-icon').getAttribute('class')).toMatch(/text-destructive/);
});
});

// objectstack#37455 put the page's Save and the AI assistant at the end of the
// diagnostics title row under Studio; objectstack#37520 (S2) pins them there,
// after the severity switch and Refresh, behind a hairline. Stubs stand in for
// the surface's controls.
describe('MetadataDiagnosticsPage under Studio: the page controls end its title row (objectstack#37520)', () => {
const ASSISTANT = (
<button type="button" data-testid="topbar-ai-assistant">
AI
</button>
);

const titleRow = () => screen.getByRole('heading', { level: 1 }).parentElement as HTMLElement;

it('the assistant is the row\'s last control, after Refresh, behind a hairline', async () => {
answer = () => envelope([]);
render(
<MemoryRouter>
<StudioTitleRowProvider save={null} assistant={ASSISTANT}>
<MetadataDiagnosticsPage />
</StudioTitleRowProvider>
</MemoryRouter>,
);
await screen.findByTestId('diagnostics-summary-badge');
const row = titleRow();
const ai = screen.getByTestId('topbar-ai-assistant');
expect(row).toContainElement(ai);
expect(row).toContainElement(screen.getByRole('button', { name: 'Refresh' }));
expect(ai.previousElementSibling).toHaveAttribute('data-testid', 'studio-title-row-divider');
// The row end is the row's last child: nothing comes after the assistant.
const end = row.lastElementChild as HTMLElement;
expect(end).toHaveAttribute('data-slot', 'studio-title-row-end');
expect(end.lastElementChild).toBe(ai);
expect(screen.getAllByTestId('topbar-ai-assistant')).toHaveLength(1);
});

it('CONTROL: outside Studio the row ends with Refresh', async () => {
answer = () => envelope([]);
render(
<MemoryRouter>
<MetadataDiagnosticsPage />
</MemoryRouter>,
);
await screen.findByTestId('diagnostics-summary-badge');
expect(titleRow().lastElementChild).toBe(screen.getByRole('button', { name: 'Refresh' }));
expect(screen.queryByTestId('topbar-ai-assistant')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*/

import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import { render, screen, cleanup, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import type { MetadataDiagnosticsSummary } from '@object-ui/data-objectstack';
import type { RichMetadataTypeEntry } from './useMetadata';
Expand Down Expand Up @@ -49,6 +50,7 @@ vi.mock('./useMetadata', async (importOriginal) => {
});

import { MetadataDirectoryPage } from './DirectoryPage';
import { StudioTitleRowProvider } from '../studio-design/studioTitleRow';

afterEach(() => {
cleanup();
Expand Down Expand Up @@ -134,3 +136,58 @@ describe('DirectoryPage — the "View all issues" link takes the sweep\'s tone (
expect(screen.queryByRole('link', { name: /View all issues/ })).toBeNull();
});
});

// objectstack#37455 put the page's Save and the AI assistant at the end of the
// directory's title row under Studio; objectstack#37520 (S2) pins them there.
// The row has no actions of its own, so no hairline comes before the
// assistant unless Save does. Stubs stand in for the surface's controls.
describe('DirectoryPage under Studio: the page controls end its title row (objectstack#37520)', () => {
const SAVE = (
<button type="button" data-testid="studio-save">
Save
</button>
);
const ASSISTANT = (
<button type="button" data-testid="topbar-ai-assistant">
AI
</button>
);

function renderUnderStudio(save: React.ReactNode) {
render(
<MemoryRouter initialEntries={[`/metadata?package=${PKG}`]}>
<StudioTitleRowProvider save={save} assistant={ASSISTANT}>
<MetadataDirectoryPage />
</StudioTitleRowProvider>
</MemoryRouter>,
);
}

const titleRow = () => screen.getByRole('heading', { level: 1 }).parentElement as HTMLElement;
const testIds = (el: Element) =>
Array.from(el.querySelectorAll('[data-testid]')).map((n) => n.getAttribute('data-testid'));

it('nothing unsaved: the assistant ends the title row, with no hairline before it', async () => {
answer = () => envelope([]);
renderUnderStudio(null);
await directoryLoaded();
expect(testIds(titleRow())).toEqual(['topbar-ai-assistant']);
expect(screen.getAllByTestId('topbar-ai-assistant')).toHaveLength(1);
});

it('unsaved edits: Save, then the hairline, then the assistant', async () => {
answer = () => envelope([]);
renderUnderStudio(SAVE);
await directoryLoaded();
expect(testIds(titleRow())).toEqual(['studio-save', 'studio-title-row-divider', 'topbar-ai-assistant']);
expect(within(titleRow()).getByRole('heading', { level: 1 })).toBeInTheDocument();
});

it('CONTROL: outside Studio the title row holds the title alone', async () => {
answer = () => envelope([]);
renderDirectory();
await directoryLoaded();
expect(testIds(titleRow())).toEqual([]);
expect(screen.queryByTestId('topbar-ai-assistant')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
*/

import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { afterEach, describe, expect, it } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { cleanup, render, screen, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { PageShell } from './PageShell';
import { StudioTitleRowProvider } from '../studio-design/studioTitleRow';

afterEach(cleanup);

Expand Down Expand Up @@ -105,3 +107,106 @@ describe('PageShell compact header wraps instead of squeezing the breadcrumb (ob
expect(classes(actions)).not.toContain('shrink-0');
});
});

// objectstack#37455 put the page's Save and the AI assistant at the end of
// PageShell's rows under Studio; objectstack#37520 pins them there (S2) and
// the hairline before the assistant (N3). The surface hands the controls down
// through `StudioTitleRowProvider`; stubs stand in for them here.
const SAVE = (
<button type="button" data-testid="studio-save">
Save
</button>
);
const ASSISTANT = (
<button type="button" data-testid="topbar-ai-assistant">
AI
</button>
);

function renderUnderStudio(
shell: Partial<React.ComponentProps<typeof PageShell>>,
save: React.ReactNode = null,
) {
render(
<MemoryRouter initialEntries={['/studio/com.acme.app/metadata/permission/showcase_contributor']}>
<StudioTitleRowProvider save={save} assistant={ASSISTANT}>
<PageShell entry={ENTRY as never} {...shell}>
<div>body</div>
</PageShell>
</StudioTitleRowProvider>
</MemoryRouter>,
);
}

const testIds = (el: Element) =>
Array.from(el.querySelectorAll('[data-testid]')).map((n) => n.getAttribute('data-testid'));

const ACTION = <button type="button" data-testid="page-action">Clone to customize</button>;

describe('PageShell under Studio: the page controls end its rows (objectstack#37520)', () => {
it('the compact row: the page\'s actions, then Save, the hairline and the assistant, in the right-aligned group', () => {
renderUnderStudio({ itemName: 'showcase_contributor', actions: ACTION }, SAVE);
const meta = screen.getByTestId('page-shell-header-meta');
const ai = within(meta).getByTestId('topbar-ai-assistant');
const group = screen.getByTestId('page-action').parentElement as HTMLElement;
expect(group).toContainElement(ai);
expect(testIds(group)).toEqual(['page-action', 'studio-save', 'studio-title-row-divider', 'topbar-ai-assistant']);
expect(screen.getAllByTestId('topbar-ai-assistant')).toHaveLength(1);
});

it('an embedded compact row (a page inside another page) draws neither Save nor the assistant', () => {
renderUnderStudio({ itemName: 'showcase_contributor', actions: ACTION, embedded: true }, SAVE);
expect(screen.getByTestId('page-shell-header-meta')).toContainElement(screen.getByTestId('page-action'));
expect(screen.queryByTestId('studio-save')).toBeNull();
expect(screen.queryByTestId('topbar-ai-assistant')).toBeNull();
expect(screen.queryByTestId('studio-title-row-divider')).toBeNull();
});

it('an embedded list row draws neither either', () => {
renderUnderStudio({ actions: ACTION, embedded: true }, SAVE);
expect(screen.getByTestId('page-action')).toBeInTheDocument();
expect(screen.queryByTestId('studio-save')).toBeNull();
expect(screen.queryByTestId('topbar-ai-assistant')).toBeNull();
});

it.each([
['compact', { itemName: 'showcase_contributor' }],
['list', {}],
] as const)('N3 — a %s row with no stats, no actions and nothing unsaved: the assistant, no hairline before it', (_row, shell) => {
renderUnderStudio(shell);
expect(screen.getByTestId('topbar-ai-assistant')).toBeInTheDocument();
expect(screen.queryByTestId('studio-title-row-divider')).toBeNull();
});

it.each([
['compact', { itemName: 'showcase_contributor' }],
['list', {}],
] as const)('N3 CONTROL — a %s row with stats of its own: the hairline before the assistant', (_row, shell) => {
renderUnderStudio({ ...shell, stats: [{ label: 'Objects granted', value: 9 }] });
const ai = screen.getByTestId('topbar-ai-assistant');
expect(ai.previousElementSibling).toHaveAttribute('data-testid', 'studio-title-row-divider');
});

// ResourceEditPage's embedded frame passes actions without `embedded`: the
// actions alone, with no stats and nothing unsaved, bring the hairline.
it.each([
['compact', { itemName: 'showcase_contributor' }],
['list', {}],
] as const)('N3 CONTROL — a %s row with actions of its own and no stats: the hairline before the assistant', (_row, shell) => {
renderUnderStudio({ ...shell, actions: ACTION });
const ai = screen.getByTestId('topbar-ai-assistant');
expect(screen.queryByTestId('studio-save')).toBeNull();
expect(ai.previousElementSibling).toHaveAttribute('data-testid', 'studio-title-row-divider');
expect(testIds(screen.getByTestId('page-action').parentElement as HTMLElement)).toEqual([
'page-action',
'studio-title-row-divider',
'topbar-ai-assistant',
]);
});

it('N3 CONTROL — no actions but unsaved edits: Save, then the hairline, then the assistant', () => {
renderUnderStudio({ itemName: 'showcase_contributor' }, SAVE);
const ai = screen.getByTestId('topbar-ai-assistant');
expect(testIds(ai.parentElement as HTMLElement)).toEqual(['studio-save', 'studio-title-row-divider', 'topbar-ai-assistant']);
});
});
9 changes: 7 additions & 2 deletions ui/packages/app-shell/src/views/metadata-admin/PageShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ export function PageShell({
// Setup catalog, not to the package-scoped Studio list of the same type.
const [search] = useSearchParams();
const scopeSuffix = environmentScopeSuffix(search);
// objectstack#37520 (N3) — the hairline before the assistant separates it
// from the row's own stats and actions; a row with neither draws none, as
// the item header and the directory header already do (`StudioTitleRowEnd`
// still draws it before Save, which always counts as an action).
const rowHasOwnControls = (stats?.length ?? 0) > 0 || !!actions;

return (
<div className="flex flex-col h-full overflow-hidden">
Expand Down Expand Up @@ -325,7 +330,7 @@ export function PageShell({
{/* objectstack#37455 — under Studio, the page's Save and the AI
assistant end the title row (nothing elsewhere, nor embedded
in another page). */}
{!embedded && <StudioTitleRowEnd />}
{!embedded && <StudioTitleRowEnd divider={rowHasOwnControls} />}
</div>
</div>
</div>
Expand Down Expand Up @@ -382,7 +387,7 @@ export function PageShell({
))}
{actions}
{/* objectstack#37455 — under Studio, the page's Save and the AI assistant end the title row. */}
{!embedded && <StudioTitleRowEnd />}
{!embedded && <StudioTitleRowEnd divider={rowHasOwnControls} />}
</div>
</div>
</div>
Expand Down
Loading
Loading