mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 09:16:22 +02:00
refactor: streamline ApprovalCard component across various tools
This commit is contained in:
parent
bd2d633546
commit
4bd2071a8d
14 changed files with 225 additions and 267 deletions
|
|
@ -146,6 +146,7 @@ function ApprovalCard({
|
|||
const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>(
|
||||
interruptData.__decided__ ?? null
|
||||
);
|
||||
const wasAlreadyDecided = interruptData.__decided__ != null;
|
||||
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
||||
const openHitlEditPanel = useSetAtom(openHitlEditPanelAtom);
|
||||
|
||||
|
|
@ -213,8 +214,6 @@ function ApprovalCard({
|
|||
return () => window.removeEventListener("keydown", handler);
|
||||
}, [handleApprove]);
|
||||
|
||||
if (decided && decided !== "reject") return null;
|
||||
|
||||
return (
|
||||
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||
{/* Header */}
|
||||
|
|
@ -227,15 +226,21 @@ function ApprovalCard({
|
|||
? "Linear Issue Approved"
|
||||
: "Create Linear Issue"}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "reject"
|
||||
? "Issue creation was cancelled"
|
||||
: decided === "edit"
|
||||
? "Issue creation is in progress with your changes"
|
||||
: decided === "approve"
|
||||
? "Issue creation is in progress"
|
||||
: "Requires your approval to proceed"}
|
||||
</p>
|
||||
{decided === "approve" || decided === "edit" ? (
|
||||
wasAlreadyDecided ? (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "edit" ? "Issue created with your changes" : "Issue created"}
|
||||
</p>
|
||||
) : (
|
||||
<TextShimmerLoader text={decided === "edit" ? "Creating issue with your changes" : "Creating issue"} size="sm" />
|
||||
)
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "reject"
|
||||
? "Issue creation was cancelled"
|
||||
: "Requires your approval to proceed"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{!decided && canEdit && (
|
||||
<Button
|
||||
|
|
@ -580,15 +585,7 @@ export const CreateLinearIssueToolUI = makeAssistantToolUI<
|
|||
CreateLinearIssueResult
|
||||
>({
|
||||
toolName: "create_linear_issue",
|
||||
render: function CreateLinearIssueUI({ args, result, status }) {
|
||||
if (status.type === "running") {
|
||||
return (
|
||||
<div className="my-4 max-w-lg rounded-2xl border bg-muted/30 px-5 py-4 select-none">
|
||||
<TextShimmerLoader text="Preparing Linear issue..." size="sm" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render: function CreateLinearIssueUI({ args, result, status: _status }) {
|
||||
if (!result) return null;
|
||||
|
||||
if (isInterruptResult(result)) {
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ function ApprovalCard({
|
|||
const [decided, setDecided] = useState<"approve" | "reject" | null>(
|
||||
interruptData.__decided__ ?? null
|
||||
);
|
||||
const wasAlreadyDecided = interruptData.__decided__ != null;
|
||||
const [deleteFromKb, setDeleteFromKb] = useState(
|
||||
typeof actionArgs.delete_from_kb === "boolean" ? actionArgs.delete_from_kb : false
|
||||
);
|
||||
|
|
@ -165,8 +166,6 @@ function ApprovalCard({
|
|||
return () => window.removeEventListener("keydown", handler);
|
||||
}, [handleApprove]);
|
||||
|
||||
if (decided && decided !== "reject") return null;
|
||||
|
||||
return (
|
||||
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||
{/* Header */}
|
||||
|
|
@ -179,13 +178,19 @@ function ApprovalCard({
|
|||
? "Linear Issue Deletion Approved"
|
||||
: "Delete Linear Issue"}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "reject"
|
||||
? "Issue deletion was cancelled"
|
||||
: decided === "approve"
|
||||
? "Issue deletion is in progress"
|
||||
{decided === "approve" ? (
|
||||
wasAlreadyDecided ? (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">Issue deleted</p>
|
||||
) : (
|
||||
<TextShimmerLoader text="Deleting issue" size="sm" />
|
||||
)
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "reject"
|
||||
? "Issue deletion was cancelled"
|
||||
: "Requires your approval to proceed"}
|
||||
</p>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -367,15 +372,7 @@ export const DeleteLinearIssueToolUI = makeAssistantToolUI<
|
|||
DeleteLinearIssueResult
|
||||
>({
|
||||
toolName: "delete_linear_issue",
|
||||
render: function DeleteLinearIssueUI({ result, status }) {
|
||||
if (status.type === "running") {
|
||||
return (
|
||||
<div className="my-4 max-w-lg rounded-2xl border bg-muted/30 px-5 py-4 select-none">
|
||||
<TextShimmerLoader text="Preparing Linear issue deletion..." size="sm" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render: function DeleteLinearIssueUI({ result, status: _status }) {
|
||||
if (!result) return null;
|
||||
|
||||
if (isInterruptResult(result)) {
|
||||
|
|
|
|||
|
|
@ -186,6 +186,7 @@ function ApprovalCard({
|
|||
const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>(
|
||||
interruptData.__decided__ ?? null
|
||||
);
|
||||
const wasAlreadyDecided = interruptData.__decided__ != null;
|
||||
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
||||
const [editedArgs, setEditedArgs] = useState(initialEditState);
|
||||
const openHitlEditPanel = useSetAtom(openHitlEditPanelAtom);
|
||||
|
|
@ -274,8 +275,6 @@ function ApprovalCard({
|
|||
return () => window.removeEventListener("keydown", handler);
|
||||
}, [handleApprove]);
|
||||
|
||||
if (decided && decided !== "reject") return null;
|
||||
|
||||
return (
|
||||
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||
{/* Header */}
|
||||
|
|
@ -288,15 +287,21 @@ function ApprovalCard({
|
|||
? "Linear Issue Update Approved"
|
||||
: "Update Linear Issue"}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "reject"
|
||||
? "Issue update was cancelled"
|
||||
: decided === "edit"
|
||||
? "Issue update is in progress with your changes"
|
||||
: decided === "approve"
|
||||
? "Issue update is in progress"
|
||||
: "Requires your approval to proceed"}
|
||||
</p>
|
||||
{decided === "approve" || decided === "edit" ? (
|
||||
wasAlreadyDecided ? (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "edit" ? "Issue updated with your changes" : "Issue updated"}
|
||||
</p>
|
||||
) : (
|
||||
<TextShimmerLoader text={decided === "edit" ? "Updating issue with your changes" : "Updating issue"} size="sm" />
|
||||
)
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{decided === "reject"
|
||||
? "Issue update was cancelled"
|
||||
: "Requires your approval to proceed"}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{!decided && canEdit && (
|
||||
<Button
|
||||
|
|
@ -718,15 +723,7 @@ export const UpdateLinearIssueToolUI = makeAssistantToolUI<
|
|||
UpdateLinearIssueResult
|
||||
>({
|
||||
toolName: "update_linear_issue",
|
||||
render: function UpdateLinearIssueUI({ result, status }) {
|
||||
if (status.type === "running") {
|
||||
return (
|
||||
<div className="my-4 max-w-lg rounded-2xl border bg-muted/30 px-5 py-4 select-none">
|
||||
<TextShimmerLoader text="Preparing Linear issue update..." size="sm" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render: function UpdateLinearIssueUI({ result, status: _status }) {
|
||||
if (!result) return null;
|
||||
|
||||
if (isInterruptResult(result)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue