mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-12 03:36:59 +00:00
feat(ui): make the core stack flow usable on mobile (#1327)
* feat(ui): make the core stack flow usable on mobile Below the md breakpoint the app collapses to a single full-width column: the stack list is full-screen, tapping a stack opens a full-screen detail with a Health / Logs / Compose segmented control (Logs first) and a back button, and a bottom tab bar switches Stacks, Fleet, Schedules, and Settings. Compose is read-only on a phone with a prompt to edit on desktop. Desktop (md and up) is unchanged: the mobile shell is gated behind a useIsMobile hook plus max-md/md variants, and the stack-detail blocks are shared with the desktop two-pane view so it renders identically. Also generalizes the unsaved-changes guard so leaving a dirty editor (back, tab bar, hamburger) prompts before discarding; adds 44px touch targets on list rows, filter chips, and actions; makes log and shell modals full-screen on mobile; and offsets toasts and the deploy pill above the bottom tab bar. * fix(ui): keep mobile nav in sync when opening views from outside the bottom bar On a phone the sidebar activity actions, the node switcher's Manage Nodes, the profile Settings entry, and the dashboard configuration links set the active view without flipping the mobile surface to content, so the user stayed on the stack list and never saw the destination. Route these through the mobile-aware navigation and settings helpers (a no-op on desktop).
This commit is contained in:
@@ -70,8 +70,10 @@ function makeOverlay(over: Partial<OverlayState> = {}): OverlayState {
|
||||
return {
|
||||
setPendingUnsavedLoad: vi.fn(),
|
||||
setPendingUnsavedNode: vi.fn(),
|
||||
setPendingLeaveAction: vi.fn(),
|
||||
pendingUnsavedLoad: null,
|
||||
pendingUnsavedNode: null,
|
||||
pendingLeaveAction: null,
|
||||
policyBlock: null,
|
||||
setPolicyBlock: vi.fn(),
|
||||
setPolicyBypassing: vi.fn(),
|
||||
@@ -300,3 +302,52 @@ describe('useStackActions.bypassPolicyAndRetry', () => {
|
||||
expect(apiFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('useStackActions.attemptLeaveEditor (mobile back / nav guard)', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(apiFetch).mockReset();
|
||||
});
|
||||
|
||||
it('stashes the navigation when the editor is dirty instead of running it', () => {
|
||||
const perform = vi.fn();
|
||||
// Default fixture: content !== originalContent and a stack is selected → dirty.
|
||||
const { result, overlayState } = setup();
|
||||
result.current.attemptLeaveEditor(perform);
|
||||
expect(perform).not.toHaveBeenCalled();
|
||||
expect(overlayState.setPendingLeaveAction).toHaveBeenCalledWith({ run: perform });
|
||||
});
|
||||
|
||||
it('runs the navigation immediately when the editor is clean', () => {
|
||||
const perform = vi.fn();
|
||||
const { result, overlayState } = setup({
|
||||
editorState: { content: 'same', originalContent: 'same' },
|
||||
});
|
||||
result.current.attemptLeaveEditor(perform);
|
||||
expect(perform).toHaveBeenCalledTimes(1);
|
||||
expect(overlayState.setPendingLeaveAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('runs the stashed leave action and clears it on discardAndLoadPending', () => {
|
||||
const run = vi.fn();
|
||||
const { result, overlayState, editorState } = setup({ overlay: { pendingLeaveAction: { run } } });
|
||||
result.current.discardAndLoadPending();
|
||||
expect(run).toHaveBeenCalledTimes(1);
|
||||
expect(overlayState.setPendingLeaveAction).toHaveBeenCalledWith(null);
|
||||
expect(editorState.setContent).toHaveBeenCalledWith(editorState.originalContent);
|
||||
});
|
||||
|
||||
it('gives a stashed leave action precedence over a coexisting pending load', () => {
|
||||
const run = vi.fn();
|
||||
const { result } = setup({ overlay: { pendingLeaveAction: { run }, pendingUnsavedLoad: 'other.yml' } });
|
||||
result.current.discardAndLoadPending();
|
||||
expect(run).toHaveBeenCalledTimes(1);
|
||||
// The leave branch returns before the load branch, so no stack fetch fires.
|
||||
expect(apiFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('clears a stashed leave action on cancel', () => {
|
||||
const { result, overlayState } = setup({ overlay: { pendingLeaveAction: { run: vi.fn() } } });
|
||||
result.current.cancelPendingUnsavedLoad();
|
||||
expect(overlayState.setPendingLeaveAction).toHaveBeenCalledWith(null);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user