0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-24 22:41:28 -05:00

refactor(console): add useMemo to resources and scopes ()

This commit is contained in:
Gao Sun 2023-04-24 21:00:53 +08:00 committed by GitHub
parent a1a563a681
commit c4864d6562
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ import { UserScope } from '@logto/core-kit';
import { LogtoProvider } from '@logto/react';
import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas';
import { conditionalArray, deduplicate } from '@silverhand/essentials';
import { useContext, useEffect } from 'react';
import { useContext, useEffect, useMemo } from 'react';
import { Helmet } from 'react-helmet';
import 'overlayscrollbars/styles/overlayscrollbars.css';
@ -36,28 +36,35 @@ function Content() {
void setup('console', { cookieDomain: getPrimaryDomain() });
}, [setup]);
const resources = deduplicate(
conditionalArray(
// Explicitly add `currentTenantId` and deduplicate since the user may directly
// access a URL with Tenant ID, adding the ID from the URL here can possibly remove one
// additional redirect.
currentTenantId && getManagementApi(currentTenantId).indicator,
...(tenants ?? []).map(({ id }) => getManagementApi(id).indicator),
isCloud && cloudApi.indicator,
meApi.indicator
)
const resources = useMemo(
() =>
deduplicate(
conditionalArray(
// Explicitly add `currentTenantId` and deduplicate since the user may directly
// access a URL with Tenant ID, adding the ID from the URL here can possibly remove one
// additional redirect.
currentTenantId && getManagementApi(currentTenantId).indicator,
...(tenants ?? []).map(({ id }) => getManagementApi(id).indicator),
isCloud && cloudApi.indicator,
meApi.indicator
)
),
[currentTenantId, tenants]
);
const scopes = [
UserScope.Email,
UserScope.Identities,
UserScope.CustomData,
PredefinedScope.All,
...conditionalArray(
isCloud && cloudApi.scopes.CreateTenant,
isCloud && cloudApi.scopes.ManageTenant
),
];
const scopes = useMemo(
() => [
UserScope.Email,
UserScope.Identities,
UserScope.CustomData,
PredefinedScope.All,
...conditionalArray(
isCloud && cloudApi.scopes.CreateTenant,
isCloud && cloudApi.scopes.ManageTenant
),
],
[]
);
return (
<LogtoProvider