Skip to content

Commit ffa1cfe

Browse files
authored
fix(console): hide add-on usage keys from downgrade modal (#7728)
hide add-on and deprecated keys from the downgrade modal
1 parent 230fe4b commit ffa1cfe

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/console/src/consts/plan-quotas.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,17 @@ export const skuQuotaItemOrder: Array<keyof LogtoSkuQuota> = [
4040
];
4141

4242
export const comingSoonSkuQuotaKeys: Array<keyof LogtoSkuQuota> = [];
43+
44+
/**
45+
* Quota keys that are hidden in the subscription downgrade notification modal.
46+
*
47+
* @remarks We hide the following quota keys from the downgrade notification modal
48+
* because they are either add-on features or their quotas vary based on the current plan.
49+
*/
50+
export const hiddenQuotaDiffUsageKeys: Array<keyof LogtoSkuQuota> = [
51+
'tokenLimit',
52+
'scopesPerResourceLimit',
53+
'userRolesLimit',
54+
'machineToMachineRolesLimit',
55+
'scopesPerRoleLimit',
56+
];

packages/console/src/pages/TenantSettings/Subscription/DowngradeConfirmModalContent/index.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next';
44

55
import { type LogtoSkuResponse } from '@/cloud/types/router';
66
import SkuName from '@/components/SkuName';
7-
import { comingSoonSkuQuotaKeys } from '@/consts/plan-quotas';
7+
import { comingSoonSkuQuotaKeys, hiddenQuotaDiffUsageKeys } from '@/consts/plan-quotas';
88
import { type LogtoSkuQuota, type LogtoSkuQuotaEntries } from '@/types/skus';
99

1010
import PlanQuotaDiffCard from './PlanQuotaDiffCard';
@@ -15,24 +15,31 @@ type Props = {
1515
readonly targetSku: LogtoSkuResponse;
1616
};
1717

18-
const excludeSkuComingSoonFeatures = (
19-
quotaDiff: Partial<LogtoSkuQuota>
20-
): Partial<LogtoSkuQuota> => {
18+
/**
19+
* Exclude the quota items that are hidden in the downgrade plan notification modal.
20+
* - Coming soon features
21+
* - Add-on/legacy features whose quotas vary based on the current plan
22+
*/
23+
const excludeHiddenUsages = (quotaDiff: Partial<LogtoSkuQuota>): Partial<LogtoSkuQuota> => {
2124
// eslint-disable-next-line no-restricted-syntax
2225
const entries = Object.entries(quotaDiff) as LogtoSkuQuotaEntries;
23-
return Object.fromEntries(entries.filter(([key]) => !comingSoonSkuQuotaKeys.includes(key)));
26+
return Object.fromEntries(
27+
entries.filter(
28+
([key]) => !comingSoonSkuQuotaKeys.includes(key) && !hiddenQuotaDiffUsageKeys.includes(key)
29+
)
30+
);
2431
};
2532

2633
function DowngradeConfirmModalContent({ currentSku, targetSku }: Props) {
2734
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
2835

2936
const currentSkuQuotaDiff = useMemo(
30-
() => excludeSkuComingSoonFeatures(diff(targetSku.quota, currentSku.quota)),
37+
() => excludeHiddenUsages(diff(targetSku.quota, currentSku.quota)),
3138
[targetSku.quota, currentSku.quota]
3239
);
3340

3441
const targetSkuQuotaDiff = useMemo(
35-
() => excludeSkuComingSoonFeatures(diff(currentSku.quota, targetSku.quota)),
42+
() => excludeHiddenUsages(diff(currentSku.quota, targetSku.quota)),
3643
[targetSku.quota, currentSku.quota]
3744
);
3845

0 commit comments

Comments
 (0)