QueryPanel.tsx93 lines · main
1import { InformationCircleIcon } from '@heroicons/react/16/solid'
2import { ArrowDown, ArrowUp } from 'lucide-react'
3import { PropsWithChildren } from 'react'
4import { cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
5
6export const QueryPanelContainer = ({
7 children,
8 className,
9}: PropsWithChildren<{ className?: string }>) => (
10 <div className={cn('flex flex-col gap-y-0 py-4', className)}>{children}</div>
11)
12
13export const QueryPanelSection = ({
14 children,
15 className,
16}: PropsWithChildren<{ className?: string }>) => (
17 <div className={cn('px-6 flex flex-col gap-y-0', className)}>{children}</div>
18)
19
20export const QueryPanelScoreSection = ({
21 className,
22 name,
23 description,
24 before: rawBefore,
25 after: rawAfter,
26 hideArrowMarkers = false,
27}: {
28 className?: string
29 name: string
30 description: string
31 before?: number
32 after?: number
33 hideArrowMarkers?: boolean
34}) => {
35 const before = rawBefore !== undefined ? Number(rawBefore) : undefined
36 const after = rawAfter !== undefined ? Number(rawAfter) : undefined
37
38 return (
39 <div className={cn('py-4 px-4 flex', className)}>
40 <div className="flex gap-x-2 w-48">
41 <span className="text-sm">{name}</span>
42 <Tooltip>
43 <TooltipTrigger asChild className="mt-1">
44 <InformationCircleIcon className="transition text-foreground-muted w-3 h-3 data-[state=delayed-open]:text-foreground-light" />
45 </TooltipTrigger>
46 <TooltipContent side="top" className="w-52 text-center">
47 {description}
48 </TooltipContent>
49 </Tooltip>
50 </div>
51 <div className="flex flex-col gap-y-1">
52 <div className="flex gap-x-2 text-sm">
53 <span className="text-foreground-light w-20">Currently:</span>
54 <span
55 className={cn(
56 'font-mono',
57 before !== undefined && after !== undefined && before !== after
58 ? 'text-foreground-light'
59 : ''
60 )}
61 >
62 {before}
63 </span>
64 </div>
65 {before !== undefined && after !== undefined && before !== after && (
66 <div className="flex items-center gap-x-2 text-sm">
67 <span className="text-foreground-light w-20">With index:</span>
68 <span className="font-mono">{after}</span>
69 {before !== undefined && !hideArrowMarkers && (
70 <div className="flex items-center gap-x-1">
71 {after > before ? (
72 <ArrowUp size={14} className="text-warning" />
73 ) : (
74 <ArrowDown size={14} className="text-brand" />
75 )}
76 {before !== 0 && !isNaN(before) && isFinite(before) && (
77 <span
78 className={cn(
79 'font-mono tracking-tighter',
80 after > before ? 'text-warning' : 'text-brand'
81 )}
82 >
83 {(((before - after) / before) * 100).toFixed(2)}%
84 </span>
85 )}
86 </div>
87 )}
88 </div>
89 )}
90 </div>
91 </div>
92 )
93}