0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix: update tenant selector dropdown data source (#6438)

This commit is contained in:
Darcy Ye 2024-08-13 13:22:26 +08:00 committed by GitHub
parent fe054d5af5
commit da58dec022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 47 additions and 77 deletions

View file

@ -27,7 +27,7 @@
"devDependencies": { "devDependencies": {
"@fontsource/roboto-mono": "^5.0.0", "@fontsource/roboto-mono": "^5.0.0",
"@jest/types": "^29.5.0", "@jest/types": "^29.5.0",
"@logto/cloud": "0.2.5-3452c56", "@logto/cloud": "0.2.5-a6cff75",
"@logto/connector-kit": "workspace:^4.0.0", "@logto/connector-kit": "workspace:^4.0.0",
"@logto/core-kit": "workspace:^2.5.0", "@logto/core-kit": "workspace:^2.5.0",
"@logto/elements": "workspace:^0.0.0", "@logto/elements": "workspace:^0.0.0",

View file

@ -1,10 +1,4 @@
import { conditional } from '@silverhand/essentials'; import { type TenantResponse } from '@/cloud/types/router';
import {
type TenantResponse,
type NewSubscriptionUsage,
type NewSubscriptionQuota,
} from '@/cloud/types/router';
import { isDevFeaturesEnabled } from '@/consts/env'; import { isDevFeaturesEnabled } from '@/consts/env';
import DynamicT from '@/ds-components/DynamicT'; import DynamicT from '@/ds-components/DynamicT';
import Tag from '@/ds-components/Tag'; import Tag from '@/ds-components/Tag';
@ -12,16 +6,13 @@ import { type SubscriptionPlan } from '@/types/subscriptions';
type Props = { type Props = {
readonly tenantData: TenantResponse; readonly tenantData: TenantResponse;
/** @deprecated */
readonly tenantSubscriptionPlan: SubscriptionPlan; readonly tenantSubscriptionPlan: SubscriptionPlan;
readonly tenantStatus: {
usage: NewSubscriptionUsage;
quota: NewSubscriptionQuota;
};
readonly className?: string; readonly className?: string;
}; };
function TenantStatusTag({ tenantData, tenantSubscriptionPlan, tenantStatus, className }: Props) { function TenantStatusTag({ tenantData, tenantSubscriptionPlan, className }: Props) {
const { usage, openInvoices, isSuspended } = tenantData; const { usage, quota, openInvoices, isSuspended } = tenantData;
/** /**
* Tenant status priority: * Tenant status priority:
@ -46,21 +37,11 @@ function TenantStatusTag({ tenantData, tenantSubscriptionPlan, tenantStatus, cla
); );
} }
const { usage: tenantUsage, quota: tenantQuota } = tenantStatus;
const { activeUsers } = usage; const { activeUsers } = usage;
const { const mauLimit = isDevFeaturesEnabled ? quota.mauLimit : tenantSubscriptionPlan.quota.mauLimit;
quota: { mauLimit },
} = tenantSubscriptionPlan;
const isMauExceeded = const isMauExceeded = mauLimit !== null && activeUsers >= mauLimit;
conditional(
isDevFeaturesEnabled &&
tenantQuota.mauLimit !== null &&
tenantUsage.mauLimit >= tenantQuota.mauLimit
) ??
(mauLimit !== null && activeUsers >= mauLimit);
if (isMauExceeded) { if (isMauExceeded) {
return ( return (

View file

@ -28,12 +28,7 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
subscription: { planId }, subscription: { planId },
} = tenantData; } = tenantData;
const { const { currentPlan, subscriptionPlans } = useContext(SubscriptionDataContext);
currentPlan,
subscriptionPlans,
currentSubscriptionUsage: usage,
currentSubscriptionQuota: quota,
} = useContext(SubscriptionDataContext);
const tenantSubscriptionPlan = useMemo( const tenantSubscriptionPlan = useMemo(
() => subscriptionPlans.find((plan) => plan.id === planId), () => subscriptionPlans.find((plan) => plan.id === planId),
[subscriptionPlans, planId] [subscriptionPlans, planId]
@ -51,7 +46,6 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
<TenantEnvTag tag={tag} /> <TenantEnvTag tag={tag} />
<TenantStatusTag <TenantStatusTag
tenantData={tenantData} tenantData={tenantData}
tenantStatus={{ usage, quota }}
tenantSubscriptionPlan={tenantSubscriptionPlan} tenantSubscriptionPlan={tenantSubscriptionPlan}
className={styles.statusTag} className={styles.statusTag}
/> />

View file

@ -34,8 +34,9 @@ export const defaultTenantResponse: TenantResponse = {
}, },
usage: { usage: {
activeUsers: 0, activeUsers: 0,
cost: 0, },
tokenUsage: 0, quota: {
mauLimit: null,
}, },
openInvoices: [], openInvoices: [],
isSuspended: false, isSuspended: false,

View file

@ -95,7 +95,7 @@
"zod": "^3.23.8" "zod": "^3.23.8"
}, },
"devDependencies": { "devDependencies": {
"@logto/cloud": "0.2.5-3452c56", "@logto/cloud": "0.2.5-a6cff75",
"@silverhand/eslint-config": "6.0.1", "@silverhand/eslint-config": "6.0.1",
"@silverhand/ts-config": "6.0.0", "@silverhand/ts-config": "6.0.0",
"@types/adm-zip": "^0.5.5", "@types/adm-zip": "^0.5.5",

View file

@ -8,7 +8,6 @@ import assertThat from '#src/utils/assert-that.js';
import { import {
getTenantSubscriptionPlan, getTenantSubscriptionPlan,
getTenantSubscriptionData, getTenantSubscriptionData,
getTenantSubscriptionScopeUsage,
reportSubscriptionUpdates, reportSubscriptionUpdates,
isReportSubscriptionUpdatesUsageKey, isReportSubscriptionUpdatesUsageKey,
} from '#src/utils/subscription/index.js'; } from '#src/utils/subscription/index.js';
@ -235,16 +234,12 @@ export const createQuotaLibrary = (
return; return;
} }
const [ const {
{ quota: { scopesPerResourceLimit, scopesPerRoleLimit },
quota: { scopesPerResourceLimit, scopesPerRoleLimit }, resources,
}, roles,
scopeUsages, } = await getTenantSubscriptionData(cloudConnection);
] = await Promise.all([ const usage = (entityName === 'resources' ? resources[entityId] : roles[entityId]) ?? 0;
getTenantSubscriptionData(cloudConnection),
getTenantSubscriptionScopeUsage(cloudConnection, entityName),
]);
const usage = scopeUsages[entityId] ?? 0;
if (entityName === 'resources') { if (entityName === 'resources') {
assertThat( assertThat(

View file

@ -43,28 +43,16 @@ export const getTenantSubscriptionData = async (
planId: string; planId: string;
quota: SubscriptionQuota; quota: SubscriptionQuota;
usage: SubscriptionUsage; usage: SubscriptionUsage;
resources: Record<string, number>;
roles: Record<string, number>;
}> => { }> => {
const client = await cloudConnection.getClient(); const client = await cloudConnection.getClient();
const [{ planId }, quota, usage] = await Promise.all([ const [{ planId }, { quota, usage, resources, roles }] = await Promise.all([
client.get('/api/tenants/my/subscription'), client.get('/api/tenants/my/subscription'),
client.get('/api/tenants/my/subscription/quota'), client.get('/api/tenants/my/subscription-usage'),
client.get('/api/tenants/my/subscription/usage'),
]); ]);
return { planId, quota, usage }; return { planId, quota, usage, resources, roles };
};
export const getTenantSubscriptionScopeUsage = async (
cloudConnection: CloudConnectionLibrary,
entityName: 'resources' | 'roles'
): Promise<Record<string, number>> => {
const client = await cloudConnection.getClient();
const scopeUsages = await client.get('/api/tenants/my/subscription/usage/:entityName/scopes', {
params: { entityName },
search: {},
});
return scopeUsages;
}; };
export const reportSubscriptionUpdates = async ( export const reportSubscriptionUpdates = async (

View file

@ -2458,8 +2458,8 @@ importers:
specifier: ^29.5.0 specifier: ^29.5.0
version: 29.5.0 version: 29.5.0
'@logto/cloud': '@logto/cloud':
specifier: 0.2.5-3452c56 specifier: 0.2.5-a6cff75
version: 0.2.5-3452c56(zod@3.23.8) version: 0.2.5-a6cff75(zod@3.23.8)
'@logto/connector-kit': '@logto/connector-kit':
specifier: workspace:^4.0.0 specifier: workspace:^4.0.0
version: link:../toolkit/connector-kit version: link:../toolkit/connector-kit
@ -2948,8 +2948,8 @@ importers:
version: 3.23.8 version: 3.23.8
devDependencies: devDependencies:
'@logto/cloud': '@logto/cloud':
specifier: 0.2.5-3452c56 specifier: 0.2.5-a6cff75
version: 0.2.5-3452c56(zod@3.23.8) version: 0.2.5-a6cff75(zod@3.23.8)
'@silverhand/eslint-config': '@silverhand/eslint-config':
specifier: 6.0.1 specifier: 6.0.1
version: 6.0.1(eslint@8.57.0)(prettier@3.0.0)(typescript@5.5.3) version: 6.0.1(eslint@8.57.0)(prettier@3.0.0)(typescript@5.5.3)
@ -5080,6 +5080,10 @@ packages:
resolution: {integrity: sha512-19MGifwYGxjQMPrm6monfoQyOp9UTL/chtZE0JugppNwvvLyqr3Nx0maCHuwrydLt0ImBSgVmPW1cJVvu2tVPg==} resolution: {integrity: sha512-19MGifwYGxjQMPrm6monfoQyOp9UTL/chtZE0JugppNwvvLyqr3Nx0maCHuwrydLt0ImBSgVmPW1cJVvu2tVPg==}
engines: {node: ^20.9.0} engines: {node: ^20.9.0}
'@logto/cloud@0.2.5-a6cff75':
resolution: {integrity: sha512-VlW8MI8RU5dWbHOXY6HjcaC4cqN+I0FIplZQnQjsf00R7K1EFvWfdzNqMcPsiK0ljnyEkRBH4GO77zJ/MYsNdg==}
engines: {node: ^20.9.0}
'@logto/js@4.1.4': '@logto/js@4.1.4':
resolution: {integrity: sha512-6twud1nFBQmj89/aflzej6yD1QwXfPiYmRtyYuN4a7O9OaaW3X/kJBVwjKUn5NC9IUt+rd+jXsI3QJXENfaLAw==} resolution: {integrity: sha512-6twud1nFBQmj89/aflzej6yD1QwXfPiYmRtyYuN4a7O9OaaW3X/kJBVwjKUn5NC9IUt+rd+jXsI3QJXENfaLAw==}
@ -14718,6 +14722,13 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- zod - zod
'@logto/cloud@0.2.5-a6cff75(zod@3.23.8)':
dependencies:
'@silverhand/essentials': 2.9.1
'@withtyped/server': 0.13.6(zod@3.23.8)
transitivePeerDependencies:
- zod
'@logto/js@4.1.4': '@logto/js@4.1.4':
dependencies: dependencies:
'@silverhand/essentials': 2.9.1 '@silverhand/essentials': 2.9.1
@ -15155,10 +15166,10 @@ snapshots:
eslint-config-prettier: 9.1.0(eslint@8.57.0) eslint-config-prettier: 9.1.0(eslint@8.57.0)
eslint-config-xo: 0.44.0(eslint@8.57.0) eslint-config-xo: 0.44.0(eslint@8.57.0)
eslint-config-xo-typescript: 4.0.0(@typescript-eslint/eslint-plugin@7.7.0(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)(typescript@5.5.3))(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)(typescript@5.5.3) eslint-config-xo-typescript: 4.0.0(@typescript-eslint/eslint-plugin@7.7.0(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)(typescript@5.5.3))(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0)(typescript@5.5.3)
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0) eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1)(eslint@8.57.0)
eslint-plugin-consistent-default-export-name: 0.0.15 eslint-plugin-consistent-default-export-name: 0.0.15
eslint-plugin-eslint-comments: 3.2.0(eslint@8.57.0) eslint-plugin-eslint-comments: 3.2.0(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
eslint-plugin-n: 17.2.1(eslint@8.57.0) eslint-plugin-n: 17.2.1(eslint@8.57.0)
eslint-plugin-no-use-extend-native: 0.5.0 eslint-plugin-no-use-extend-native: 0.5.0
eslint-plugin-prettier: 5.1.3(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.0.0) eslint-plugin-prettier: 5.1.3(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.0.0)
@ -18096,13 +18107,13 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0): eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1)(eslint@8.57.0):
dependencies: dependencies:
debug: 4.3.4 debug: 4.3.4
enhanced-resolve: 5.16.0 enhanced-resolve: 5.16.0
eslint: 8.57.0 eslint: 8.57.0
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
fast-glob: 3.3.2 fast-glob: 3.3.2
get-tsconfig: 4.7.3 get-tsconfig: 4.7.3
is-core-module: 2.13.1 is-core-module: 2.13.1
@ -18113,14 +18124,14 @@ snapshots:
- eslint-import-resolver-webpack - eslint-import-resolver-webpack
- supports-color - supports-color
eslint-module-utils@2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): eslint-module-utils@2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0):
dependencies: dependencies:
debug: 3.2.7(supports-color@5.5.0) debug: 3.2.7(supports-color@5.5.0)
optionalDependencies: optionalDependencies:
'@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.5.3) '@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.5.3)
eslint: 8.57.0 eslint: 8.57.0
eslint-import-resolver-node: 0.3.9 eslint-import-resolver-node: 0.3.9
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0) eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1)(eslint@8.57.0)
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
@ -18142,7 +18153,7 @@ snapshots:
eslint: 8.57.0 eslint: 8.57.0
ignore: 5.3.1 ignore: 5.3.1
eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
dependencies: dependencies:
array-includes: 3.1.8 array-includes: 3.1.8
array.prototype.findlastindex: 1.2.5 array.prototype.findlastindex: 1.2.5
@ -18152,7 +18163,7 @@ snapshots:
doctrine: 2.1.0 doctrine: 2.1.0
eslint: 8.57.0 eslint: 8.57.0
eslint-import-resolver-node: 0.3.9 eslint-import-resolver-node: 0.3.9
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0)
hasown: 2.0.2 hasown: 2.0.2
is-core-module: 2.13.1 is-core-module: 2.13.1
is-glob: 4.0.3 is-glob: 4.0.3