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
14 changes: 14 additions & 0 deletions .changeset/29771-app-landing-menu-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

Clause-②: yes
Metadata-protocol: none

An app whose entries live only under `areas` now opens on its first entry there, and an app whose menu holds only links or actions now says it opens from its menu, instead of an empty page (#29771).

- The app root walks the top-level navigation, then each area's navigation in order. It opens the first object, page, dashboard, report or component entry the member is shown in any of them, and only then the first doc entry. A working entry in an area therefore outranks a doc in the top-level navigation.
- When every entry the member is shown is a `url` or `action` link, the root draws an empty state that says the app opens from its menu (`AppNoAccessEmptyState`, reason `menu-only`). It offers no Setup link: the member has access.
- `@object-ui/i18n` adds `empty.appOpensFromMenu` and `empty.appOpensFromMenuDescription` to all ten locale packs.
- The app designer's preview names the same landing as the console, areas included.
42 changes: 33 additions & 9 deletions ui/packages/app-shell/src/console/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,9 @@ function buildItemRoute(item: any, ctx?: NavTemplateContext): string {
* walks groups and lands on an `object`, `page`, `dashboard`, `report` or
* `component` entry (objectui#12113 added `component`). It skips the item
* types that address nothing inside the app (`url`, `separator`, `action`).
* The walk covers every tree the member is shown: the top-level `navigation`
* first, then each `areas[].navigation` in order, so an app whose entries live
* only under `areas` lands too (objectstack-ai/objectstack#29771).
* A `doc` entry is passed over there: a working entry outranks reading
* material, so an app whose first entry is its manual still opens on its first
* working entry. Only when no entry lands does the root open the FIRST `doc`
Expand All @@ -1850,8 +1853,28 @@ function resolveLandingRoute(
const declared = resolveDeclaredLandingRoute(app?.landing, shownTrees, evaluateVisibility, (item) =>
buildItemRoute(item, ctx),
);
const tree = shownTrees[0] ?? [];
return declared || findFirstRoute(tree, ctx) || findFirstRoute(tree, ctx, DOC_LANDING_TYPES);
return declared || firstRouteAcross(shownTrees, ctx) || firstRouteAcross(shownTrees, ctx, DOC_LANDING_TYPES);
}

/**
* objectstack-ai/objectstack#29771 — the first route of `types` across every
* tree the member is shown, in order: the top-level `navigation`, then each
* `areas[].navigation` as authored. The preference holds across the trees, not
* per tree: a working entry in any area outranks a `doc` entry in the
* top-level navigation, as it does inside one tree (#29678). The sidebar elects
* the area that holds the landed entry (`electSidebarArea`), so a landing in a
* later area opens with that area active.
*/
function firstRouteAcross(
shownTrees: readonly NavigationItem[][],
ctx?: NavTemplateContext,
types: ReadonlySet<string> = WORKING_LANDING_TYPES,
): string {
for (const tree of shownTrees) {
const route = findFirstRoute(tree ?? [], ctx, types);
if (route) return route;
}
return '';
}

/**
Expand Down Expand Up @@ -1981,13 +2004,14 @@ function AppRootLanding({
if (appServesNoNavigation(shownApp)) {
return <AppNoAccessEmptyState app={app} setupPath={setupPath} />;
}
// A navigation with no landing: every entry the sidebar draws is a `url` or
// `action` link, or the items live only under `areas`, which the resolver
// does not walk (a `doc` entry lands, objectstack-ai/objectstack#29678). The
// root renders no page of its own and the sidebar offers the entries. It used
// to render the Studio app's overview, `StudioHomePage`, which objectui#12113
// retired.
return null;
// objectstack-ai/objectstack#29771 — a navigation with no in-app landing:
// every entry the member is shown, in `navigation` and in every area, is a
// `url` or `action` link (a working or `doc` entry anywhere would have
// landed). The root has no page of its own to open, so it says the app opens
// from its menu, instead of the empty `main` it used to render. The member
// does have access here, so the screen offers no Setup link. Before
// objectui#12113 this fell through to the Studio app's overview.
return <AppNoAccessEmptyState app={app} setupPath={setupPath} reason="menu-only" />;
}

/**
Expand Down
35 changes: 32 additions & 3 deletions ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@
* still draws its dashboards and pages, but every tile on them would refuse,
* so the description says the caller can read nothing here yet and asks for a
* permission set, instead of claiming the app has no pages.
*
* objectstack-ai/objectstack#29771 — and a third: an app that shows the caller
* entries, none of which opens a page inside the app (every one is a `url` or
* `action` link, in `navigation` and in every area). The caller has access;
* the app simply has no page of its own. So this reason has its own title and
* description, which point at the menu, a menu icon instead of the lock, and
* no Setup link: there is nothing to grant.
*/

import { Link } from 'react-router-dom';
import { Lock } from 'lucide-react';
import { Lock, PanelLeft } from 'lucide-react';
// The shared empty state (objectstack#25915): it draws the muted icon square
// this screen used to hand-copy, and it is `role="status"`, so "nothing here
// for you" is announced instead of being an unlabelled block. `AppContent.tsx`
Expand All @@ -47,9 +54,13 @@ export interface AppNoAccessEmptyStateProps {
/**
* Why the app has nothing for this caller: it shows them no navigation
* (`'no-navigation'`, the default), or it names only objects they may not
* read (`'no-readable-object'`, objectstack#25338).
* read (`'no-readable-object'`, objectstack#25338), or every entry it
* shows them is a `url` or `action` link, so the app opens from its menu
* and has no page of its own (`'menu-only'`,
* objectstack-ai/objectstack#29771). `setupPath` is not read for
* `'menu-only'`: the caller has access, so there is nothing to grant.
*/
reason?: 'no-navigation' | 'no-readable-object';
reason?: 'no-navigation' | 'no-readable-object' | 'menu-only';
}

export function AppNoAccessEmptyState({ app, setupPath, reason = 'no-navigation' }: AppNoAccessEmptyStateProps) {
Expand All @@ -58,6 +69,24 @@ export function AppNoAccessEmptyState({ app, setupPath, reason = 'no-navigation'
// The same label the header's app switcher shows for this app.
const label = appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) });

if (reason === 'menu-only') {
return (
<div className="flex h-full w-full items-center justify-center p-8" data-testid="app-no-access-empty-state">
<DataEmptyState
data-reason={reason}
icon={<PanelLeft className="size-5 text-muted-foreground" aria-hidden="true" />}
title={t('empty.appOpensFromMenu', {
app: label,
defaultValue: '{{app}} opens from its menu',
})}
description={t('empty.appOpensFromMenuDescription', {
defaultValue: 'This app has no page of its own. Choose an entry in its menu to open a link or run an action.',
})}
/>
</div>
);
}

const description =
reason === 'no-readable-object'
? setupPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
* - CONTROL: a pending read ahead of the doc still holds the skeleton, and
* the doc is landed on only once that read fails.
*
* objectstack-ai/objectstack#29771 — the rest of that blank page, pinned in
* its own `describe` below on the same harness:
* - an app whose entries live only under `areas` lands on the first working
* entry across the area trees, and a working entry in an area outranks a
* `doc` entry in the top-level navigation;
* - an app whose every shown entry is a `url` or `action` link draws the
* menu-only empty state (`data-reason="menu-only"`), with no Setup link;
* - CONTROL: a pending read in an area still holds the skeleton.
*
* NOTE ON SCOPE: routing only. `ConsoleLayout`, the lazily imported pages and
* the host's docs portal are stubbed.
*/
Expand Down Expand Up @@ -326,3 +335,117 @@ describe('objectstack-ai/objectstack#29678 — a doc-only app opens its first do
expect(pathname()).toBe('/apps/crm/docs/crm_manual');
});
});

const urlEntry = (id: string) => ({ id, type: 'url', label: id, url: 'https://example.com' });
const actionEntry = (id: string) => ({ id, type: 'action', label: id, actionDef: { actionName: 'export_data' } });

describe('objectstack-ai/objectstack#29771 — an areas-only app lands; a url/action-only app says it opens from its menu', () => {
beforeEach(() => {
metadataApps = [];
});

it('lands on the first working entry of its areas when the top-level navigation is empty', async () => {
metadataApps = [
{
name: 'crm',
label: 'CRM',
navigation: [],
areas: [
{ id: 'area_links', label: 'Links', navigation: [urlEntry('nav_site')] },
{ id: 'area_sales', label: 'Sales', navigation: [docEntry('nav_manual', { book: 'crm_manual' }), plainEntry('nav_deals', 'crm_deal')] },
],
},
];
const { apiFetch } = heldApiFetch();
renderConsoleAt('/apps/crm', apiFetch);

expect(await screen.findByTestId('object-view')).toBeInTheDocument();
expect(pathname()).toBe('/apps/crm/crm_deal');
expect(screen.queryByTestId('app-no-access-empty-state')).not.toBeInTheDocument();
});

it('prefers a working entry in an area over a doc entry in the top-level navigation', async () => {
metadataApps = [
{
name: 'crm',
label: 'CRM',
navigation: [docEntry('nav_manual', { book: 'crm_manual' })],
areas: [{ id: 'area_sales', label: 'Sales', navigation: [plainEntry('nav_deals', 'crm_deal')] }],
},
];
const { apiFetch } = heldApiFetch();
renderConsoleAt('/apps/crm', apiFetch);

expect(await screen.findByTestId('object-view')).toBeInTheDocument();
expect(pathname()).toBe('/apps/crm/crm_deal');
expect(screen.queryByTestId('docs-probe')).not.toBeInTheDocument();
});

it('lands on a doc in an area when no tree holds a working entry', async () => {
metadataApps = [
{
name: 'crm_help',
label: 'CRM Help',
navigation: [urlEntry('nav_site')],
areas: [{ id: 'area_help', label: 'Help', navigation: [docEntry('nav_manual', { book: 'crm_manual' })] }],
},
];
const { apiFetch } = heldApiFetch();
renderConsoleAt('/apps/crm_help', apiFetch);

expect(await screen.findByTestId('docs-probe')).toHaveTextContent('crm_manual');
expect(pathname()).toBe('/apps/crm_help/docs/crm_manual');
});

it('draws the menu-only empty state when every shown entry is a `url` or `action` link', async () => {
metadataApps = [
{
name: 'links',
label: 'Links',
navigation: [urlEntry('nav_site'), { id: 'group_tools', type: 'group', label: 'Tools', children: [actionEntry('nav_run')] }],
areas: [{ id: 'area_more', label: 'More', navigation: [urlEntry('nav_wiki')] }],
},
];
const { apiFetch } = heldApiFetch();
renderConsoleAt('/apps/links', apiFetch);

const status = await screen.findByRole('status');
expect(status).toHaveAttribute('data-reason', 'menu-only');
expect(screen.getByTestId('app-no-access-empty-state')).toContainElement(status);
expect(status).toHaveTextContent('Links opens from its menu');
expect(status).not.toHaveTextContent('available to you yet');
expect(screen.queryByTestId('app-no-access-open-setup')).not.toBeInTheDocument();
expect(pathname()).toBe('/apps/links');
});

it('CONTROL: an app that shows the member no navigation keeps the no-access reason', async () => {
metadataApps = [{ name: 'links', label: 'Links', navigation: [], areas: [{ id: 'area_empty', label: 'Empty', navigation: [] }] }];
const { apiFetch } = heldApiFetch();
renderConsoleAt('/apps/links', apiFetch);

expect(await screen.findByRole('status')).toHaveAttribute('data-reason', 'no-navigation');
expect(screen.getByRole('status')).toHaveTextContent('Nothing in Links is available to you yet');
});

it('CONTROL: a pending read in an area holds the skeleton, then lands on the bound entry once shown', async () => {
const envUrl = freshUrl();
metadataApps = [
{
name: 'crm',
label: 'CRM',
navigation: [urlEntry('nav_site')],
areas: [{ id: 'area_ops', label: 'Ops', navigation: [boundEntry('nav_env', 'crm_env', envUrl), docEntry('nav_manual', { book: 'crm_manual' })] }],
},
];
const { apiFetch, answer } = heldApiFetch();
renderConsoleAt('/apps/crm', apiFetch);

await waitFor(() => expect(apiFetch).toHaveBeenCalledWith(envUrl, expect.objectContaining({ method: 'GET' })));
expect(screen.getByTestId('app-landing-pending')).toBeInTheDocument();
expect(pathname()).toBe('/apps/crm');

await answer(envUrl, 200, SHOWN);
expect(await screen.findByTestId('object-view')).toBeInTheDocument();
expect(pathname()).toBe('/apps/crm/crm_env');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* - control: an app whose first entry is an `object` lands where it did;
* - control: an app that serves no navigation still gets the empty state;
* - an app whose entries address no page in the app (only `url` links)
* stays on its root with neither the empty state nor any page.
* stays on its root with no page, and says it opens from its menu
* (objectstack-ai/objectstack#29771; it used to draw nothing at all).
*
* NOTE ON SCOPE: routing only. `ConsoleLayout` and the lazily imported pages
* are stubbed, as in `AppContent.emptyNavigationLanding-12079.test.tsx`.
Expand Down Expand Up @@ -243,7 +244,7 @@ describe('AppContent — the Studio app root lands on its first navigation entry
expect(screen.getByTestId('pathname').textContent).toBe('/apps/clm');
});

it('an app whose entries address no page in the app stays on its root, with no empty state and no page', async () => {
it('an app whose entries address no page in the app stays on its root, with the menu-only empty state and no page', async () => {
metadataApps = [
{
name: 'links',
Expand All @@ -255,7 +256,10 @@ describe('AppContent — the Studio app root lands on its first navigation entry

expect(await screen.findByTestId('console-layout')).toHaveAttribute('data-active-app', 'links');
expect(screen.getByTestId('pathname').textContent).toBe('/apps/links');
expect(screen.queryByTestId('app-no-access-empty-state')).not.toBeInTheDocument();
// objectstack-ai/objectstack#29771 — the root says the app opens from its
// menu, never the "no access" sentence.
expect(screen.getByTestId('app-no-access-empty-state')).toContainElement(screen.getByRole('status'));
expect(screen.getByRole('status')).toHaveAttribute('data-reason', 'menu-only');
expect(screen.queryByTestId('component-nav-view')).not.toBeInTheDocument();
expect(screen.queryByTestId('metadata-directory-page')).not.toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('AppNoAccessEmptyState draws the shared empty state (objectstack#25915)
it.each([
['no-navigation', undefined],
['no-readable-object', 'no-readable-object' as const],
['menu-only', 'menu-only' as const],
])('carries data-reason=%s on the status node', (expected, reason) => {
renderState(reason ? { reason } : {});

Expand All @@ -74,3 +75,21 @@ describe('AppNoAccessEmptyState draws the shared empty state (objectstack#25915)
expect(link).toHaveAttribute('href', '/setup/permissions');
});
});

describe("AppNoAccessEmptyState's menu-only reason (objectstack-ai/objectstack#29771)", () => {
it('says the app opens from its menu, never the no-access sentence', () => {
renderState({ reason: 'menu-only' });

const status = screen.getByRole('status');
expect(status).toHaveTextContent('{{app}} opens from its menu');
expect(status).toHaveTextContent('Choose an entry in its menu to open a link or run an action.');
expect(status).not.toHaveTextContent('available to you yet');
});

it('offers no Setup link even when a setup path is given: the member has access', () => {
renderState({ reason: 'menu-only', setupPath: '/setup/permissions' });

expect(screen.getByRole('status')).toHaveAttribute('data-reason', 'menu-only');
expect(screen.queryByTestId('app-no-access-open-setup')).not.toBeInTheDocument();
});
});
16 changes: 9 additions & 7 deletions ui/packages/app-shell/src/console/appServesNoNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ interface AppNavigationLike {
* sidebar wires an action dispatcher, so an `action` item counts as content.
*
* ⛔ This is NOT "no landing route". The landing resolver walks the top-level
* `navigation` only and lands on an `object`, `page`, `dashboard`, `report` or
* `component` entry, so an app can serve entries and still have no landing:
* one whose entries are all `url`, `action` or `doc` links, or one that serves
* them only under `areas`. Such an app is not one the caller has no access in,
* and this answers no for it. The Studio app is not that case: its navigation
* is all `component` entries, and its root lands on the first one
* (objectui#12113).
* `navigation`, then every `areas[].navigation` in order
* (objectstack-ai/objectstack#29771), and lands on the first `object`, `page`,
* `dashboard`, `report` or `component` entry, else on the first `doc` entry
* (objectstack-ai/objectstack#29678). So an app can serve entries and still
* have no landing: one whose entries are all `url` or `action` links. Such an
* app is not one the caller has no access in, and this answers no for it; the
* root says the app opens from its menu instead (`AppNoAccessEmptyState`'s
* `'menu-only'` reason). The Studio app is not that case: its navigation is all
* `component` entries, and its root lands on the first one (objectui#12113).
*/
export function appServesNoNavigation(app: AppNavigationLike | null | undefined): boolean {
const options = { hasActionHandler: true };
Expand Down
Loading
Loading