-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(console): add management api access flag for role options
- Loading branch information
Showing
22 changed files
with
180 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { RoleType, type RoleResponse } from '@logto/schemas'; | ||
import { RoleType, type ScopeResponse, isManagementApi, type RoleResponse } from '@logto/schemas'; | ||
import { useTranslation } from 'react-i18next'; | ||
import useSWR from 'swr'; | ||
|
||
import ManagementApiAccessFlag from '@/assets/icons/management-api-access.svg'; | ||
import { isDevFeaturesEnabled } from '@/consts/env'; | ||
import DynamicT from '@/ds-components/DynamicT'; | ||
import { Tooltip } from '@/ds-components/Tip'; | ||
|
||
import * as styles from './index.module.scss'; | ||
|
||
|
@@ -9,19 +15,36 @@ type Props = { | |
|
||
function RoleInformation({ role }: Props) { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); | ||
const { id, name, type, usersCount, applicationsCount } = role; | ||
const { data } = useSWR<ScopeResponse[]>( | ||
// Todo @xiaoyijun remove dev feature flag | ||
Check warning on line 20 in packages/console/src/components/RolesTransfer/components/RoleInformation/index.tsx GitHub Actions / ESLint Report Analysispackages/console/src/components/RolesTransfer/components/RoleInformation/index.tsx#L20
|
||
isDevFeaturesEnabled && type === RoleType.MachineToMachine && `api/roles/${id}/scopes` | ||
); | ||
|
||
const { name, type, usersCount, applicationsCount } = role; | ||
const withManagementApiAccess = data?.some(({ resource: { indicator } }) => | ||
isManagementApi(indicator) | ||
); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.name}>{name}</div> | ||
<div className={styles.count}> | ||
( | ||
{type === RoleType.User | ||
? t('user_details.roles.assigned_user_count', { value: usersCount }) | ||
: t('application_details.roles.assigned_app_count', { value: applicationsCount })} | ||
) | ||
</div> | ||
{!isDevFeaturesEnabled && ( | ||
<div className={styles.count}> | ||
( | ||
{type === RoleType.User | ||
? t('user_details.roles.assigned_user_count', { value: usersCount }) | ||
: t('application_details.roles.assigned_app_count', { value: applicationsCount })} | ||
) | ||
</div> | ||
)} | ||
{withManagementApiAccess && ( | ||
<Tooltip | ||
anchorClassName={styles.flag} | ||
content={<DynamicT forKey="roles.with_management_api_access_tip" />} | ||
> | ||
<ManagementApiAccessFlag /> | ||
</Tooltip> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
packages/console/src/components/RolesTransfer/index.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
.rolesTransfer { | ||
height: 360px; | ||
} | ||
|
||
.flagIcon { | ||
color: var(--color-text-secondary); | ||
// Align the flag icon with the text bottom to make it look centered visually | ||
vertical-align: text-bottom; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import type { RoleResponse, RoleType } from '@logto/schemas'; | ||
import { type RoleResponse, RoleType } from '@logto/schemas'; | ||
import classNames from 'classnames'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
|
||
import ManagementApiAccessFlag from '@/assets/icons/management-api-access.svg'; | ||
import { isDevFeaturesEnabled } from '@/consts/env'; | ||
import FormField from '@/ds-components/FormField'; | ||
import InlineNotification from '@/ds-components/InlineNotification'; | ||
import useConfigs from '@/hooks/use-configs'; | ||
import * as transferLayout from '@/scss/transfer.module.scss'; | ||
|
||
import SourceRolesBox from './SourceRolesBox'; | ||
|
@@ -15,11 +21,48 @@ type Props = { | |
}; | ||
|
||
function RolesTransfer({ entityId, type, value, onChange }: Props) { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); | ||
const isM2mRole = type === RoleType.MachineToMachine; | ||
const { configs, updateConfigs } = useConfigs(); | ||
|
||
// Default to true if configs is not loaded to avoid page flickering | ||
const notificationAcknowledged = configs | ||
? Boolean(configs.roleWithManagementApiAccessNotificationAcknowledged) | ||
: true; | ||
|
||
return ( | ||
<div className={classNames(transferLayout.container, styles.rolesTransfer)}> | ||
<SourceRolesBox entityId={entityId} type={type} selectedRoles={value} onChange={onChange} /> | ||
<div className={transferLayout.verticalBar} /> | ||
<TargetRolesBox selectedRoles={value} onChange={onChange} /> | ||
<div> | ||
{/* Todo @xiaoyijun remove dev feature flag */} | ||
Check warning on line 35 in packages/console/src/components/RolesTransfer/index.tsx GitHub Actions / ESLint Report Analysispackages/console/src/components/RolesTransfer/index.tsx#L35
|
||
{isDevFeaturesEnabled && isM2mRole && !notificationAcknowledged && ( | ||
<InlineNotification | ||
action="general.got_it" | ||
onClick={() => { | ||
void updateConfigs({ | ||
roleWithManagementApiAccessNotificationAcknowledged: true, | ||
}); | ||
}} | ||
> | ||
<Trans | ||
components={{ | ||
flag: <ManagementApiAccessFlag className={styles.flagIcon} />, | ||
}} | ||
> | ||
{t('roles.management_api_access_notification')} | ||
</Trans> | ||
</InlineNotification> | ||
)} | ||
<FormField title={isM2mRole ? 'roles.assign_m2m_roles' : 'roles.assign_user_roles'}> | ||
<div className={classNames(transferLayout.container, styles.rolesTransfer)}> | ||
<SourceRolesBox | ||
entityId={entityId} | ||
type={type} | ||
selectedRoles={value} | ||
onChange={onChange} | ||
/> | ||
<div className={transferLayout.verticalBar} /> | ||
<TargetRolesBox selectedRoles={value} onChange={onChange} /> | ||
</div> | ||
</FormField> | ||
</div> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters