ReportSectionHeader.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Check, Link } from 'lucide-react'
  2. import { useState } from 'react'
  3. import { copyToClipboard } from 'ui'
  4. import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
  5. interface ReportSectionHeaderProps {
  6. id: string
  7. title: string
  8. description: string
  9. }
  10. export const ReportSectionHeader = ({ id, title, description }: ReportSectionHeaderProps) => {
  11. const [copiedLink, setCopiedLink] = useState<string | null>(null)
  12. const copyLinkToClipboard = async () => {
  13. // [jordi] We want to keep the existing query params (filters)
  14. // But if the user has an anchor in the URL,
  15. // we remove it and add the one for this section
  16. // This is so the shared URL shows the exact same report as the one the user is on
  17. const url = `${window.location.href.split('#')[0]}#${id}`
  18. await copyToClipboard(url)
  19. setCopiedLink(id)
  20. setTimeout(() => setCopiedLink(null), 2000)
  21. }
  22. return (
  23. <div className="flex flex-col gap-1 mb-4 group">
  24. <div
  25. className="flex items-center gap-2 cursor-pointer hover:opacity-80 transition-opacity"
  26. onClick={copyLinkToClipboard}
  27. >
  28. <h3 className="text-foreground text-lg font-medium">{title}</h3>
  29. <ButtonTooltip
  30. type="text"
  31. icon={copiedLink === id ? <Check size={14} /> : <Link size={14} />}
  32. className="w-7 h-7 opacity-0 group-hover:opacity-100 transition-opacity"
  33. tooltip={{
  34. content: {
  35. side: 'bottom',
  36. text: copiedLink === id ? 'Link copied!' : 'Copy link to section',
  37. },
  38. }}
  39. />
  40. </div>
  41. <p className="text-foreground-light text-sm">{description}</p>
  42. </div>
  43. )
  44. }