From fa6f8ef498e473da088fae82c6bfe214b44a9237 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Tue, 24 Sep 2024 21:42:21 +0800 Subject: [PATCH] fix(console): fix console resource usage tooltip (#6629) --- .../src/components/PlanUsage/index.tsx | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/packages/console/src/components/PlanUsage/index.tsx b/packages/console/src/components/PlanUsage/index.tsx index 47c5174bb..0157c4c53 100644 --- a/packages/console/src/components/PlanUsage/index.tsx +++ b/packages/console/src/components/PlanUsage/index.tsx @@ -104,54 +104,54 @@ function PlanUsage({ periodicUsage: rawPeriodicUsage }: Props) { isEnterprisePlan || (onlyShowPeriodicUsage && (key === 'mauLimit' || key === 'tokenLimit')) ) - .map((key) => { - const parsedUsage = getUsageByKey(key, { + .map((key) => ({ + usage: getUsageByKey(key, { periodicUsage, countBasedUsage: currentSubscriptionUsage, basicQuota: currentSubscriptionBasicQuota, - }); - return { - usage: parsedUsage, - usageKey: 'subscription.usage.usage_description_with_limited_quota', - titleKey: `subscription.usage.${titleKeyMap[key]}`, - unitPrice: usageKeyPriceMap[key], - ...cond( - (key === 'tokenLimit' || key === 'mauLimit' || isPaidTenant) && { - quota: currentSubscriptionQuota[key], - } - ), - ...cond( - isPaidTenant && { - basicQuota: currentSubscriptionBasicQuota[key], - // Do not show tooltip if the basic quota is null (unlimited) and the usage is number-typed. - ...cond( - !(currentSubscriptionBasicQuota[key] === null && typeof parsedUsage === 'number') && { - tooltipKey: `subscription.usage.${ - isEnterprisePlan ? enterpriseTooltipKeyMap[key] : tooltipKeyMap[key] - }`, - } - ), - // Show tooltip for number-typed basic quota for 'organizationsLimit'. - ...cond( - key === 'organizationsLimit' && - typeof currentSubscriptionBasicQuota[key] === 'number' && - currentSubscriptionBasicQuota[key] > 0 && { - tooltipKey: - 'subscription.usage.organizations.tooltip_for_enterprise_with_numbered_basic_quota', - } - ), - } - ), - // Hide the quota notice for Pro plans if the basic quota is 0. - // Per current pricing model design, it should apply to `enterpriseSsoLimit`. - ...cond( - planId === ReservedPlanId.Pro && - currentSubscriptionBasicQuota[key] === 0 && { - isQuotaNoticeHidden: true, + }), + usageKey: 'subscription.usage.usage_description_with_limited_quota', + titleKey: `subscription.usage.${titleKeyMap[key]}`, + unitPrice: usageKeyPriceMap[key], + ...cond( + (key === 'tokenLimit' || key === 'mauLimit' || isPaidTenant) && { + quota: currentSubscriptionQuota[key], + } + ), + ...cond( + isPaidTenant && { + basicQuota: currentSubscriptionBasicQuota[key], + // Do not show tooltip if the basic quota is null (unlimited) for m2m/API resource add-on. + ...cond( + !( + currentSubscriptionBasicQuota[key] === null && + (key === 'machineToMachineLimit' || key === 'resourcesLimit') + ) && { + tooltipKey: `subscription.usage.${ + isEnterprisePlan ? enterpriseTooltipKeyMap[key] : tooltipKeyMap[key] + }`, } - ), - }; - }); + ), + // Show tooltip for number-typed basic quota for 'organizationsLimit'. + ...cond( + key === 'organizationsLimit' && + typeof currentSubscriptionBasicQuota[key] === 'number' && + currentSubscriptionBasicQuota[key] > 0 && { + tooltipKey: + 'subscription.usage.organizations.tooltip_for_enterprise_with_numbered_basic_quota', + } + ), + } + ), + // Hide the quota notice for Pro plans if the basic quota is 0. + // Per current pricing model design, it should apply to `enterpriseSsoLimit`. + ...cond( + planId === ReservedPlanId.Pro && + currentSubscriptionBasicQuota[key] === 0 && { + isQuotaNoticeHidden: true, + } + ), + })); return (