-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove Accountbox usage (#29786)
- Loading branch information
Showing
9 changed files
with
86 additions
and
157 deletions.
There are no files selected for viewing
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
70 changes: 9 additions & 61 deletions
70
apps/meteor/client/sidebar/header/actions/hooks/useAdministrationMenu.tsx
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,72 +1,20 @@ | ||
import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; | ||
import { useAtLeastOnePermission, usePermission, useTranslation } from '@rocket.chat/ui-contexts'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
|
||
import { AccountBox } from '../../../../../app/ui-utils/client'; | ||
import type { IAppAccountBoxItem, AccountBoxItem } from '../../../../../app/ui-utils/client/lib/AccountBox'; | ||
import { isAppAccountBoxItem } from '../../../../../app/ui-utils/client/lib/AccountBox'; | ||
import { useHasLicenseModule } from '../../../../../ee/client/hooks/useHasLicenseModule'; | ||
import { useReactiveValue } from '../../../../hooks/useReactiveValue'; | ||
import type { GenericMenuItemProps } from '../../../../components/GenericMenu/GenericMenuItem'; | ||
import { useAdministrationItems } from './useAdministrationItems'; | ||
import { useAppsItems } from './useAppsItems'; | ||
import { useAuditItems } from './useAuditItems'; | ||
|
||
const ADMIN_PERMISSIONS = [ | ||
'view-statistics', | ||
'run-import', | ||
'view-user-administration', | ||
'view-room-administration', | ||
'create-invite-links', | ||
'manage-cloud', | ||
'view-logs', | ||
'manage-sounds', | ||
'view-federation-data', | ||
'manage-email-inbox', | ||
'manage-emoji', | ||
'manage-outgoing-integrations', | ||
'manage-own-outgoing-integrations', | ||
'manage-incoming-integrations', | ||
'manage-own-incoming-integrations', | ||
'manage-oauth-apps', | ||
'access-mailer', | ||
'manage-user-status', | ||
'access-permissions', | ||
'access-setting-permissions', | ||
'view-privileged-setting', | ||
'edit-privileged-setting', | ||
'manage-selected-settings', | ||
'view-engagement-dashboard', | ||
'view-moderation-console', | ||
]; | ||
|
||
export const useAdministrationMenu = () => { | ||
const t = useTranslation(); | ||
const getAccountBoxItems = useMutableCallback(() => AccountBox.getItems()); | ||
const accountBoxItems = useReactiveValue(getAccountBoxItems); | ||
|
||
const hasAuditLicense = useHasLicenseModule('auditing') === true; | ||
const hasManageAppsPermission = usePermission('manage-apps'); | ||
const hasAccessMarketplacePermission = usePermission('access-marketplace'); | ||
const hasAdminPermission = useAtLeastOnePermission(ADMIN_PERMISSIONS); | ||
const hasAuditPermission = usePermission('can-audit') && hasAuditLicense; | ||
const hasAuditLogPermission = usePermission('can-audit-log') && hasAuditLicense; | ||
|
||
const appBoxItems = accountBoxItems.filter((item): item is IAppAccountBoxItem => isAppAccountBoxItem(item)); | ||
const adminBoxItems = accountBoxItems.filter((item): item is AccountBoxItem => !isAppAccountBoxItem(item)); | ||
|
||
const showAdmin = hasAdminPermission || !!adminBoxItems.length; | ||
const showAudit = hasAuditPermission || hasAuditLogPermission; | ||
const showWorkspace = hasAdminPermission; | ||
const showApps = hasAccessMarketplacePermission || hasManageAppsPermission || !!appBoxItems.length; | ||
|
||
const administrationItems = useAdministrationItems({ accountBoxItems: adminBoxItems, showWorkspace }); | ||
const administrationItems = useAdministrationItems(); | ||
const appItems = useAppsItems(); | ||
const auditItems = useAuditItems({ showAudit: hasAuditPermission, showAuditLog: hasAuditLogPermission }); | ||
|
||
const sections = [ | ||
{ title: t('Administration'), items: administrationItems, permission: showAdmin }, | ||
{ title: t('Apps'), items: appItems, permission: showApps }, | ||
{ title: t('Audit'), items: auditItems, permission: showAudit }, | ||
]; | ||
const auditItems = useAuditItems(); | ||
|
||
return sections.filter(({ permission }) => permission); | ||
return [ | ||
administrationItems.length && { title: t('Administration'), items: administrationItems }, | ||
appItems.length && { title: t('Apps'), items: appItems }, | ||
auditItems.length && { title: t('Audit'), items: auditItems }, | ||
].filter(Boolean) as Array<{ title: string; items: GenericMenuItemProps[] }>; | ||
}; |
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