Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

deprecation-notice.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React, { useMemo } from 'react'
  2. import type { FC } from 'react'
  3. import Link from 'next/link'
  4. import cn from '@/utils/classnames'
  5. import { RiAlertFill } from '@remixicon/react'
  6. import { Trans } from 'react-i18next'
  7. import { useMixedTranslation } from '../marketplace/hooks'
  8. import { camelCase } from 'lodash-es'
  9. type DeprecationNoticeProps = {
  10. status: 'deleted' | 'active'
  11. deprecatedReason: string
  12. alternativePluginId: string
  13. alternativePluginURL: string
  14. locale?: string
  15. className?: string
  16. innerWrapperClassName?: string
  17. iconWrapperClassName?: string
  18. textClassName?: string
  19. }
  20. const i18nPrefix = 'plugin.detailPanel.deprecation'
  21. const DeprecationNotice: FC<DeprecationNoticeProps> = ({
  22. status,
  23. deprecatedReason,
  24. alternativePluginId,
  25. alternativePluginURL,
  26. locale,
  27. className,
  28. innerWrapperClassName,
  29. iconWrapperClassName,
  30. textClassName,
  31. }) => {
  32. const { t } = useMixedTranslation(locale)
  33. const deprecatedReasonKey = useMemo(() => {
  34. if (!deprecatedReason) return ''
  35. return camelCase(deprecatedReason)
  36. }, [deprecatedReason])
  37. // Check if the deprecatedReasonKey exists in i18n
  38. const hasValidDeprecatedReason = useMemo(() => {
  39. if (!deprecatedReason || !deprecatedReasonKey) return false
  40. // Define valid reason keys that exist in i18n
  41. const validReasonKeys = ['businessAdjustments', 'ownershipTransferred', 'noMaintainer']
  42. return validReasonKeys.includes(deprecatedReasonKey)
  43. }, [deprecatedReason, deprecatedReasonKey])
  44. if (status !== 'deleted')
  45. return null
  46. return (
  47. <div className={cn('w-full', className)}>
  48. <div className={cn(
  49. 'relative flex items-start gap-x-0.5 overflow-hidden rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur p-2 shadow-xs shadow-shadow-shadow-3 backdrop-blur-[5px]',
  50. innerWrapperClassName,
  51. )}>
  52. <div className='absolute left-0 top-0 -z-10 h-full w-full bg-toast-warning-bg opacity-40' />
  53. <div className={cn('flex size-6 shrink-0 items-center justify-center', iconWrapperClassName)}>
  54. <RiAlertFill className='size-4 text-text-warning-secondary' />
  55. </div>
  56. <div className={cn('system-xs-regular grow py-1 text-text-primary', textClassName)}>
  57. {
  58. hasValidDeprecatedReason && alternativePluginId && (
  59. <Trans
  60. t={t}
  61. i18nKey={`${i18nPrefix}.fullMessage`}
  62. components={{
  63. CustomLink: (
  64. <Link
  65. href={alternativePluginURL}
  66. target='_blank'
  67. rel='noopener noreferrer'
  68. className='underline'
  69. />
  70. ),
  71. }}
  72. values={{
  73. deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`),
  74. alternativePluginId,
  75. }}
  76. />
  77. )
  78. }
  79. {
  80. hasValidDeprecatedReason && !alternativePluginId && (
  81. <span>
  82. {t(`${i18nPrefix}.onlyReason`, { deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`) })}
  83. </span>
  84. )
  85. }
  86. {
  87. !hasValidDeprecatedReason && (
  88. <span>{t(`${i18nPrefix}.noReason`)}</span>
  89. )
  90. }
  91. </div>
  92. </div>
  93. </div>
  94. )
  95. }
  96. export default React.memo(DeprecationNotice)