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

pull/22685/head
Junyan Qin 10 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) return snakeCase2CamelCase(deprecatedReason)
}, [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') if (status !== 'deleted')
return null return null
@ -54,7 +63,7 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
</div> </div>
<div className={cn('system-xs-regular grow py-1 text-text-primary', textClassName)}> <div className={cn('system-xs-regular grow py-1 text-text-primary', textClassName)}>
{ {
deprecatedReason && alternativePluginId && ( hasValidDeprecatedReason && alternativePluginId && (
<Trans <Trans
i18nKey={`${i18nPrefix}.fullMessage`} i18nKey={`${i18nPrefix}.fullMessage`}
components={{ components={{
@ -75,14 +84,14 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({
) )
} }
{ {
deprecatedReason && !alternativePluginId && ( hasValidDeprecatedReason && !alternativePluginId && (
<span> <span>
{t(`${i18nPrefix}.onlyReason`, { deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`) })} {t(`${i18nPrefix}.onlyReason`, { deprecatedReason: t(`${i18nPrefix}.reason.${deprecatedReasonKey}`) })}
</span> </span>
) )
} }
{ {
!deprecatedReason && ( !hasValidDeprecatedReason && (
<span>{t(`${i18nPrefix}.noReason`)}</span> <span>{t(`${i18nPrefix}.noReason`)}</span>
) )
} }

Loading…
Cancel
Save