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:
parent
fe054d5af5
commit
da58dec022
8 changed files with 47 additions and 77 deletions
|
@ -27,7 +27,7 @@
|
|||
"devDependencies": {
|
||||
"@fontsource/roboto-mono": "^5.0.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/core-kit": "workspace:^2.5.0",
|
||||
"@logto/elements": "workspace:^0.0.0",
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
import { conditional } from '@silverhand/essentials';
|
||||
|
||||
import {
|
||||
type TenantResponse,
|
||||
type NewSubscriptionUsage,
|
||||
type NewSubscriptionQuota,
|
||||
} from '@/cloud/types/router';
|
||||
import { type TenantResponse } from '@/cloud/types/router';
|
||||
import { isDevFeaturesEnabled } from '@/consts/env';
|
||||
import DynamicT from '@/ds-components/DynamicT';
|
||||
import Tag from '@/ds-components/Tag';
|
||||
|
@ -12,16 +6,13 @@ import { type SubscriptionPlan } from '@/types/subscriptions';
|
|||
|
||||
type Props = {
|
||||
readonly tenantData: TenantResponse;
|
||||
/** @deprecated */
|
||||
readonly tenantSubscriptionPlan: SubscriptionPlan;
|
||||
readonly tenantStatus: {
|
||||
usage: NewSubscriptionUsage;
|
||||
quota: NewSubscriptionQuota;
|
||||
};
|
||||
readonly className?: string;
|
||||
};
|
||||
|
||||
function TenantStatusTag({ tenantData, tenantSubscriptionPlan, tenantStatus, className }: Props) {
|
||||
const { usage, openInvoices, isSuspended } = tenantData;
|
||||
function TenantStatusTag({ tenantData, tenantSubscriptionPlan, className }: Props) {
|
||||
const { usage, quota, openInvoices, isSuspended } = tenantData;
|
||||
|
||||
/**
|
||||
* Tenant status priority:
|
||||
|
@ -46,21 +37,11 @@ function TenantStatusTag({ tenantData, tenantSubscriptionPlan, tenantStatus, cla
|
|||
);
|
||||
}
|
||||
|
||||
const { usage: tenantUsage, quota: tenantQuota } = tenantStatus;
|
||||
|
||||
const { activeUsers } = usage;
|
||||
|
||||
const {
|
||||
quota: { mauLimit },
|
||||
} = tenantSubscriptionPlan;
|
||||
const mauLimit = isDevFeaturesEnabled ? quota.mauLimit : tenantSubscriptionPlan.quota.mauLimit;
|
||||
|
||||
const isMauExceeded =
|
||||
conditional(
|
||||
isDevFeaturesEnabled &&
|
||||
tenantQuota.mauLimit !== null &&
|
||||
tenantUsage.mauLimit >= tenantQuota.mauLimit
|
||||
) ??
|
||||
(mauLimit !== null && activeUsers >= mauLimit);
|
||||
const isMauExceeded = mauLimit !== null && activeUsers >= mauLimit;
|
||||
|
||||
if (isMauExceeded) {
|
||||
return (
|
||||
|
|
|
@ -28,12 +28,7 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
|
|||
subscription: { planId },
|
||||
} = tenantData;
|
||||
|
||||
const {
|
||||
currentPlan,
|
||||
subscriptionPlans,
|
||||
currentSubscriptionUsage: usage,
|
||||
currentSubscriptionQuota: quota,
|
||||
} = useContext(SubscriptionDataContext);
|
||||
const { currentPlan, subscriptionPlans } = useContext(SubscriptionDataContext);
|
||||
const tenantSubscriptionPlan = useMemo(
|
||||
() => subscriptionPlans.find((plan) => plan.id === planId),
|
||||
[subscriptionPlans, planId]
|
||||
|
@ -51,7 +46,6 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
|
|||
<TenantEnvTag tag={tag} />
|
||||
<TenantStatusTag
|
||||
tenantData={tenantData}
|
||||
tenantStatus={{ usage, quota }}
|
||||
tenantSubscriptionPlan={tenantSubscriptionPlan}
|
||||
className={styles.statusTag}
|
||||
/>
|
||||
|
|
|
@ -34,8 +34,9 @@ export const defaultTenantResponse: TenantResponse = {
|
|||
},
|
||||
usage: {
|
||||
activeUsers: 0,
|
||||
cost: 0,
|
||||
tokenUsage: 0,
|
||||
},
|
||||
quota: {
|
||||
mauLimit: null,
|
||||
},
|
||||
openInvoices: [],
|
||||
isSuspended: false,
|
||||
|
|
|
@ -95,7 +95,7 @@
|
|||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@logto/cloud": "0.2.5-3452c56",
|
||||
"@logto/cloud": "0.2.5-a6cff75",
|
||||
"@silverhand/eslint-config": "6.0.1",
|
||||
"@silverhand/ts-config": "6.0.0",
|
||||
"@types/adm-zip": "^0.5.5",
|
||||
|
|
|
@ -8,7 +8,6 @@ import assertThat from '#src/utils/assert-that.js';
|
|||
import {
|
||||
getTenantSubscriptionPlan,
|
||||
getTenantSubscriptionData,
|
||||
getTenantSubscriptionScopeUsage,
|
||||
reportSubscriptionUpdates,
|
||||
isReportSubscriptionUpdatesUsageKey,
|
||||
} from '#src/utils/subscription/index.js';
|
||||
|
@ -235,16 +234,12 @@ export const createQuotaLibrary = (
|
|||
return;
|
||||
}
|
||||
|
||||
const [
|
||||
{
|
||||
const {
|
||||
quota: { scopesPerResourceLimit, scopesPerRoleLimit },
|
||||
},
|
||||
scopeUsages,
|
||||
] = await Promise.all([
|
||||
getTenantSubscriptionData(cloudConnection),
|
||||
getTenantSubscriptionScopeUsage(cloudConnection, entityName),
|
||||
]);
|
||||
const usage = scopeUsages[entityId] ?? 0;
|
||||
resources,
|
||||
roles,
|
||||
} = await getTenantSubscriptionData(cloudConnection);
|
||||
const usage = (entityName === 'resources' ? resources[entityId] : roles[entityId]) ?? 0;
|
||||
|
||||
if (entityName === 'resources') {
|
||||
assertThat(
|
||||
|
|
|
@ -43,28 +43,16 @@ export const getTenantSubscriptionData = async (
|
|||
planId: string;
|
||||
quota: SubscriptionQuota;
|
||||
usage: SubscriptionUsage;
|
||||
resources: Record<string, number>;
|
||||
roles: Record<string, number>;
|
||||
}> => {
|
||||
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/quota'),
|
||||
client.get('/api/tenants/my/subscription/usage'),
|
||||
client.get('/api/tenants/my/subscription-usage'),
|
||||
]);
|
||||
|
||||
return { planId, quota, usage };
|
||||
};
|
||||
|
||||
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;
|
||||
return { planId, quota, usage, resources, roles };
|
||||
};
|
||||
|
||||
export const reportSubscriptionUpdates = async (
|
||||
|
|
|
@ -2458,8 +2458,8 @@ importers:
|
|||
specifier: ^29.5.0
|
||||
version: 29.5.0
|
||||
'@logto/cloud':
|
||||
specifier: 0.2.5-3452c56
|
||||
version: 0.2.5-3452c56(zod@3.23.8)
|
||||
specifier: 0.2.5-a6cff75
|
||||
version: 0.2.5-a6cff75(zod@3.23.8)
|
||||
'@logto/connector-kit':
|
||||
specifier: workspace:^4.0.0
|
||||
version: link:../toolkit/connector-kit
|
||||
|
@ -2948,8 +2948,8 @@ importers:
|
|||
version: 3.23.8
|
||||
devDependencies:
|
||||
'@logto/cloud':
|
||||
specifier: 0.2.5-3452c56
|
||||
version: 0.2.5-3452c56(zod@3.23.8)
|
||||
specifier: 0.2.5-a6cff75
|
||||
version: 0.2.5-a6cff75(zod@3.23.8)
|
||||
'@silverhand/eslint-config':
|
||||
specifier: 6.0.1
|
||||
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==}
|
||||
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':
|
||||
resolution: {integrity: sha512-6twud1nFBQmj89/aflzej6yD1QwXfPiYmRtyYuN4a7O9OaaW3X/kJBVwjKUn5NC9IUt+rd+jXsI3QJXENfaLAw==}
|
||||
|
||||
|
@ -14718,6 +14722,13 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- 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':
|
||||
dependencies:
|
||||
'@silverhand/essentials': 2.9.1
|
||||
|
@ -15155,10 +15166,10 @@ snapshots:
|
|||
eslint-config-prettier: 9.1.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-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-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-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)
|
||||
|
@ -18096,13 +18107,13 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- 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:
|
||||
debug: 4.3.4
|
||||
enhanced-resolve: 5.16.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-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-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)(eslint@8.57.0)
|
||||
fast-glob: 3.3.2
|
||||
get-tsconfig: 4.7.3
|
||||
is-core-module: 2.13.1
|
||||
|
@ -18113,14 +18124,14 @@ snapshots:
|
|||
- eslint-import-resolver-webpack
|
||||
- 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:
|
||||
debug: 3.2.7(supports-color@5.5.0)
|
||||
optionalDependencies:
|
||||
'@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.5.3)
|
||||
eslint: 8.57.0
|
||||
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:
|
||||
- supports-color
|
||||
|
||||
|
@ -18142,7 +18153,7 @@ snapshots:
|
|||
eslint: 8.57.0
|
||||
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:
|
||||
array-includes: 3.1.8
|
||||
array.prototype.findlastindex: 1.2.5
|
||||
|
@ -18152,7 +18163,7 @@ snapshots:
|
|||
doctrine: 2.1.0
|
||||
eslint: 8.57.0
|
||||
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
|
||||
is-core-module: 2.13.1
|
||||
is-glob: 4.0.3
|
||||
|
|
Loading…
Reference in a new issue