Files
PaperClipAI/ui/src/pages/AgentAdvancedTab.tsx
T
Dotta ffd8dcb4af fix(ui): clear mobile bottom nav on overlays and wrap mobile toolbars (#23045)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The board UI renders a fixed mobile bottom navigation bar
(`MobileBottomNav`, height `4rem` plus safe-area inset) and shared
collection toolbars on narrow viewports below `48rem`.
> - On mobile viewports (375px–390px), multi-control toolbars clip
actions off-screen, hidden org-chart controls reserve invisible width in
agent list view, and fixed or sticky footers and floating overlays
either hide behind `MobileBottomNav`, overlap it, or overflow the right
edge.
> - Operators on mobile cannot reach save, discard, retry, wizard
navigation, or toolbar filter controls when those surfaces collide with
the bottom navigation bar or clip off-screen.
> - This pull request adds shared mobile bottom-nav clearance tokens and
responsive rules in `ui/src/index.css`, lifts fixed/sticky footers and
floating overlays above `MobileBottomNav` on `< md` while constraining
horizontal fit at 375px+, wraps `.design-toolbar-actions` and collapses
hidden org-chart controls below `48rem`, and adds unit tests and mobile
Storybook stories.
> - The benefit is that every mobile toolbar, save bar, wizard footer,
bulk selection bar, toast, retry alert, and voice call panel stays fully
visible, reachable, and within the viewport width without changing
desktop layouts.

## Linked Issues or Issue Description

**What happened?**

On viewports narrower than `48rem` (such as 375px–390px mobile screens):
- `.design-toolbar-actions` did not wrap on mobile, pushing trailing
controls (such as Group by and View dropdowns in Coordinator Inbox)
off-screen into `overflow-x-clip`.
- `.agents-org-controls-reveal` reserved invisible `width: max-content`
space next to `New Agent` in mobile list view.
- `AgentAdvancedTab` (`sticky bottom-0 z-10`) and `ProfileWizard`
(`fixed inset-x-0 bottom-0 z-10`) footers sat behind `MobileBottomNav`
(`z-30`, `h-16`).
- `.agent-config-save-bar` (`bottom: 0; z-index: 40`) covered
`MobileBottomNav`, and `.agent-selection-bar` (`--selection-bar-bottom:
48px`) overlapped its top 16px.
- `ToastViewport` (`bottom-3 left-3 w-full max-w-sm`) overlapped
`MobileBottomNav` and overflowed the right edge by 12px at 375px.
- `IssueRowDetailsNotice` and `VoiceCallProvider` sat at `bottom-4` on
top of `MobileBottomNav` and lacked mobile horizontal containment /
viewport-safe max-height.

**Expected behavior**

- Multi-control toolbars wrap cleanly inside the mobile viewport, and
hidden org-chart controls occupy zero space in mobile list view.
- Fixed and sticky footers (`AgentConfigSaveBar`, `AgentAdvancedTab`,
`ProfileWizard`) and floating overlays (`.agent-selection-bar`,
`ToastViewport`, `IssueRowDetailsNotice`, `VoiceCallProvider`) clear
`MobileBottomNav` on `< md` viewports and stay within 375px–390px
horizontal bounds.
- Desktop (`>= 48rem`) layout and positioning remain unchanged.

**Steps to reproduce**

1. Open the Paperclip board UI at a `390x844` or `375x812` mobile
viewport.
2. Open Coordinator Inbox or Agents list view and inspect
`.design-toolbar-actions` and `.agents-org-controls-reveal`.
3. Open Agent settings (Identity/Runtime/Advanced), Tool Profile Wizard,
Agent bulk selection, or trigger a toast, row-details retry alert, or
active voice call panel while `MobileBottomNav` is visible.

**Paperclip version or commit**

`85ad16b47e` (`master`)

## What Changed

- **`ui/src/index.css`**:
- Added `--mobile-nav-overlay-bottom` (`calc(4rem + var(--spacing) * 3 +
var(--sz-safe-bottom))`) and `--mobile-nav-overlay-max-h` tokens for
floating overlays mounted outside `<main>`.
- Added `@media (width < 48rem)` rules to wrap `.design-toolbar-actions`
(`flex-wrap: wrap; min-width: 0; max-width: 100%`), expand
`[data-canonical-toolbar="inbox"] [data-toolbar-search]` to `width:
100%`, and collapse hidden
`.agents-org-controls-reveal:not([data-visible="true"])` (`display:
none`).
- Lifted `.agent-selection-bar` (`--selection-bar-bottom: calc(4rem +
var(--spacing) * 3)`) and `.agent-config-save-bar` (`bottom:
var(--tc-composer-bottom)`, `z-index: var(--z-20)`, mobile padding, full
slide-out transform when hidden, and matching
`.agent-settings-with-save-bar` bottom clearance) below `48rem` while
preserving cascade and `prefers-reduced-motion: reduce` ordering.
- **`ui/src/pages/AgentAdvancedTab.tsx`**: Updated the sticky save
footer to use `mobile-nav-composer`, `bottom-(--tc-composer-bottom)`,
`z-20`, `flex-wrap`, and `md:bottom-0`.
- **`ui/src/pages/tools/profiles/ProfileWizard.tsx`**: Updated the fixed
wizard footer to use `mobile-nav-composer`,
`bottom-(--tc-composer-bottom)`, `z-20`, `md:bottom-0`, and `flex-wrap`,
and increased mobile container bottom padding (`pb-36 md:pb-24`).
- **`ui/src/components/ToastViewport.tsx`**: Lifted toasts with
`bottom-(--mobile-nav-overlay-bottom) md:bottom-3` and replaced `left-3
w-full` with `inset-x-3 sm:inset-x-auto sm:left-3 sm:w-full` to
eliminate 375px right-edge overflow.
- **`ui/src/components/IssueRowDetailsNotice.tsx`**: Lifted above
`MobileBottomNav` with `bottom-(--mobile-nav-overlay-bottom)
md:bottom-4` and bounded mobile width with `inset-x-4 flex-wrap
sm:left-auto sm:right-4 sm:max-w-sm sm:flex-nowrap`.
- **`ui/src/components/voice/VoiceCallProvider.tsx`**: Lifted the active
voice panel with `bottom-(--mobile-nav-overlay-bottom)
max-h-(--mobile-nav-overlay-max-h) md:bottom-4 md:max-h-(--sz-calc-18)`.
- **Tests & Storybook**: Added `ui/src/index.mobile-overlays.test.ts`,
`ui/src/components/IssueRowDetailsNotice.test.tsx`,
`ui/src/components/voice/VoiceCallProvider.test.tsx`,
`ui/src/pages/AgentAdvancedTab.test.tsx`,
`ui/src/pages/tools/profiles/ProfileWizard.test.tsx`, expanded
`ui/src/components/ToastViewport.test.tsx`, and added catalog-compliant
mobile stories in
`ui/storybook/stories/navigation-preferences/mobile-overlays-clearance.stories.tsx`.

## Verification

- `pnpm --filter @paperclipai/ui exec vitest run
src/components/ToastViewport.test.tsx
src/components/IssueRowDetailsNotice.test.tsx
src/components/voice/VoiceCallProvider.test.tsx
src/pages/AgentAdvancedTab.test.tsx
src/pages/tools/profiles/ProfileWizard.test.tsx
src/index.mobile-overlays.test.ts` — 6 test files passed, 14/14 tests
passed.
- `pnpm --filter @paperclipai/ui exec vitest run
src/lib/analytics/replay-masking.test.tsx` — 220/220 tests passed.
- `pnpm --filter @paperclipai/ui typecheck` — passed with 0 errors.
- `pnpm check:token-gates` — all 4 token gates clean and `cliplab
character in sync`.
- `node scripts/storybook-catalog.mjs --check` — passed (373 files, 3491
stories).
- `node --test scripts/check-maps.test.mjs
scripts/storybook-catalog.test.mjs
scripts/storybook-feature-index.test.mjs` — 30/30 tests passed.
- Full-repo Vitest and browser E2E suites were not run locally; CI will
run the required repository checks on this PR.

## Risks

- Low risk. All positioning changes are scoped to `< md` / `< 48rem`
viewports using existing CSS custom property conventions
(`--tc-composer-bottom`, `--tc-composer-visible-nav-offset`,
`--sz-safe-bottom`), leaving desktop (`>= 48rem`) layouts unchanged.
- Floating overlays outside `<main>` (`ToastViewport`,
`IssueRowDetailsNotice`, `VoiceCallProvider`, `.agent-selection-bar`)
use the fixed `--mobile-nav-overlay-bottom` offset so they always clear
`MobileBottomNav` even when rendered in `document.body` portals; when
`MobileBottomNav` auto-hides on scroll, those overlays remain at the
safe clearance height rather than tracking `<main>`'s scroll state.

## Model Used

- Provider and model: Google Antigravity — Gemini 4 Neon (High)
- Capabilities: tool use, code editing, local terminal/test execution

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-27 13:41:39 +00:00

192 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describeError } from "@/api/errors";
import { useEffect, useMemo, useRef, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { basicSetup } from "codemirror";
import { Compartment, EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { yaml } from "@codemirror/lang-yaml";
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
import { tags } from "@lezer/highlight";
import type { Agent } from "@paperclipai/shared";
import { Button } from "../components/ui/button";
import { useToastActions } from "../context/ToastContext";
import { queryKeys } from "../lib/queryKeys";
import { parseAgentConfigurationYaml, serializeAgentConfigurationDocument } from "../lib/agent-configuration-yaml";
import { loadAgentConfiguration, type AgentConfigurationSnapshot } from "../lib/agent-configuration/load";
import { ConfigurationSaveInterrupted, planAgentConfiguration, saveAgentConfiguration, type ConfigurationReceipt } from "../lib/agent-configuration/save";
import { compactAgentConfiguration } from "../lib/agent-configuration/compact";
const editableYaml = (configuration: AgentConfigurationSnapshot) => serializeAgentConfigurationDocument(compactAgentConfiguration(configuration.document));
const yamlHighlightStyle = HighlightStyle.define([
{ tag: tags.propertyName, class: "text-primary" },
{ tag: tags.string, class: "text-foreground" },
{ tag: [tags.bool, tags.number, tags.null], class: "text-muted-foreground" },
{ tag: tags.keyword, class: "text-primary" },
{ tag: tags.comment, class: "text-muted-foreground" },
]);
export interface AgentAdvancedTabProps {
agent: Agent;
onDirtyChange: (dirty: boolean) => void;
onSaved: (updated: Agent) => void;
onSavingChange?: (saving: boolean) => void;
}
export function AgentAdvancedTab(props: AgentAdvancedTabProps) {
const [initial, setInitial] = useState<AgentConfigurationSnapshot | null>(null);
const query = useQuery({
queryKey: ["agent-configuration-yaml", props.agent.companyId, props.agent.id],
queryFn: () => loadAgentConfiguration(props.agent.id, props.agent.companyId),
refetchOnWindowFocus: false,
});
useEffect(() => {
if (!initial && query.data && !query.isFetching) setInitial(query.data);
}, [initial, query.data, query.isFetching]);
if (!initial) {
if (query.error) return <div role="alert" className="space-y-3 text-sm">
<p>{describeError(query.error).body}</p>
<Button variant="outline" onClick={() => query.refetch()}>Retry</Button>
</div>;
return <p role="status" className="text-sm text-muted-foreground">Loading configuration…</p>;
}
return <ConfigurationEditor key={props.agent.id} {...props} initial={initial} />;
}
function ConfigurationEditor({ agent, initial, onDirtyChange, onSaved, onSavingChange }: AgentAdvancedTabProps & { initial: AgentConfigurationSnapshot }) {
const queryClient = useQueryClient();
const { pushToast } = useToastActions();
const [saved, setSaved] = useState(initial);
const [source, setSource] = useState(() => editableYaml(initial));
const [error, setError] = useState<string | null>(null);
const [reloadRequired, setReloadRequired] = useState(false);
const [progress, setProgress] = useState("");
const [receipts, setReceipts] = useState<ConfigurationReceipt[]>([]);
const operationPending = useRef(false);
const active = useRef(true);
useEffect(() => { active.current = true; return () => { active.current = false; }; }, []);
const original = useMemo(() => editableYaml(saved), [saved]);
const dirty = source !== original;
const validation = useMemo(() => {
try {
const document = parseAgentConfigurationYaml(source);
return { document, changes: planAgentConfiguration(saved, document).map(step => step.label), error: null };
} catch (cause) { return { document: null, changes: [], error: cause instanceof Error ? cause.message : "Invalid YAML" }; }
}, [source, saved]);
useEffect(() => { onDirtyChange(dirty || reloadRequired); }, [dirty, reloadRequired, onDirtyChange]);
useEffect(() => () => onDirtyChange(false), [onDirtyChange]);
const save = useMutation({
mutationFn: async () => {
if (!validation.document) throw new Error(validation.error ?? "Invalid YAML");
if (reloadRequired) throw new Error("Reload saved before saving again.");
return saveAgentConfiguration(saved, validation.document,
receipt => { if (active.current) setReceipts(current => [...current, receipt]); },
label => { if (active.current) setProgress(label); });
},
onSuccess: configuration => {
queryClient.invalidateQueries({ queryKey: queryKeys.agents.detail(agent.id) });
queryClient.invalidateQueries({ queryKey: queryKeys.agents.detail(agent.urlKey) });
queryClient.invalidateQueries({ queryKey: queryKeys.agents.list(agent.companyId) });
queryClient.setQueryData(["agent-configuration-yaml", agent.companyId, agent.id], configuration);
if (!active.current) return;
setSaved(configuration);
setSource(editableYaml(configuration));
setError(null);
onDirtyChange(false);
setReloadRequired(false);
onSaved(configuration.agent);
const warnings = configuration.agent.configurationWarnings;
pushToast({ title: "Agent saved", tone: warnings?.length ? "warn" : "success", body: warnings?.map(warning => warning.message).join("\n") });
},
onSettled: () => {
operationPending.current = false;
queryClient.invalidateQueries({ predicate: query => query.queryKey.some(part => part === agent.id || part === agent.companyId), refetchType: "none" });
},
onError: cause => {
if (!active.current) return;
setError(cause.message);
if (cause instanceof ConfigurationSaveInterrupted) setReloadRequired(true);
},
});
const reload = useMutation({
mutationFn: () => loadAgentConfiguration(agent.id, agent.companyId),
onSuccess: updated => {
queryClient.setQueryData(["agent-configuration-yaml", agent.companyId, agent.id], updated);
queryClient.invalidateQueries({ queryKey: queryKeys.agents.detail(agent.id) });
queryClient.invalidateQueries({ queryKey: queryKeys.agents.detail(agent.urlKey) });
queryClient.invalidateQueries({ queryKey: queryKeys.agents.list(agent.companyId) });
if (active.current) { setSaved(updated); setSource(editableYaml(updated)); setError(null); setReloadRequired(false); onSaved(updated.agent); }
},
onSettled: () => { operationPending.current = false; },
onError: cause => setError(cause.message),
});
const busy = save.isPending || reload.isPending;
useEffect(() => { onSavingChange?.(busy); }, [busy, onSavingChange]);
useEffect(() => () => onSavingChange?.(false), [onSavingChange]);
return <div className="space-y-4">
<p className="text-sm text-muted-foreground">Omitted settings stay unchanged. Instruction file contents, inherited access, and history are available in their settings tabs.</p>
{receipts.length > 0 && <div className="space-y-3 rounded-md border border-border p-4" aria-label="Created credentials">
{receipts.map((receipt, index) => <div key={`${receipt.id}-${index}`} className="space-y-2 text-sm">
<p className="font-medium">{receipt.label}</p>
{receipt.token ? <>
<p className="text-muted-foreground">Copy this key now. It won’t be shown again after leaving this page.</p>
<input readOnly aria-label={`${receipt.label} token`} value={receipt.token} className="w-full rounded-md border border-border bg-muted p-2 font-mono text-sm" />
</> : <p className="font-mono text-muted-foreground">{receipt.id}</p>}
</div>)}
</div>}
<AgentYamlEditor value={source} onChange={value => { setSource(value); if (!reloadRequired) setError(null); }} readOnly={busy} />
{dirty && validation.changes.length > 0 && <details className="rounded-md border border-border p-3 text-sm">
<summary className="cursor-pointer font-medium">{validation.changes.length} {validation.changes.length === 1 ? "change" : "changes"} to apply</summary>
<ul className="mt-2 list-inside list-disc space-y-1">{validation.changes.map((label, index) => <li key={index}>{label}</li>)}</ul>
<p className="mt-2 text-muted-foreground">Changes save in this order. If one fails, earlier changes remain saved.</p>
</details>}
{(validation.error || error) && <p role="alert" className="whitespace-pre-wrap text-sm text-destructive">{validation.error || error}</p>}
<footer className="mobile-nav-composer sticky bottom-(--tc-composer-bottom) z-20 flex flex-wrap items-center justify-between gap-3 border-t border-border bg-background py-4 md:bottom-0">
<Button variant="ghost" disabled={busy} onClick={() => { if (!operationPending.current) { operationPending.current = true; reload.mutate(); } }}>Reload saved</Button>
<div className="flex flex-wrap items-center gap-3">
<span role="status" className="flex items-center gap-2 text-xs text-muted-foreground">
{!save.isPending && !reload.isPending && dirty ? <span aria-hidden className="size-1.5 shrink-0 rounded-full bg-(--agent-detail-dot-unsaved)" /> : null}
{save.isPending ? `Saving: ${progress || "configuration"}…` : reload.isPending ? "Loading configuration…" : dirty ? validation.document && !validation.changes.length ? "No configuration changes" : "Unsaved changes" : "No unsaved changes"}
</span>
<Button disabled={!dirty || busy || reloadRequired || !validation.document || !validation.changes.length} onClick={() => { if (!operationPending.current) { operationPending.current = true; save.mutate(); } }}>{save.isPending ? "Saving…" : "Save changes"}</Button>
</div>
</footer>
</div>;
}
function AgentYamlEditor({ value, onChange, readOnly }: { value: string; onChange: (value: string) => void; readOnly: boolean }) {
const container = useRef<HTMLDivElement>(null);
const editor = useRef<EditorView | null>(null);
const editability = useRef(new Compartment());
const change = useRef(onChange);
change.current = onChange;
const current = useRef(value);
current.current = value;
useEffect(() => {
if (!container.current) return;
const view = new EditorView({
parent: container.current,
state: EditorState.create({ doc: current.current, extensions: [
basicSetup, yaml(),
syntaxHighlighting(yamlHighlightStyle),
EditorView.contentAttributes.of({ "aria-label": "Agent YAML configuration", spellcheck: "false" }),
editability.current.of([EditorState.readOnly.of(readOnly), EditorView.editable.of(!readOnly)]),
EditorView.updateListener.of(update => { if (update.docChanged) change.current(update.state.doc.toString()); }),
] }),
});
editor.current = view;
return () => { view.destroy(); editor.current = null; };
}, []);
useEffect(() => {
editor.current?.dispatch({ effects: editability.current.reconfigure([
EditorState.readOnly.of(readOnly), EditorView.editable.of(!readOnly),
]) });
}, [readOnly]);
useEffect(() => {
const view = editor.current;
if (view && view.state.doc.toString() !== value) view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: value } });
}, [value]);
return <div ref={container} className="agent-yaml-editor overflow-hidden rounded-lg" />;
}