View remote rules and workflows in the editor (#7702)

* allow the user to view remote rules and workflows in the editor by creating a temp file

* add await
This commit is contained in:
celestial-vault
2025-11-27 11:37:47 -06:00
committed by GitHub
parent 06585821d1
commit 2a20523e16
5 changed files with 65 additions and 15 deletions
@@ -1,10 +1,10 @@
import { StringRequest } from "@shared/proto/cline/common"
import { RuleFileRequest } from "@shared/proto/index.cline"
import { InfoIcon, PenIcon, Trash2Icon } from "lucide-react"
import { REMOTE_URI_SCHEME } from "@shared/remote-config/constants"
import { EyeIcon, InfoIcon, PenIcon, Trash2Icon } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Switch } from "@/components/ui/switch"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { cn } from "@/lib/utils"
import { FileServiceClient } from "@/services/grpc-client"
const RuleRow: React.FC<{
@@ -81,7 +81,9 @@ const RuleRow: React.FC<{
}
const handleEditClick = () => {
FileServiceClient.openFile(StringRequest.create({ value: rulePath })).catch((err) =>
// For remote rules, use the special remote:// URI format
const filePath = isRemote ? `${REMOTE_URI_SCHEME}${ruleType === "workflow" ? "workflow" : "rule"}/${rulePath}` : rulePath
FileServiceClient.openFile(StringRequest.create({ value: filePath })).catch((err) =>
console.error("Failed to open file:", err),
)
}
@@ -98,10 +100,7 @@ const RuleRow: React.FC<{
return (
<div className="mb-2.5">
<div
className={cn("flex items-center px-2 py-4 rounded bg-text-block-background max-h-4", {
"opacity-60": isDisabled,
})}>
<div className="flex items-center px-2 py-4 rounded bg-text-block-background max-h-4">
<span className="flex-1 overflow-hidden break-all whitespace-normal flex items-center mr-1" title={rulePath}>
{getRuleTypeIcon() && <span className="mr-1.5">{getRuleTypeIcon()}</span>}
<span className="ph-no-capture">{finalDisplayName}</span>
@@ -128,13 +127,12 @@ const RuleRow: React.FC<{
title={isDisabled ? "This rule is required and cannot be disabled" : undefined}
/>
<Button
aria-label="Edit rule file"
disabled={isRemote}
aria-label={isRemote ? "View rule file" : "Edit rule file"}
onClick={handleEditClick}
size="xs"
title="Edit rule file"
title={isRemote ? "View rule file (read-only)" : "Edit rule file"}
variant="icon">
<PenIcon />
{isRemote ? <EyeIcon /> : <PenIcon />}
</Button>
<Button
aria-label="Delete rule file"
+1 -1
View File
@@ -4,7 +4,7 @@ import * as React from "react"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer [&_svg]:size-2",
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 cursor-pointer [&_svg]:size-2",
{
variants: {
variant: {