Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

debug-info.tsx 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useContext } from 'use-context-selector'
  5. import I18n from '@/context/i18n'
  6. import {
  7. RiArrowRightUpLine,
  8. RiBugLine,
  9. } from '@remixicon/react'
  10. import { useTranslation } from 'react-i18next'
  11. import KeyValueItem from '../base/key-value-item'
  12. import Tooltip from '@/app/components/base/tooltip'
  13. import Button from '@/app/components/base/button'
  14. import { getDocsUrl } from '@/app/components/plugins/utils'
  15. import { useDebugKey } from '@/service/use-plugins'
  16. const i18nPrefix = 'plugin.debugInfo'
  17. const DebugInfo: FC = () => {
  18. const { t } = useTranslation()
  19. const { locale } = useContext(I18n)
  20. const { data: info, isLoading } = useDebugKey()
  21. // info.key likes 4580bdb7-b878-471c-a8a4-bfd760263a53 mask the middle part using *.
  22. const maskedKey = info?.key?.replace(/(.{8})(.*)(.{8})/, '$1********$3')
  23. if (isLoading) return null
  24. return (
  25. <Tooltip
  26. triggerMethod='click'
  27. disabled={!info}
  28. popupContent={
  29. <>
  30. <div className='flex items-center gap-1 self-stretch'>
  31. <span className='system-sm-semibold flex shrink-0 grow basis-0 flex-col items-start justify-center text-text-secondary'>{t(`${i18nPrefix}.title`)}</span>
  32. <a href={getDocsUrl(locale, '/plugins/quick-start/debug-plugin')} target='_blank' className='flex cursor-pointer items-center gap-0.5 text-text-accent-light-mode-only'>
  33. <span className='system-xs-medium'>{t(`${i18nPrefix}.viewDocs`)}</span>
  34. <RiArrowRightUpLine className='h-3 w-3' />
  35. </a>
  36. </div>
  37. <div className='space-y-0.5'>
  38. <KeyValueItem
  39. label={'URL'}
  40. value={`${info?.host}:${info?.port}`}
  41. />
  42. <KeyValueItem
  43. label={'Key'}
  44. value={info?.key || ''}
  45. maskedValue={maskedKey}
  46. />
  47. </div>
  48. </>
  49. }
  50. popupClassName='flex flex-col items-start w-[256px] px-4 py-3.5 gap-1 border border-components-panel-border
  51. rounded-xl bg-components-tooltip-bg shadows-shadow-lg z-50'
  52. asChild={false}
  53. position='bottom'
  54. >
  55. <Button className='h-full w-full p-2 text-components-button-secondary-text'>
  56. <RiBugLine className='h-4 w-4' />
  57. </Button>
  58. </Tooltip>
  59. )
  60. }
  61. export default React.memo(DebugInfo)