perf: fallback to onReason UI when provided reason key has no corresponding i18n text

pull/22685/head
Junyan Qin 7 months ago
parent 7ab66bdb48
commit 557e01ef74
No known key found for this signature in database
GPG Key ID: 22FE3AFADC710CEB

@ -39,6 +39,15 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
return snakeCase2CamelCase(deprecatedReason)
}, [deprecatedReason])
// Check if the deprecatedReasonKey exists in i18n
const hasValidDeprecatedReason = useMemo(() => {
if (!deprecatedReason || !deprecatedReasonKey) return false
// Define valid reason keys that exist in i18n
const validReasonKeys = ['businessAdjustments', 'ownershipTransferred', 'noMaintainer']
return validReasonKeys.includes(deprecatedReasonKey)
}, [deprecatedReason, deprecatedReasonKey])
if (status !== 'deleted')
return null
@ -54,7 +63,7 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
</div>
<div className={cn('system-xs-regular grow py-1 text-text-primary', textClassName)}>
{
deprecatedReason && alternativePluginId && (
hasValidDeprecatedReason && alternativePluginId && (
<Trans
i18nKey={`${i18nPrefix}.fullMessage`}
components={{
@ -75,14 +84,14 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
)
}
{
deprecatedReason && !alternativePluginId && (
hasValidDeprecatedReason && !alternativePluginId && (
<span>
{t(`${i18nPrefix}.onlyReason`, { deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`) })}
</span>
)
}
{
!deprecatedReason && (
!hasValidDeprecatedReason && (
<span>{t(`${i18nPrefix}.noReason`)}</span>
)
}

Loading…
Cancel
Save