mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Operators use the board UI on mobile viewports (`390x844`) to inspect routines, members, costs, projects, dashboards, skills, and settings > - Wide tables overflowed the page horizontally, several `PageTabBar` callers omitted `value`/`onValueChange` (breaking their mobile section dropdowns), `w-96` popovers and floating save bars clipped or overlapped the bottom nav, and key controls were hover-only or cramped on narrow screens > - Mobile operators could not scroll clipped columns, switch sections, switch diff files, or tap hidden row actions on phones > - This pull request constrains table scrollers and flex/grid ancestors, wires all missing `PageTabBar` mobile callbacks, caps wide popovers and floating save bars using existing viewport tokens, polishes narrow layouts across collections and settings, and adds 390×844 Storybook views and Vitest regressions > - The benefit is clean mobile layout without horizontal page overflow and working touch controls across tables, tabs, popovers, dashboards, and settings ## Linked Issues or Issue Description Related mobile responsiveness PRs: #23045, #23046, #23047. **What happened?** On mobile viewports (`< 768px`, tested at `390x844`): - Wide tables in Routines, Members, Costs, Connections, and tool profile views caused horizontal page overflow or permanently clipped columns (`overflow-hidden`). - `AuditHub`, `Costs` (Providers/Billers), `Approvals`, `Inbox`, and `LegacyInbox` omitted `value` and/or `onValueChange` on `PageTabBar`, bypassing its mobile `<select>` section switcher. - `w-96` popovers in `RoutinePage` and `WorkspaceServiceControlBar` overflowed narrow viewports; the `CompanySkills` diff dialog hid its file picker on `< md` and its floating save bar overlapped `MobileBottomNav`. - `ProjectDetail` task toolbars crushed the search field on `< sm`, `Dashboard` charts rendered 2 cramped columns with uneven metric card heights, `Agents` hid row `Chat` buttons on touch devices, and `Inbox` hid nesting controls on `< sm`. **Expected behavior** Every collection, table, popover, dashboard, and settings screen stays within the mobile viewport (`scrollWidth <= innerWidth`), wide tables scroll horizontally inside their containers, mobile `PageTabBar` dropdowns switch sections cleanly, and touch users can reach all row actions, diff files, and nesting controls. **Steps to reproduce** 1. Open the board UI at `390x844` (or the added Storybook `*Mobile` stories). 2. Navigate to Routines, Settings → Members, Settings → Profile, Audit → Costs, Approvals, Project Detail, Dashboard, and Company Skills diff view. 3. Observe horizontal overflow, missing mobile tab switchers, hidden diff file picker, and cramped toolbars/charts prior to this change. **Paperclip version or commit** `85ad16b47e` (`master`) **Deployment mode** Local dev (pnpm dev) ## What Changed - **Horizontal table scroll containment & ancestor constraints**: - Wrapped and constrained tables plus flex/grid ancestors (`overflow-x-auto max-w-full`, `min-w-0`) in `RoutineTable.tsx`, `Routines.tsx`, `CompanyAccess.tsx`, `CostByUserTable.tsx`, `Costs.tsx`, `ProfileSettings.tsx`, `Connections.tsx`, `AgentToolsTab.tsx`, `RoutineHistoryTab.tsx`, `RoutineVariablesEditor.tsx`, `ProfilesTab.tsx`, `ProfileDetail.tsx`, `ProfilesIndex.tsx`, and `SmokeLabTab.tsx`. - Fixed `ProfileSettings.tsx` avatar upload `<label>` sizing (`inline-block w-fit`) so the camera badge stays anchored to the avatar circle. - **Wired missing `PageTabBar` mobile callbacks**: - Passed `value` and `onValueChange` to `PageTabBar` in `AuditHub.tsx`, `Costs.tsx` (Providers and Billers), `Approvals.tsx`, `Inbox.tsx`, and `LegacyInbox.tsx`. - **Popovers & floating bars**: - Capped `w-96` popovers in `RoutinePage.tsx` and `WorkspaceServiceControlBar.tsx` with `max-w-(--sz-calc-4)` and wrapping footer rows. - Added a mobile file `<select>` (`md:hidden`) in the `CompanySkills.tsx` version diff dialog and lifted its floating save bar above `MobileBottomNav` (`bottom-20 md:bottom-6 max-w-(--sz-calc-4) flex-wrap`). - **Touch visibility & responsive layout polish**: - Switched `ProjectDetail.tsx` task lists to `toolbarPresentation="collection"` so the toolbar wraps cleanly on `< sm`, and added `flex-wrap` to its left-membership notice banner. - Made the `Agents.tsx` inline row `Chat` button touch-visible via `pointer-coarse:opacity-100`. - Exposed mobile parent-child nesting toggle and row expand chevrons in `Inbox.tsx` and `LegacyInbox.tsx`. - Stacked `Dashboard.tsx` chart cards to `grid-cols-1 sm:grid-cols-2` and aligned the 2×2 summary metric cards with `auto-rows-fr items-stretch`. - Added responsive wrapping and width caps in `CompanySettings.tsx`, `Secrets.tsx`, `SkillStudio.tsx`, `GrokBotSetupContent.tsx`, and `ActionTestDialog.tsx`. - **Storybook & Vitest coverage**: - Added 390×844 mobile Storybook views for Routines (`RoutinesListMobile`, `RoutineDetailMobile`), Members (`MembersMobile`), Costs (`CostsMobile`), ProjectDetail (`ProjectDetailMobile`), CompanySettings (`CompanySettingsMobile`), and Dashboard (`DashboardMobile`). - Added `ui/src/pages/mobile-collections-responsive.test.tsx`. ## Verification - `pnpm exec vitest run ui/src/pages/mobile-collections-responsive.test.tsx ui/src/pages/CompanyAccess.test.tsx ui/src/pages/Dashboard.test.ts` — 3 files, 35/35 passed - `pnpm --filter @paperclipai/ui typecheck` — passed (0 errors) - `pnpm check:token-gates` — all 4 gates CLEAN + cliplab character in sync - `node scripts/storybook-catalog.mjs --check` — passed (373 files, 3494 stories) - `node --test scripts/check-maps.test.mjs scripts/storybook-catalog.test.mjs scripts/storybook-feature-index.test.mjs` — 30/30 passed ## Risks - Low risk: layout-only responsive class updates, missing prop wiring on `PageTabBar` callers, and additive mobile Storybook stories/tests. Desktop breakpoints (`sm:` / `md:` / `lg:` / `xl:`) preserve existing layouts. - Several edited pages (`CompanySkills.tsx`, `Inbox.tsx`, `LegacyInbox.tsx`, `Secrets.tsx`, `SkillStudio.tsx`, `Costs.tsx`, `ProfilesTab.tsx`, `RoutineHistoryTab.tsx`, `ActionTestDialog.tsx`) were already over 1,000 lines on `master`; this PR keeps edits minimal and localized without introducing new subsystems into those files. ## Model Used - Google Gemini 4 Neon (High) via Antigravity (tool use, code execution, multi-agent code review) ## 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 --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
509 lines
22 KiB
TypeScript
509 lines
22 KiB
TypeScript
import { useEffect, useMemo, useState } from "react";
|
|
import { ChevronDown, ChevronRight, HelpCircle } from "lucide-react";
|
|
import { isValidRoutineDateString, syncRoutineVariablesWithTemplate, type RoutineVariable } from "@paperclipai/shared";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
|
|
const variableTypes: RoutineVariable["type"][] = ["text", "textarea", "number", "boolean", "select", "date"];
|
|
|
|
function serializeVariables(value: RoutineVariable[]) {
|
|
return JSON.stringify(value);
|
|
}
|
|
|
|
function parseSelectOptions(value: string) {
|
|
return value
|
|
.split(",")
|
|
.map((entry) => entry.trim())
|
|
.filter(Boolean);
|
|
}
|
|
|
|
function updateVariableList(
|
|
variables: RoutineVariable[],
|
|
name: string,
|
|
mutate: (variable: RoutineVariable) => RoutineVariable,
|
|
) {
|
|
return variables.map((variable) => (variable.name === name ? mutate(variable) : variable));
|
|
}
|
|
|
|
function defaultValueForType(type: RoutineVariable["type"], current: RoutineVariable["defaultValue"]) {
|
|
if (type === "boolean") return null;
|
|
if (type === "date") {
|
|
return typeof current === "string" && isValidRoutineDateString(current) ? current : null;
|
|
}
|
|
return current;
|
|
}
|
|
|
|
export function RoutineVariablesEditor({
|
|
title,
|
|
description,
|
|
value,
|
|
onChange,
|
|
variant = "default",
|
|
}: {
|
|
title: string;
|
|
description: string;
|
|
value: RoutineVariable[];
|
|
onChange: (value: RoutineVariable[]) => void;
|
|
/** `compact` puts each variable on one row under shared column labels. */
|
|
variant?: "default" | "compact";
|
|
}) {
|
|
const [open, setOpen] = useState(true);
|
|
const syncedVariables = useMemo(
|
|
() => syncRoutineVariablesWithTemplate([title, description], value),
|
|
[description, title, value],
|
|
);
|
|
const syncedSignature = serializeVariables(syncedVariables);
|
|
const currentSignature = serializeVariables(value);
|
|
|
|
useEffect(() => {
|
|
if (syncedSignature !== currentSignature) {
|
|
onChange(syncedVariables);
|
|
}
|
|
}, [currentSignature, onChange, syncedSignature, syncedVariables]);
|
|
|
|
if (syncedVariables.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
if (variant === "compact") {
|
|
return (
|
|
<CompactVariableRows
|
|
variables={syncedVariables}
|
|
onPatch={(name, mutate) => onChange(updateVariableList(syncedVariables, name, mutate))}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Collapsible open={open} onOpenChange={setOpen} className="overflow-hidden rounded-lg border border-border/70">
|
|
<CollapsibleTrigger className="flex w-full items-center justify-between px-3 py-2 text-left">
|
|
<div>
|
|
<p className="text-sm font-medium">Variables</p>
|
|
<p className="text-xs text-muted-foreground">
|
|
Detected from `{"{{name}}"}` placeholders in the title and instructions.
|
|
</p>
|
|
</div>
|
|
{open ? <ChevronDown className="h-4 w-4 text-muted-foreground" /> : <ChevronRight className="h-4 w-4 text-muted-foreground" />}
|
|
</CollapsibleTrigger>
|
|
<CollapsibleContent className="divide-y divide-border/70 border-t border-border/70">
|
|
{syncedVariables.map((variable) => (
|
|
<div key={variable.name} className="p-4">
|
|
<div className="mb-3 flex flex-wrap items-center gap-2">
|
|
<Badge variant="outline" className="font-mono text-xs">
|
|
{`{{${variable.name}}}`}
|
|
</Badge>
|
|
<span className="text-xs text-muted-foreground">
|
|
Prompt the user for this value before each manual run.
|
|
</span>
|
|
</div>
|
|
|
|
<div className="grid gap-3 md:grid-cols-2">
|
|
<div className="space-y-1.5">
|
|
<Label className="text-xs">Label</Label>
|
|
<Input
|
|
value={variable.label ?? ""}
|
|
onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
label: event.target.value || null,
|
|
})))}
|
|
placeholder={variable.name.replaceAll("_", " ")}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-1.5">
|
|
<Label className="text-xs">Type</Label>
|
|
<Select
|
|
value={variable.type}
|
|
onValueChange={(type) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
type: type as RoutineVariable["type"],
|
|
defaultValue: defaultValueForType(type as RoutineVariable["type"], current.defaultValue),
|
|
options: type === "select" ? current.options : [],
|
|
})))}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{variableTypes.map((type) => (
|
|
<SelectItem key={type} value={type}>{type}</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
|
|
<div className="space-y-1.5 md:col-span-2">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<Label className="text-xs">Default value</Label>
|
|
<label className="flex items-center gap-2 text-xs text-muted-foreground">
|
|
<input
|
|
type="checkbox"
|
|
checked={variable.required}
|
|
onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
required: event.target.checked,
|
|
})))}
|
|
/>
|
|
Required
|
|
</label>
|
|
</div>
|
|
|
|
{variable.type === "textarea" ? (
|
|
<Textarea
|
|
rows={3}
|
|
value={variable.defaultValue == null ? "" : String(variable.defaultValue)}
|
|
onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
defaultValue: event.target.value || null,
|
|
})))}
|
|
/>
|
|
) : variable.type === "boolean" ? (
|
|
<Select
|
|
value={variable.defaultValue === true ? "true" : variable.defaultValue === false ? "false" : "__unset__"}
|
|
onValueChange={(next) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
defaultValue: next === "__unset__" ? null : next === "true",
|
|
})))}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="__unset__">No default</SelectItem>
|
|
<SelectItem value="true">True</SelectItem>
|
|
<SelectItem value="false">False</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
) : variable.type === "select" ? (
|
|
<div className="grid gap-3 md:grid-cols-2">
|
|
<div className="space-y-1.5">
|
|
<Label className="text-xs">Options</Label>
|
|
<Input
|
|
value={variable.options.join(", ")}
|
|
onChange={(event) => {
|
|
const options = parseSelectOptions(event.target.value);
|
|
onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
options,
|
|
defaultValue:
|
|
typeof current.defaultValue === "string" && options.includes(current.defaultValue)
|
|
? current.defaultValue
|
|
: null,
|
|
})));
|
|
}}
|
|
placeholder="high, medium, low"
|
|
/>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<Label className="text-xs">Default option</Label>
|
|
<Select
|
|
value={typeof variable.defaultValue === "string" ? variable.defaultValue : "__unset__"}
|
|
onValueChange={(next) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
defaultValue: next === "__unset__" ? null : next,
|
|
})))}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue placeholder="No default" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="__unset__">No default</SelectItem>
|
|
{variable.options.map((option) => (
|
|
<SelectItem key={option} value={option}>{option}</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
) : variable.type === "date" ? (
|
|
<Input
|
|
type="date"
|
|
value={typeof variable.defaultValue === "string" ? variable.defaultValue : ""}
|
|
onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
defaultValue: event.target.value || null,
|
|
})))}
|
|
/>
|
|
) : (
|
|
<Input
|
|
type={variable.type === "number" ? "number" : "text"}
|
|
value={variable.defaultValue == null ? "" : String(variable.defaultValue)}
|
|
onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({
|
|
...current,
|
|
defaultValue: event.target.value || null,
|
|
})))}
|
|
placeholder={variable.type === "number" ? "42" : "Default value"}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</CollapsibleContent>
|
|
</Collapsible>
|
|
);
|
|
}
|
|
|
|
const compactColumns = {
|
|
name: "w-full shrink-0 sm:w-48",
|
|
type: "w-28 shrink-0",
|
|
defaultValue: "min-w-0 flex-1 basis-32",
|
|
required: "flex w-16 shrink-0 justify-center",
|
|
};
|
|
|
|
/** One row per variable: name, type, default and required, with the column labels shown once.
|
|
* A saved label is kept as-is; this layout does not edit it. */
|
|
function CompactVariableRows({
|
|
variables,
|
|
onPatch,
|
|
}: {
|
|
variables: RoutineVariable[];
|
|
onPatch: (name: string, mutate: (variable: RoutineVariable) => RoutineVariable) => void;
|
|
}) {
|
|
return (
|
|
<div className="flex flex-col gap-2" role="group" aria-label="Variables">
|
|
<Label>Variables</Label>
|
|
<div className="hidden items-center gap-2 text-xs text-muted-foreground sm:flex" aria-hidden="true">
|
|
<span className={compactColumns.name}>Name</span>
|
|
<span className={compactColumns.type}>Type</span>
|
|
<span className={compactColumns.defaultValue}>Default</span>
|
|
<span className={compactColumns.required}>Required</span>
|
|
</div>
|
|
{variables.map((variable) => {
|
|
const patch = (change: Partial<RoutineVariable>) => onPatch(variable.name, (current) => ({ ...current, ...change }));
|
|
return (
|
|
<div key={variable.name} className="flex flex-col gap-2">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<code className={`${compactColumns.name} truncate font-mono text-xs`} title={`{{${variable.name}}}`}>
|
|
{`{{${variable.name}}}`}
|
|
</code>
|
|
<Select
|
|
value={variable.type}
|
|
onValueChange={(type) => onPatch(variable.name, (current) => ({
|
|
...current,
|
|
type: type as RoutineVariable["type"],
|
|
defaultValue: defaultValueForType(type as RoutineVariable["type"], current.defaultValue),
|
|
options: type === "select" ? current.options : [],
|
|
}))}
|
|
>
|
|
<SelectTrigger className={compactColumns.type} aria-label={`Type of ${variable.name}`}>
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{variableTypes.map((type) => (
|
|
<SelectItem key={type} value={type}>{type}</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
<div className={compactColumns.defaultValue}>
|
|
{variable.type === "boolean" ? (
|
|
<Select
|
|
value={variable.defaultValue === true ? "true" : variable.defaultValue === false ? "false" : "__unset__"}
|
|
onValueChange={(next) => patch({ defaultValue: next === "__unset__" ? null : next === "true" })}
|
|
>
|
|
<SelectTrigger className="w-full" aria-label={`Default for ${variable.name}`}>
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="__unset__">No default</SelectItem>
|
|
<SelectItem value="true">True</SelectItem>
|
|
<SelectItem value="false">False</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
) : variable.type === "select" ? (
|
|
<Select
|
|
value={typeof variable.defaultValue === "string" ? variable.defaultValue : "__unset__"}
|
|
onValueChange={(next) => patch({ defaultValue: next === "__unset__" ? null : next })}
|
|
>
|
|
<SelectTrigger className="w-full" aria-label={`Default for ${variable.name}`}>
|
|
<SelectValue placeholder="No default" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="__unset__">No default</SelectItem>
|
|
{variable.options.map((option) => (
|
|
<SelectItem key={option} value={option}>{option}</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
) : variable.type === "textarea" ? (
|
|
<Textarea
|
|
rows={1}
|
|
aria-label={`Default for ${variable.name}`}
|
|
value={variable.defaultValue == null ? "" : String(variable.defaultValue)}
|
|
placeholder="No default"
|
|
onChange={(event) => patch({ defaultValue: event.target.value || null })}
|
|
/>
|
|
) : (
|
|
<Input
|
|
type={variable.type === "number" ? "number" : variable.type === "date" ? "date" : "text"}
|
|
aria-label={`Default for ${variable.name}`}
|
|
value={variable.defaultValue == null ? "" : String(variable.defaultValue)}
|
|
placeholder="No default"
|
|
onChange={(event) => patch({ defaultValue: event.target.value || null })}
|
|
/>
|
|
)}
|
|
</div>
|
|
<label className={`${compactColumns.required} items-center gap-2 text-xs text-muted-foreground`}>
|
|
<input
|
|
type="checkbox"
|
|
checked={variable.required}
|
|
aria-label={`${variable.name} is required`}
|
|
onChange={(event) => patch({ required: event.target.checked })}
|
|
/>
|
|
<span className="sm:hidden">Required</span>
|
|
</label>
|
|
</div>
|
|
{variable.type === "select" ? (
|
|
<div className="flex items-center gap-2">
|
|
<span className={`${compactColumns.name} hidden sm:block`} aria-hidden="true" />
|
|
<Input
|
|
className="min-w-0 flex-1"
|
|
aria-label={`Options for ${variable.name}`}
|
|
value={variable.options.join(", ")}
|
|
placeholder="Options, separated by commas: high, medium, low"
|
|
onChange={(event) => {
|
|
const options = parseSelectOptions(event.target.value);
|
|
onPatch(variable.name, (current) => ({
|
|
...current,
|
|
options,
|
|
defaultValue:
|
|
typeof current.defaultValue === "string" && options.includes(current.defaultValue)
|
|
? current.defaultValue
|
|
: null,
|
|
}));
|
|
}}
|
|
/>
|
|
<span className={`${compactColumns.required} hidden sm:block`} aria-hidden="true" />
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
type BuiltinVariableDoc = {
|
|
name: string;
|
|
example: string;
|
|
description: string;
|
|
};
|
|
|
|
const BUILTIN_VARIABLE_DOCS: BuiltinVariableDoc[] = [
|
|
{
|
|
name: "date",
|
|
example: "2026-04-28",
|
|
description: "Current date in YYYY-MM-DD format (UTC) at the time the routine runs.",
|
|
},
|
|
{
|
|
name: "timestamp",
|
|
example: "April 28, 2026 at 12:17 PM UTC",
|
|
description: "Human-readable date and time (UTC) at the time the routine runs.",
|
|
},
|
|
];
|
|
|
|
export function RoutineVariablesHint() {
|
|
const [helpOpen, setHelpOpen] = useState(false);
|
|
|
|
return (
|
|
<>
|
|
<div className="flex items-center justify-between gap-2 rounded-lg border border-dashed border-border/70 px-3 py-2 text-xs text-muted-foreground">
|
|
<span>
|
|
Use `{"{{variable_name}}"}` placeholders in the title or instructions to prompt for inputs when the routine runs.
|
|
</span>
|
|
<button
|
|
type="button"
|
|
onClick={() => setHelpOpen(true)}
|
|
className="shrink-0 rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
aria-label="Show variable help"
|
|
>
|
|
<HelpCircle className="h-3.5 w-3.5" />
|
|
</button>
|
|
</div>
|
|
|
|
<Dialog open={helpOpen} onOpenChange={setHelpOpen}>
|
|
<DialogContent className="sm:max-w-xl">
|
|
<DialogHeader>
|
|
<DialogTitle>Routine variables</DialogTitle>
|
|
<DialogDescription>
|
|
How to prompt for inputs and which variables Paperclip fills in automatically.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<div className="space-y-5 text-sm">
|
|
<section className="space-y-2">
|
|
<h3 className="text-xs font-semibold uppercase tracking-(--tracking-caps) text-muted-foreground">
|
|
Custom variables
|
|
</h3>
|
|
<p className="text-muted-foreground">
|
|
Type{" "}
|
|
<code className="rounded bg-muted px-1 py-0.5 font-mono text-xs text-foreground">
|
|
{"{{variable_name}}"}
|
|
</code>{" "}
|
|
anywhere in the title or instructions. Paperclip detects each placeholder, lists it
|
|
under <span className="font-medium text-foreground">Variables</span>, and prompts
|
|
for a value before each run.
|
|
</p>
|
|
<ul className="list-disc space-y-1 pl-5 text-muted-foreground">
|
|
<li>Names must start with a letter and may use letters, numbers, and underscores.</li>
|
|
<li>Pick a type (text, textarea, number, boolean, select, date), default value, and whether it is required.</li>
|
|
<li>Variable names ending in capital Date, such as startDate, are created as date variables by default.</li>
|
|
<li>The same name reused across the title and instructions is treated as one variable.</li>
|
|
</ul>
|
|
</section>
|
|
|
|
<section className="space-y-2">
|
|
<h3 className="text-xs font-semibold uppercase tracking-(--tracking-caps) text-muted-foreground">
|
|
Built-in variables
|
|
</h3>
|
|
<p className="text-muted-foreground">
|
|
These are filled in automatically — no setup needed and they will not appear in the
|
|
Variables list.
|
|
</p>
|
|
<div className="max-w-full overflow-x-auto rounded-lg border border-border/70">
|
|
<table className="w-full text-left text-xs">
|
|
<thead className="bg-muted/40 text-muted-foreground">
|
|
<tr>
|
|
<th className="px-3 py-2 font-medium">Placeholder</th>
|
|
<th className="px-3 py-2 font-medium">Example</th>
|
|
<th className="px-3 py-2 font-medium">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-border/70">
|
|
{BUILTIN_VARIABLE_DOCS.map((entry) => (
|
|
<tr key={entry.name} className="align-top">
|
|
<td className="px-3 py-2">
|
|
<Badge variant="outline" className="font-mono text-xs">{`{{${entry.name}}}`}</Badge>
|
|
</td>
|
|
<td className="px-3 py-2 font-mono text-muted-foreground">{entry.example}</td>
|
|
<td className="px-3 py-2 text-muted-foreground">{entry.description}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</>
|
|
);
|
|
}
|