|
| 1 | +import { Button } from "@superset/ui/button"; |
| 2 | +import { Label } from "@superset/ui/label"; |
| 3 | +import { Popover, PopoverContent, PopoverTrigger } from "@superset/ui/popover"; |
| 4 | +import { |
| 5 | + Select, |
| 6 | + SelectContent, |
| 7 | + SelectItem, |
| 8 | + SelectTrigger, |
| 9 | + SelectValue, |
| 10 | +} from "@superset/ui/select"; |
| 11 | +import { Separator } from "@superset/ui/separator"; |
| 12 | +import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; |
| 13 | +import { useState } from "react"; |
| 14 | +import { |
| 15 | + LuBuilding2, |
| 16 | + LuCheck, |
| 17 | + LuLink2, |
| 18 | + LuLock, |
| 19 | + LuShare2, |
| 20 | +} from "react-icons/lu"; |
| 21 | +import { useCopyToClipboard } from "renderer/hooks/useCopyToClipboard"; |
| 22 | +import { cloudTrpc } from "renderer/lib/cloud-trpc"; |
| 23 | + |
| 24 | +interface ReviewSharePopoverProps { |
| 25 | + prUrl: string; |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Surfaces the AI code review already published for this PR (via |
| 30 | + * `reviews_publish` — an external, agent-driven action, not something this |
| 31 | + * view can trigger itself: it has no findings to publish). Reviews reuse the |
| 32 | + * generic Pages table, so visibility is changed through `page.setVisibility` |
| 33 | + * the same way the Pages share popover does. |
| 34 | + */ |
| 35 | +export function ReviewSharePopover({ prUrl }: ReviewSharePopoverProps) { |
| 36 | + const [open, setOpen] = useState(false); |
| 37 | + const { copyToClipboard, copied } = useCopyToClipboard(); |
| 38 | + |
| 39 | + const review = cloudTrpc.review.getForPullRequest.useQuery( |
| 40 | + { prUrl }, |
| 41 | + { enabled: Boolean(prUrl) }, |
| 42 | + ); |
| 43 | + const setVisibility = cloudTrpc.page.setVisibility.useMutation({ |
| 44 | + onSuccess: () => void review.refetch(), |
| 45 | + }); |
| 46 | + |
| 47 | + const page = review.data; |
| 48 | + const iconButton = ( |
| 49 | + <Button |
| 50 | + variant="ghost" |
| 51 | + size="icon-sm" |
| 52 | + disabled={!page} |
| 53 | + aria-label={page ? "Share AI review" : "No AI review shared yet"} |
| 54 | + > |
| 55 | + <LuShare2 className="size-4" /> |
| 56 | + </Button> |
| 57 | + ); |
| 58 | + |
| 59 | + if (!page) { |
| 60 | + return ( |
| 61 | + <Tooltip delayDuration={300}> |
| 62 | + <TooltipTrigger asChild> |
| 63 | + {/* A disabled button still lets a wrapping span pick up the |
| 64 | + hover that opens the tooltip. */} |
| 65 | + <span>{iconButton}</span> |
| 66 | + </TooltipTrigger> |
| 67 | + <TooltipContent side="bottom"> |
| 68 | + {review.isLoading |
| 69 | + ? "Checking for a shared review…" |
| 70 | + : "No AI review has been shared for this PR yet"} |
| 71 | + </TooltipContent> |
| 72 | + </Tooltip> |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + return ( |
| 77 | + <Popover open={open} onOpenChange={setOpen}> |
| 78 | + <PopoverTrigger asChild>{iconButton}</PopoverTrigger> |
| 79 | + <PopoverContent align="end" className="w-80 p-0"> |
| 80 | + <div className="flex items-center justify-between gap-2 px-3 py-2.5"> |
| 81 | + <span className="min-w-0 truncate font-medium text-sm"> |
| 82 | + {page.title} |
| 83 | + </span> |
| 84 | + <Button |
| 85 | + size="xs" |
| 86 | + variant="ghost" |
| 87 | + onClick={() => void copyToClipboard(page.url)} |
| 88 | + > |
| 89 | + {copied ? ( |
| 90 | + <LuCheck className="size-3.5 text-primary" /> |
| 91 | + ) : ( |
| 92 | + <LuLink2 className="size-3.5" /> |
| 93 | + )} |
| 94 | + {copied ? "Copied" : "Copy link"} |
| 95 | + </Button> |
| 96 | + </div> |
| 97 | + <Separator /> |
| 98 | + <div className="space-y-2 px-3 py-2.5"> |
| 99 | + <div className="space-y-0.5"> |
| 100 | + <Label className="font-medium text-sm">General access</Label> |
| 101 | + <p className="text-muted-foreground text-xs"> |
| 102 | + Who can open this review from its link |
| 103 | + </p> |
| 104 | + </div> |
| 105 | + <Select |
| 106 | + value={page.visibility} |
| 107 | + disabled={setVisibility.isPending} |
| 108 | + onValueChange={(value) => |
| 109 | + setVisibility.mutate({ |
| 110 | + id: page.id, |
| 111 | + visibility: value as "just_me" | "org", |
| 112 | + }) |
| 113 | + } |
| 114 | + > |
| 115 | + <SelectTrigger size="sm" className="w-full"> |
| 116 | + <SelectValue /> |
| 117 | + </SelectTrigger> |
| 118 | + <SelectContent> |
| 119 | + <SelectItem value="just_me"> |
| 120 | + <LuLock className="size-3.5 text-muted-foreground" /> |
| 121 | + Only you |
| 122 | + </SelectItem> |
| 123 | + <SelectItem value="org"> |
| 124 | + <LuBuilding2 className="size-3.5 text-muted-foreground" /> |
| 125 | + Anyone in your organization |
| 126 | + </SelectItem> |
| 127 | + </SelectContent> |
| 128 | + </Select> |
| 129 | + </div> |
| 130 | + </PopoverContent> |
| 131 | + </Popover> |
| 132 | + ); |
| 133 | +} |
0 commit comments