forked from farhoodlabs/paperclip
176d279403
Add ApprovalDetail page with comment thread, revision request/resubmit flow, and ApprovalPayload component for structured payload display. Extend AgentDetail with permissions management, config revision history, and duplicate action. Add agent hire dialog with permission-gated access. Rework Costs page with per-agent breakdown table and period filtering. Add sidebar badge counts for pending approvals and inbox items. Enhance Dashboard with live metrics and sparkline trends. Extend Agents list with pending_approval status and bulk actions. Update IssueDetail with approval linking. Various component improvements to MetricCard, InlineEditor, CommentThread, and StatusBadge. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
132 lines
3.1 KiB
TypeScript
132 lines
3.1 KiB
TypeScript
import { useState, useRef, useEffect, useCallback } from "react";
|
|
import Markdown from "react-markdown";
|
|
import { cn } from "../lib/utils";
|
|
|
|
interface InlineEditorProps {
|
|
value: string;
|
|
onSave: (value: string) => void;
|
|
as?: "h1" | "h2" | "p" | "span";
|
|
className?: string;
|
|
placeholder?: string;
|
|
multiline?: boolean;
|
|
}
|
|
|
|
/** Shared padding so display and edit modes occupy the exact same box. */
|
|
const pad = "px-1 -mx-1";
|
|
|
|
export function InlineEditor({
|
|
value,
|
|
onSave,
|
|
as: Tag = "span",
|
|
className,
|
|
placeholder = "Click to edit...",
|
|
multiline = false,
|
|
}: InlineEditorProps) {
|
|
const [editing, setEditing] = useState(false);
|
|
const [draft, setDraft] = useState(value);
|
|
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null);
|
|
|
|
useEffect(() => {
|
|
setDraft(value);
|
|
}, [value]);
|
|
|
|
const autoSize = useCallback((el: HTMLTextAreaElement | null) => {
|
|
if (!el) return;
|
|
el.style.height = "auto";
|
|
el.style.height = `${el.scrollHeight}px`;
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (editing && inputRef.current) {
|
|
inputRef.current.focus();
|
|
inputRef.current.select();
|
|
if (multiline && inputRef.current instanceof HTMLTextAreaElement) {
|
|
autoSize(inputRef.current);
|
|
}
|
|
}
|
|
}, [editing, multiline, autoSize]);
|
|
|
|
function commit() {
|
|
const trimmed = draft.trim();
|
|
if (trimmed && trimmed !== value) {
|
|
onSave(trimmed);
|
|
} else {
|
|
setDraft(value);
|
|
}
|
|
setEditing(false);
|
|
}
|
|
|
|
function handleKeyDown(e: React.KeyboardEvent) {
|
|
if (e.key === "Enter" && !multiline) {
|
|
e.preventDefault();
|
|
commit();
|
|
}
|
|
if (e.key === "Escape") {
|
|
setDraft(value);
|
|
setEditing(false);
|
|
}
|
|
}
|
|
|
|
if (editing) {
|
|
const sharedProps = {
|
|
ref: inputRef as any,
|
|
value: draft,
|
|
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
setDraft(e.target.value);
|
|
if (multiline && e.target instanceof HTMLTextAreaElement) {
|
|
autoSize(e.target);
|
|
}
|
|
},
|
|
onBlur: commit,
|
|
onKeyDown: handleKeyDown,
|
|
};
|
|
|
|
if (multiline) {
|
|
return (
|
|
<textarea
|
|
{...sharedProps}
|
|
rows={1}
|
|
className={cn(
|
|
"w-full resize-none bg-accent/30 rounded outline-none",
|
|
pad,
|
|
"py-0.5",
|
|
className
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<input
|
|
type="text"
|
|
{...sharedProps}
|
|
className={cn(
|
|
"w-full bg-transparent rounded outline-none",
|
|
pad,
|
|
className
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Tag
|
|
className={cn(
|
|
"cursor-pointer rounded hover:bg-accent/50 transition-colors",
|
|
pad,
|
|
!value && "text-muted-foreground italic",
|
|
className
|
|
)}
|
|
onClick={() => setEditing(true)}
|
|
>
|
|
{value && multiline ? (
|
|
<div className="prose prose-sm prose-invert max-w-none prose-p:my-1 prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-pre:my-2 prose-headings:my-2 prose-headings:text-sm">
|
|
<Markdown>{value}</Markdown>
|
|
</div>
|
|
) : (
|
|
value || placeholder
|
|
)}
|
|
</Tag>
|
|
);
|
|
}
|