mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip helps people manage AI agents and their work. > - Operators search the Plugins catalog for tools their agents need. > - An empty search offers only a way to clear the query. > - Operators can now use the search term to request the missing tool. > - Each submission creates a backlog task that the company can track. ## Linked Issues or Issue Description **Subsystem affected** Plugins catalog search. **Problem or motivation** An operator who cannot find a tool must leave the catalog to write a request. **Proposed solution** Add a primary request button beside Clear search. Open a form with the search term as its editable name. ## What Changed - Collect an optional website and notification email. Save the request as a company backlog task and show its identifier. - Capture `plugin_request_submitted` after a successful save. Include the source and flags for website presence and email opt-in. - Add a test that submits the form and checks the saved fields, confirmation, and event count. ## Verification - Run `node_modules/.bin/vitest run ui/src/pages/apps/RequestPluginDialog.test.tsx ui/src/lib/analytics/product-analytics-events.test.ts`. All three tests passed locally. The query error policy check reported zero findings. - A manual worktree submission produced one PostHog event with both flags true. - [Final CI run](https://github.com/paperclipai/paperclip/actions/runs/47424073788) passed the required verification and end-to-end gates on `e749348c05`. ## Risks The optional email becomes visible to people who can read the company task. The form records the notification preference. Email delivery requires a future integration. ## Model Used OpenAI GPT-6 via Codex, with local code execution and browser verification. ## 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 - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] 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>
120 lines
5.6 KiB
TypeScript
120 lines
5.6 KiB
TypeScript
import { useState } from "react";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Checkbox } from "@/components/ui/checkbox";
|
||
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||
import { Input } from "@/components/ui/input";
|
||
import { Label } from "@/components/ui/label";
|
||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||
import { createUuid } from "@/lib/uuid";
|
||
import { describeError } from "@/api/errors";
|
||
import { issuesApi } from "@/api/issues";
|
||
import { useCompany } from "@/context/CompanyContext";
|
||
import { queryKeys } from "@/lib/queryKeys";
|
||
import { ANALYTICS_MASK_CLASS } from "@/lib/analytics/privacy";
|
||
import { captureProductAnalyticsEvent } from "@/lib/analytics/product-analytics";
|
||
|
||
interface PluginRequestSubmission {
|
||
idempotencyKey: string;
|
||
companyId: string;
|
||
title: string;
|
||
description: string;
|
||
hasWebsite: boolean;
|
||
notificationOptIn: boolean;
|
||
}
|
||
|
||
export function RequestPluginDialog({ searchedName }: { searchedName: string }) {
|
||
const { selectedCompanyId } = useCompany();
|
||
const queryClient = useQueryClient();
|
||
const submission = useMutation({
|
||
mutationFn: ({ companyId, title, description, idempotencyKey }: PluginRequestSubmission) =>
|
||
issuesApi.create(companyId, { title, description, status: "backlog", allowDuplicate: true, idempotencyKey }),
|
||
onSuccess: (_, { companyId, hasWebsite, notificationOptIn }) => {
|
||
captureProductAnalyticsEvent("plugin_request_submitted", {
|
||
source: "plugins_empty_search",
|
||
has_website: String(hasWebsite),
|
||
notification_opt_in: String(notificationOptIn),
|
||
});
|
||
void queryClient.invalidateQueries({ queryKey: queryKeys.issues.list(companyId) });
|
||
},
|
||
});
|
||
const [open, setOpen] = useState(false);
|
||
const [notify, setNotify] = useState(false);
|
||
|
||
return (
|
||
<Dialog open={open} onOpenChange={(next) => {
|
||
if (submission.isPending) return;
|
||
if (next) {
|
||
submission.reset();
|
||
setNotify(false);
|
||
}
|
||
setOpen(next);
|
||
}}>
|
||
<DialogTrigger asChild><Button size="sm">Request plugin/tool</Button></DialogTrigger>
|
||
<DialogContent className={ANALYTICS_MASK_CLASS} showCloseButton={!submission.isPending}>
|
||
{submission.isSuccess ? <>
|
||
<DialogHeader>
|
||
<DialogTitle>Request submitted</DialogTitle>
|
||
<DialogDescription>Your request was saved as company task {submission.data.identifier}.</DialogDescription>
|
||
</DialogHeader>
|
||
<DialogFooter><DialogClose asChild><Button>Done</Button></DialogClose></DialogFooter>
|
||
</> : <>
|
||
<DialogHeader>
|
||
<DialogTitle>Request a plugin or tool</DialogTitle>
|
||
<DialogDescription>Your request will be saved as a company task.</DialogDescription>
|
||
</DialogHeader>
|
||
<form className="grid gap-5" onSubmit={(event) => {
|
||
event.preventDefault();
|
||
if (!selectedCompanyId || submission.isPending) return;
|
||
const data = new FormData(event.currentTarget);
|
||
const name = String(data.get("name") ?? "").trim();
|
||
const url = String(data.get("url") ?? "").trim();
|
||
const description = [
|
||
url && `Website: ${url}`,
|
||
notify && `Email me when available: ${data.get("email")}`,
|
||
].filter(Boolean).join("\n\n");
|
||
const title = name ? `Request plugin/tool: ${name}` : "Request plugin/tool";
|
||
const previous = submission.variables;
|
||
const idempotencyKey = previous?.companyId === selectedCompanyId
|
||
&& previous.title === title && previous.description === description
|
||
? previous.idempotencyKey : createUuid();
|
||
submission.mutate({
|
||
idempotencyKey,
|
||
companyId: selectedCompanyId,
|
||
title,
|
||
description,
|
||
hasWebsite: Boolean(url),
|
||
notificationOptIn: notify,
|
||
});
|
||
}}>
|
||
<div className="grid gap-2">
|
||
<Label htmlFor="requested-plugin-name">Plugin or tool name</Label>
|
||
<Input id="requested-plugin-name" name="name" defaultValue={searchedName.trim()} />
|
||
</div>
|
||
<div className="grid gap-2">
|
||
<Label htmlFor="requested-plugin-url">Website (optional)</Label>
|
||
<Input id="requested-plugin-url" name="url" type="url" placeholder="https://example.com" />
|
||
</div>
|
||
<div className="flex items-center gap-2">
|
||
<Checkbox id="requested-plugin-notify" checked={notify} onCheckedChange={(checked) => setNotify(checked === true)} />
|
||
<Label htmlFor="requested-plugin-notify">Email me when this integration is available</Label>
|
||
</div>
|
||
{notify && <div className="grid gap-2">
|
||
<Label htmlFor="requested-plugin-email">Notification email</Label>
|
||
<Input id="requested-plugin-email" name="email" type="email" autoComplete="email" required />
|
||
</div>}
|
||
{submission.error && <p role="alert" className="text-sm text-destructive">
|
||
Couldn’t submit your request. {describeError(submission.error).body}
|
||
</p>}
|
||
<DialogFooter className="flex-row items-center justify-between sm:justify-between">
|
||
<DialogClose asChild><Button type="button" variant="ghost" disabled={submission.isPending}>Cancel</Button></DialogClose>
|
||
<Button type="submit" disabled={!selectedCompanyId || submission.isPending}>
|
||
{submission.isPending ? "Submitting…" : "Submit request"}
|
||
</Button>
|
||
</DialogFooter>
|
||
</form>
|
||
</>}
|
||
</DialogContent>
|
||
</Dialog>
|
||
);
|
||
}
|