fix(topbar): mobile overflow menu reaches Version history and the command palette
On mobile the collapsed topbar had no route to Version history, Export ZIP, Business profile or the command palette. Add a 'Version history' item (only when the site.history command is registered, run through the registry) and a 'More commands…' item that opens the command palette. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c62a333257
commit
49ed687c3b
3 files changed
+84
-2
No files matched your search
@@ -88,7 +88,12 @@ vi.mock('../sitesmith/SitesmithButton', () => ({ SitesmithButton: () => null }))
|
||||
const openPaletteMock = vi.fn();
|
||||
vi.mock('../command-palette/CommandPalette', () => ({ openCommandPalette: () => openPaletteMock() }));
|
||||
|
||||
const mobileFixture = { isMobile: false };
|
||||
vi.mock('../../hooks/useIsMobile', () => ({ useIsMobile: () => mobileFixture.isMobile }));
|
||||
|
||||
import { TopBar } from './TopBar';
|
||||
import { MobileChromeProvider } from '../../state/MobileChromeContext';
|
||||
import { registerCommand } from '../../editor/commands';
|
||||
import { EditorConfigProvider } from '../../state/EditorConfigContext';
|
||||
import { WhpConfig } from '../../types';
|
||||
|
||||
@@ -149,6 +154,7 @@ afterEach(() => {
|
||||
checkFixture.footerState = null;
|
||||
checkFixture.editingGlobal = false;
|
||||
openPaletteMock.mockReset();
|
||||
mobileFixture.isMobile = false;
|
||||
});
|
||||
|
||||
describe('TopBar publish-warnings wiring', () => {
|
||||
@@ -430,3 +436,57 @@ describe('TopBar Preview head parity (item 14)', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('TopBar mobile overflow menu reaches history and the command palette', () => {
|
||||
function renderMobile() {
|
||||
mobileFixture.isMobile = true;
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
act(() => {
|
||||
root = createRoot(container);
|
||||
root.render(
|
||||
<EditorConfigProvider config={whpConfig}>
|
||||
<MobileChromeProvider>
|
||||
<TopBar showGuides={false} onToggleGuides={() => {}} />
|
||||
</MobileChromeProvider>
|
||||
</EditorConfigProvider>,
|
||||
);
|
||||
});
|
||||
act(() => {
|
||||
container.querySelector<HTMLButtonElement>('button[aria-label="More options"]')!
|
||||
.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
});
|
||||
}
|
||||
const item = (label: string) =>
|
||||
Array.from(container.querySelectorAll<HTMLButtonElement>('.topbar-overflow-item'))
|
||||
.find((b) => (b.textContent || '').includes(label)) || null;
|
||||
|
||||
test('"More commands…" opens the command palette', () => {
|
||||
renderMobile();
|
||||
const btn = item('More commands');
|
||||
expect(btn).not.toBeNull();
|
||||
act(() => { btn!.dispatchEvent(new MouseEvent('click', { bubbles: true })); });
|
||||
expect(openPaletteMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('"Version history" appears only when site.history is registered, and runs it', async () => {
|
||||
renderMobile();
|
||||
expect(item('Version history')).toBeNull();
|
||||
act(() => { root.unmount(); });
|
||||
container.remove();
|
||||
const run = vi.fn();
|
||||
const off = registerCommand({ id: 'site.history', title: 'Version history…', group: 'site', run });
|
||||
try {
|
||||
renderMobile();
|
||||
const btn = item('Version history');
|
||||
expect(btn).not.toBeNull();
|
||||
await act(async () => {
|
||||
btn!.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
await Promise.resolve();
|
||||
});
|
||||
expect(run).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
off();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useState, useEffect, useRef } from 'react';
|
||||
import React, { useCallback, useState, useEffect, useRef, useSyncExternalStore } from 'react';
|
||||
import { useEditor } from '@craftjs/core';
|
||||
import { useEditorConfig } from '../../state/EditorConfigContext';
|
||||
import { useWhpApi, SaveOptions } from '../../hooks/useWhpApi';
|
||||
@@ -22,7 +22,7 @@ import { SaveStatusPill, SaveStatus } from './SaveStatusPill';
|
||||
import { useSaveGuard } from '../../state/SaveGuardContext';
|
||||
import { SitesmithButton } from '../sitesmith/SitesmithButton';
|
||||
import { useSitesmithModal } from '../../state/SitesmithContext';
|
||||
import { useRegisterCommands } from '../../editor/commands';
|
||||
import { getCommand, subscribeCommands, useRegisterCommands, useRunCommand } from '../../editor/commands';
|
||||
import { TopBarCommandMenu } from './TopBarCommandMenu';
|
||||
import { openCommandPalette } from '../command-palette/CommandPalette';
|
||||
|
||||
@@ -69,6 +69,11 @@ export const TopBar: React.FC<TopBarProps> = ({ showGuides, onToggleGuides }) =>
|
||||
const [reportOpen, setReportOpen] = useState(false);
|
||||
const isMobile = useIsMobile();
|
||||
const { open: openSitesmith } = useSitesmithModal();
|
||||
// Mobile overflow: Version history only when its command is registered.
|
||||
// A boolean snapshot (not useCommandState) so TopBar's own per-render
|
||||
// command re-registration doesn't re-render it in a loop.
|
||||
const hasHistory = useSyncExternalStore(subscribeCommands, () => !!getCommand('site.history'));
|
||||
const runCommand = useRunCommand();
|
||||
const savingRef = useRef(false);
|
||||
const publishingRef = useRef(false);
|
||||
// Read at tick time by autosaveDue, never a stale closure.
|
||||
@@ -447,6 +452,8 @@ export const TopBar: React.FC<TopBarProps> = ({ showGuides, onToggleGuides }) =>
|
||||
onOpenHeadCode={() => setHeadCodeModalOpen(true)}
|
||||
onOpenReportIssue={() => setReportOpen(true)}
|
||||
onPreview={handlePreview}
|
||||
onOpenCommandPalette={() => openCommandPalette()}
|
||||
onOpenHistory={hasHistory ? () => { void runCommand('site.history'); } : undefined}
|
||||
sitesmithNode={<SitesmithButton onClick={() => openSitesmith()} disabled={!canSave} />}
|
||||
editingDisabled={!canSave}
|
||||
templatesDisabled={isEditingGlobal}
|
||||
|
||||
@@ -11,6 +11,11 @@ export interface TopBarOverflowMenuProps {
|
||||
onOpenHeadCode: () => void;
|
||||
onOpenReportIssue: () => void;
|
||||
onPreview: () => void;
|
||||
/** Opens the command palette -- the mobile route to every registered
|
||||
* command (Export ZIP, Business profile, ...) that has no item here. */
|
||||
onOpenCommandPalette: () => void;
|
||||
/** Present only when the `site.history` command is registered. */
|
||||
onOpenHistory?: () => void;
|
||||
/** Rendered `<SitesmithButton onClick={...} />` -- passed in rather than
|
||||
* re-implemented here so the mobile menu reuses the exact same
|
||||
* lock/cap-aware button the desktop topbar shows. */
|
||||
@@ -37,6 +42,8 @@ export const TopBarOverflowMenu: React.FC<TopBarOverflowMenuProps> = ({
|
||||
onOpenHeadCode,
|
||||
onOpenReportIssue,
|
||||
onPreview,
|
||||
onOpenCommandPalette,
|
||||
onOpenHistory,
|
||||
sitesmithNode,
|
||||
editingDisabled,
|
||||
templatesDisabled,
|
||||
@@ -97,6 +104,14 @@ export const TopBarOverflowMenu: React.FC<TopBarOverflowMenuProps> = ({
|
||||
<button type="button" className="topbar-overflow-item" role="menuitem" disabled={editingDisabled} onClick={runAndClose(onOpenHeadCode)}>
|
||||
<i className="fa fa-code" aria-hidden="true" /> Head Code
|
||||
</button>
|
||||
{onOpenHistory && (
|
||||
<button type="button" className="topbar-overflow-item" role="menuitem" onClick={runAndClose(onOpenHistory)}>
|
||||
<i className="fa fa-history" aria-hidden="true" /> Version history
|
||||
</button>
|
||||
)}
|
||||
<button type="button" className="topbar-overflow-item" role="menuitem" onClick={runAndClose(onOpenCommandPalette)}>
|
||||
<i className="fa fa-search" aria-hidden="true" /> More commands…
|
||||
</button>
|
||||
<button type="button" className="topbar-overflow-item" role="menuitem" onClick={runAndClose(onOpenReportIssue)}>
|
||||
<i className="fa fa-bug" aria-hidden="true" /> Report an issue
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user