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
17 changes: 17 additions & 0 deletions .changeset/35881-phone-app-home-fixed-bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
'@object-ui/i18n': patch
---

feat(app-shell): on a phone, sign-in lands in an app whose home is its whole menu, and the bottom bar is fixed to Home, Notifications, Approvals and search

Clause-②: no
Metadata-protocol: none

Phone width only (below 768 px). Desktop and tablet widths do not change.

- **Where sign-in lands.** A phone opens the app the person used last. The app the product marks as default is used only when there is no record yet, for example on a first sign-in. With one app it opens that app; with several and neither, it opens the app list. The last app is kept per person with their other console preferences (the `ui.app.last` key), so it follows them across devices. It is read in the same request as those preferences, not in a new one. A desktop still lands on the declared default first, as before.
- **The app's home is its whole menu.** On a phone, `/apps/SEGMENT` shows the app's menu with its groups, order and icons, one row per entry. It no longer redirects to the first entry. This is the sidebar's own menu drawn in a second place, so it cannot list an entry the sidebar hides. 「‹」 on a page one level down goes back to it, and the page comes back scrolled as it was left. An app that shows the member no entry still says so.
- **App switcher.** The app pill at the top left opens a bottom sheet: 「Current app」 with a check, then 「Other apps」 with Setup last, and a search box at the bottom. On a phone, `/home` is that same list as a page.
- **Bottom bar.** The bar has three fixed cells, Home, Notifications and Approvals, and a round search button. They do not change with the app and cannot be configured. Home opens the app's home. Notifications and Approvals open the pages the bell opens, with the bell's two counts as badges. Search opens the command palette. The bar shows only on those three pages; a list, a record, a form or any deeper page has the screen to itself. The bar no longer holds menu entries, a 「More」 cell or pinned entries (objectstack#34594). Pins already stored are ignored, and the drawer's menu search and pin hint are gone. The drawer still opens with a swipe in from the left edge.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*/

import { describe, expect, it, vi, beforeEach } from 'vitest';
import { render, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import { MemoryRouter, Routes, Route, Navigate, useLocation } from 'react-router-dom';
import type { ReactNode } from 'react';

Expand All @@ -82,6 +82,11 @@ const metadata = vi.hoisted(() => ({
},
}));

/** objectstack#35881 — the width and the person's last app, varied by the phone cases. */
const phone = vi.hoisted(() => ({
value: { isPhone: false, lastApp: null as string | null, settled: true },
}));

/** The auth verdict each case varies. */
const auth = vi.hoisted(() => ({
value: { isAuthenticated: false, isLoading: false, user: null as any },
Expand All @@ -107,6 +112,8 @@ vi.mock('@object-ui/app-shell', async (importOriginal) => ({
<Navigate to={to} replace={replace} />
</>
),
usePhoneViewport: () => phone.value.isPhone,
useLastApp: () => ({ lastApp: phone.value.lastApp, settled: phone.value.settled, rememberApp: () => {} }),
SETUP_APP_PACKAGE_ID: 'com.objectstack.setup',
SETUP_APP_NAME: 'setup',
useMetadata: () => ({
Expand Down Expand Up @@ -187,6 +194,7 @@ const OTHER_APP = { name: 'showcase_app' };
beforeEach(() => {
metadata.value = { apps: [], loading: false, status: 'ready', refresh: vi.fn(async () => {}) };
auth.value = { isAuthenticated: false, isLoading: false, user: null };
phone.value = { isPhone: false, lastApp: null, settled: true };
});

// ── (b) The control QA used to isolate the defect ────────────────────────
Expand Down Expand Up @@ -390,3 +398,45 @@ describe('the landing carries the query and hash `/` arrived with', () => {
expect(screen.getByTestId('location-hash').textContent).toBe('');
});
});

// ── objectstack#35881, ruling 7045309332 (「上次用的优先」) ────────────────────
describe('a phone lands in the app the person used last (objectstack#35881)', () => {
beforeEach(() => {
auth.value.isAuthenticated = true;
metadata.value.apps = [OTHER_APP, DEFAULT_APP];
});

it('the last-used app wins over the declared default', () => {
phone.value = { isPhone: true, lastApp: 'showcase_app', settled: true };
renderAt('/');
expect(location()).toBe('/apps/showcase_app');
});

it('with no record yet it takes the declared default', () => {
phone.value = { isPhone: true, lastApp: null, settled: true };
renderAt('/');
expect(location()).toBe('/apps/crm_app');
});

it('waits while the record is still being read, then resolves without it after the wait', () => {
vi.useFakeTimers();
try {
phone.value = { isPhone: true, lastApp: null, settled: false };
renderAt('/');
expect(location()).toBe('/');
expect(screen.getByTestId('loading-fallback')).toBeInTheDocument();
act(() => {
vi.advanceTimersByTime(2000);
});
expect(location()).toBe('/apps/crm_app');
} finally {
vi.useRealTimers();
}
});

it('CONTROL — a desktop ignores the last app and keeps the declared default', () => {
phone.value = { isPhone: false, lastApp: 'showcase_app', settled: true };
renderAt('/');
expect(location()).toBe('/apps/crm_app');
});
});
45 changes: 44 additions & 1 deletion ui/apps/console/src/components/RootLandingRedirect.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.

import { describe, it, expect } from 'vitest';
import { resolveLandingPath, isAppListConclusive } from './RootLandingRedirect';
import { resolveLandingPath, resolvePhoneLandingPath, isAppListConclusive } from './RootLandingRedirect';

describe('resolveLandingPath', () => {
it('routes to the App marked isDefault (isDefault now ROUTES, not just badges)', () => {
Expand Down Expand Up @@ -185,3 +185,46 @@ describe('isAppListConclusive — is this list an answer, or an unknown?', () =>
expect(isAppListConclusive(undefined)).toBe(true);
});
});

// objectstack#35881, ruling 7045309332 (「上次用的优先」): on a phone the app the
// person used last wins; the declared default applies only when there is no
// record yet. One function, one test per order.
describe('resolvePhoneLandingPath — the last app first, then the desktop order', () => {
const APPS = [
{ name: 'crm', _packageId: 'com.acme.crm' },
{ name: 'cloud_control', isDefault: true },
{ name: 'service' },
];

it('the last-used app beats the declared default', () => {
expect(resolvePhoneLandingPath(APPS, 'service')).toBe('/apps/service');
});

it('the last-used app lands at its address segment (its package id when it has one)', () => {
expect(resolvePhoneLandingPath(APPS, 'crm')).toBe('/apps/com.acme.crm');
});

it('no record yet: the declared default', () => {
expect(resolvePhoneLandingPath(APPS, null)).toBe('/apps/cloud_control');
expect(resolvePhoneLandingPath(APPS, undefined)).toBe('/apps/cloud_control');
});

it('no record and no default: the single visible app, else /home', () => {
expect(resolvePhoneLandingPath([{ name: 'only' }], null)).toBe('/apps/only');
expect(resolvePhoneLandingPath([{ name: 'a' }, { name: 'b' }], null)).toBe('/home');
});

it('a last app that is gone, hidden or switched off is ignored', () => {
expect(resolvePhoneLandingPath(APPS, 'removed')).toBe('/apps/cloud_control');
expect(
resolvePhoneLandingPath([...APPS, { name: 'secret', hidden: true }], 'secret'),
).toBe('/apps/cloud_control');
expect(
resolvePhoneLandingPath([...APPS, { name: 'off', active: false }], 'off'),
).toBe('/apps/cloud_control');
});

it('CONTROL — the desktop resolver does not read the last app', () => {
expect(resolveLandingPath(APPS)).toBe('/apps/cloud_control');
});
});
51 changes: 49 additions & 2 deletions ui/apps/console/src/components/RootLandingRedirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
* declaration is the source of truth.)
*/

import { useEffect, useRef } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useLocation } from 'react-router-dom';
import {
useMetadata,
LoadingFallback,
RedirectWithSplash,
SETUP_APP_PACKAGE_ID,
SETUP_APP_NAME,
useLastApp,
usePhoneViewport,
} from '@object-ui/app-shell';
import type { MetadataTypeStatus } from '@object-ui/app-shell';

Expand Down Expand Up @@ -136,6 +138,39 @@ export function resolveLandingPath(apps: readonly LandingApp[] | null | undefine
return '/home';
}

/**
* The path `/` redirects to on a phone (objectstack#35881): the app this
* person last had open, when it is still an active, visible app; otherwise
* the three rules of {@link resolveLandingPath} (the declared default, the one
* app, the app list at `/home`).
*
* The order is the maintainer's ruling (record 7045309332 on #35881, Sales
* 2026-11-20 16:50Z, 「上次用的优先」): the last app beats a declared default,
* which decides only a first sign-in with no last app yet. From 768 px up `/`
* resolves as before, through {@link resolveLandingPath} alone.
*/
export function resolvePhoneLandingPath(
apps: readonly LandingApp[] | null | undefined,
lastApp: string | null | undefined,
): string {
const list = apps ?? [];
const last = lastApp
? list.find(
(a): a is LandingApp & { name: string } =>
a?.name === lastApp && a.active !== false && a.hidden !== true,
)
: undefined;
if (last) return `/apps/${landingSegment(list, last)}`;
return resolveLandingPath(apps);
}

/**
* How long a phone's `/` waits for the person's last app to be read before it
* resolves without it (objectstack#35881). The row rides the console's one
* preference read, which is normally in by the time the app list is.
*/
const LAST_APP_WAIT_MS = 2000;

/**
* Is the app list this resolver was handed an ANSWER, or an unknown standing
* in for one? (objectui#4233)
Expand Down Expand Up @@ -183,6 +218,15 @@ const APP_LIST_RETRY_DELAY_MS = 1500;
export function RootLandingRedirect() {
const { apps, loading, getTypeStatus, refresh } = useMetadata();
const location = useLocation();
// objectstack#35881 — a phone lands in the person's last app.
const phone = usePhoneViewport();
const { lastApp, settled: lastAppSettled } = useLastApp();
const [lastAppWaitOver, setLastAppWaitOver] = useState(false);
useEffect(() => {
if (!phone || lastAppSettled) return;
const id = setTimeout(() => setLastAppWaitOver(true), LAST_APP_WAIT_MS);
return () => clearTimeout(id);
}, [phone, lastAppSettled]);

// "Not yet" (`loading`) and "asked and failed" (`status === 'error'`) are
// both "no answer" — they differ only in whether waiting will help.
Expand All @@ -207,6 +251,7 @@ export function RootLandingRedirect() {
}, [unresolved, refresh]);

if (loading || unresolved) return <LoadingFallback />;
if (phone && !lastAppSettled && !lastAppWaitOver) return <LoadingFallback />;
// `RedirectWithSplash`, not a bare `<Navigate>` (objectui#6378). This is the
// widest measured instance of the boot blank: the line above holds the splash
// while the app list loads, and handing off to a null-rendering redirect left
Expand All @@ -217,6 +262,8 @@ export function RootLandingRedirect() {
// overlays (`?palette=1`, `?recordId=`) live in the query, and the landing is
// a bare `/apps/<segment>` or `/home`, so there is nothing to merge with. The
// app root it lands on carries them on to the app's own landing in turn.
const landing = resolveLandingPath(apps as LandingApp[] | undefined);
const landing = phone
? resolvePhoneLandingPath(apps as LandingApp[] | undefined, lastApp)
: resolveLandingPath(apps as LandingApp[] | undefined);
return <RedirectWithSplash to={`${landing}${location.search}${location.hash}`} replace />;
}
36 changes: 24 additions & 12 deletions ui/e2e/live/phone-nav-drawer-back-29131.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { test, expect, type Page } from '@playwright/test';
* browser's own, the close is an outside tap, and the reload is a real one,
* which keeps `history.state`.
*
* On a phone inside an app the drawer opens from the bottom menu bar's 「More」
* cell (objectstack#34594): the app bar's left slot holds the Back-to-home
* link there, not the sidebar trigger, which only the desktop control below
* still taps. Both open the same drawer through `setOpenMobile(true)`, so the
* history hook sees the same `openMobile` whichever control opened it.
* On a phone inside an app the drawer opens by a swipe in from the left edge:
* the bottom bar's 「More」 cell is gone (objectstack#35882, the app's menu is
* the app's home page, objectstack#35881), and the app bar's left slot holds
* 「‹」 back to that home, not the sidebar trigger, which only the desktop
* control below still taps. Both open the same drawer through
* `setOpenMobile(true)`, so the history hook sees the same `openMobile`
* whichever opened it.
*
* In `test:e2e:live:nightly`, not the required `:ci` allowlist.
*/
Expand All @@ -25,7 +27,8 @@ const APP = 'com.example.showcase';
const LIST = `/apps/${APP}/showcase_task`;
const DRAWER = '[data-sidebar="sidebar"][data-mobile="true"]';
const TRIGGER = 'button[data-sidebar="trigger"]';
const MORE = '[data-testid="phone-app-nav-more"]';
/** On a phone list the app bar's 「‹」, there once the page is drawn. */
const PHONE_BACK = '[data-testid="app-bar-phone-home"]';
const FLAG = '__navDrawerOpen';

async function openList(page: Page, opener: string) {
Expand All @@ -36,8 +39,17 @@ async function openList(page: Page, opener: string) {
await expect(page.locator(opener).first()).toBeVisible();
}

/** A swipe in from the left edge, the phone's drawer gesture (`UnifiedSidebar`). */
async function swipeFromEdge(page: Page) {
await page.evaluate(() => {
const touch = (x: number) => new Touch({ identifier: 1, target: document.body, clientX: x, clientY: 420 });
document.dispatchEvent(new TouchEvent('touchstart', { touches: [touch(10)], changedTouches: [touch(10)] }));
document.dispatchEvent(new TouchEvent('touchend', { touches: [], changedTouches: [touch(120)] }));
});
}

async function openDrawer(page: Page) {
await page.locator(MORE).first().tap();
await swipeFromEdge(page);
await expect(page.locator(DRAWER)).toBeVisible();
await expect.poll(() => drawerFlag(page)).toBe(true);
}
Expand All @@ -58,7 +70,7 @@ for (const width of [375, 390]) {
test.use({ viewport: { width, height: 844 }, isMobile: true, hasTouch: true });

test('Back with the drawer open closes it and stays on the list', async ({ page }) => {
await openList(page, MORE);
await openList(page, PHONE_BACK);
const url = page.url();
await openDrawer(page);

Expand All @@ -70,7 +82,7 @@ for (const width of [375, 390]) {
});

test('an outside tap closes the drawer and pops its entry: Back goes to the previous page', async ({ page }) => {
await openList(page, MORE);
await openList(page, PHONE_BACK);
const before = await historyLength(page);
await openDrawer(page);

Expand All @@ -87,7 +99,7 @@ for (const width of [375, 390]) {
});

test('choosing a nav entry replaces the drawer entry: Back returns to the list', async ({ page }) => {
await openList(page, MORE);
await openList(page, PHONE_BACK);
const listUrl = page.url();
await openDrawer(page);

Expand All @@ -112,12 +124,12 @@ for (const width of [375, 390]) {
});

test('a reload with the drawer open leaves it closed, with no flagged entry left', async ({ page }) => {
await openList(page, MORE);
await openList(page, PHONE_BACK);
await openDrawer(page);
const length = await historyLength(page);

await page.reload();
await expect(page.locator(MORE).first()).toBeVisible();
await expect(page.locator(PHONE_BACK).first()).toBeVisible();

await expect.poll(() => drawerFlag(page)).toBe(false);
await expect(page.locator(DRAWER)).toBeHidden();
Expand Down
18 changes: 17 additions & 1 deletion ui/packages/app-shell/src/console/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import { readItemPreferLocal, useReadItemsByName } from '../hooks/useObjectPrese
import { useLauncherApps } from '../hooks/useLauncherApps.js';
import { resolveRecordFormTarget, resolveRecordFormModalLayout, resolveFormViewChrome, selectRecordFormView, resolveNavigateCreateUrl, resolveNavigateEditUrl, resolvePostCreateTarget, recordFormCreateValues, readRecordFormCreateValues, RECORD_FORM_CREATE_VALUES_STATE } from '../utils/recordFormNavigation.js';
import { deriveRecordSurface, deriveRecordFlowSurface } from '@object-ui/plugin-view/core';
import { isPhoneViewportNow } from '../hooks/usePhoneViewport.js';
import { isPhoneViewportNow, usePhoneViewport } from '../hooks/usePhoneViewport.js';
import { PhoneAppHome } from '../layout/PhoneAppHome.js';
import { servedObjectLabel, servedObjectPluralLabel } from '../hooks/servedObjectLabel.js';
import { RECORD_DRAWER_PARAM, RECORD_FORM_PARAM, RECORD_FORM_OBJECT_PARAM, RECORD_FORM_LINK_PARAM } from '../urlParams.js';
import { appAddressSegment, appRouteSegment, canonicalAppPathname, matchAppBySegment } from '../utils/appRoute.js';
Expand Down Expand Up @@ -1968,6 +1969,11 @@ function AppRootLanding({
}) {
const gates = useNavMemberGates();
const location = useLocation();
// objectstack#35881 — on a phone the app's root is the app's home: its whole
// menu, drawn by the sidebar into this page (`PhoneAppHome`), rather than a
// redirect to its first entry. Read synchronously, so the first frame does
// not start a redirect a phone would then undo.
const phone = usePhoneViewport();
// objectstack#25338 — an app that names objects, none of which this member
// may read, has nothing for them: its dashboards and pages would answer a
// grid of "You don't have access" tiles. Say so once, before any landing is
Expand Down Expand Up @@ -2003,6 +2009,15 @@ function AppRootLanding({
gates.evaluateVisibility,
ctx,
);
// objectstack#35881 — a phone never redirects to an entry: the menu is the
// page. An app that shows this member no entry, now or once its pending
// reads answer, still says so.
if (phone) {
if (appServesNoNavigation(shownApp) && appServesNoNavigation(undecidedApp)) {
return <AppNoAccessEmptyState app={app} setupPath={setupPath} />;
}
return <PhoneAppHome basePath={location.pathname.replace(/\/+$/, '')} />;
}
if (
undecidedLanding !== landing ||
(!landing && appServesNoNavigation(shownApp) !== appServesNoNavigation(undecidedApp))
Expand All @@ -2027,6 +2042,7 @@ function AppRootLanding({
if (appServesNoNavigation(shownApp)) {
return <AppNoAccessEmptyState app={app} setupPath={setupPath} />;
}

// 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
Expand Down
Loading
Loading