debug-info.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // zlwu12 2025-09-18 注释
  20. // const { locale } = useContext(I18n)
  21. const { data: info, isLoading } = useDebugKey()
  22. // info.key likes 4580bdb7-b878-471c-a8a4-bfd760263a53 mask the middle part using *.
  23. const maskedKey = info?.key?.replace(/(.{8})(.*)(.{8})/, '$1********$3')
  24. if (isLoading) return null
  25. return (
  26. <Tooltip
  27. triggerMethod='click'
  28. disabled={!info}
  29. popupContent={
  30. <>
  31. <div className='flex items-center gap-1 self-stretch'>
  32. <span className='system-sm-semibold flex shrink-0 grow basis-0 flex-col items-start justify-center text-text-secondary'>{t(`${i18nPrefix}.title`)}</span>
  33. {/* zlwu12 2025-09-18 注释 */}
  34. {/* <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'>
  35. <span className='system-xs-medium'>{t(`${i18nPrefix}.viewDocs`)}</span>
  36. <RiArrowRightUpLine className='h-3 w-3' />
  37. </a> */}
  38. </div>
  39. <div className='space-y-0.5'>
  40. <KeyValueItem
  41. label={'URL'}
  42. value={`${info?.host}:${info?.port}`}
  43. />
  44. <KeyValueItem
  45. label={'Key'}
  46. value={info?.key || ''}
  47. maskedValue={maskedKey}
  48. />
  49. </div>
  50. </>
  51. }
  52. popupClassName='flex flex-col items-start w-[256px] px-4 py-3.5 gap-1 border border-components-panel-border
  53. rounded-xl bg-components-tooltip-bg shadows-shadow-lg z-50'
  54. asChild={false}
  55. position='bottom'
  56. >
  57. <Button className='h-full w-full p-2 text-components-button-secondary-text'>
  58. <RiBugLine className='h-4 w-4' />
  59. </Button>
  60. </Tooltip>
  61. )
  62. }
  63. export default React.memo(DebugInfo)