QueryPanel.tsx 3.1 KB

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