fix: fix sorting of user menu (#2288)

This commit is contained in:
被雨水过滤的空气-Rain 2023-07-21 10:39:58 +08:00 committed by GitHub
parent 4f5ec0a581
commit aab3fafd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 39 deletions

View File

@ -1,7 +1,7 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import { error } from '@nocobase/utils/client'; import { error } from '@nocobase/utils/client';
import { App, Dropdown, Menu, MenuProps } from 'antd'; import { App, Dropdown, Menu, MenuProps } from 'antd';
import React, { createContext, useCallback, useMemo, useState } from 'react'; import React, { createContext, useCallback, useMemo as useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { useACLRoleContext, useAPIClient, useCurrentUserContext } from '..'; import { useACLRoleContext, useAPIClient, useCurrentUserContext } from '..';
@ -13,7 +13,7 @@ import { useLanguageSettings } from './LanguageSettings';
import { useSwitchRole } from './SwitchRole'; import { useSwitchRole } from './SwitchRole';
const useApplicationVersion = () => { const useApplicationVersion = () => {
const data = useCurrentAppInfo(); const data = useCurrentAppInfo();
return useMemo(() => { return useEffect(() => {
return { return {
key: 'version', key: 'version',
disabled: true, disabled: true,
@ -62,7 +62,7 @@ export const SettingsMenu: React.FC<{
const switchRole = useSwitchRole(); const switchRole = useSwitchRole();
const languageSettings = useLanguageSettings(); const languageSettings = useLanguageSettings();
const { modal } = App.useApp(); const { modal } = App.useApp();
const controlApp = useMemo<MenuProps['items']>(() => { const controlApp = useEffect<MenuProps['items']>(() => {
if (!appAllowed) { if (!appAllowed) {
return []; return [];
} }
@ -102,40 +102,56 @@ export const SettingsMenu: React.FC<{
]; ];
}, [api, appAllowed, check, modal, t]); }, [api, appAllowed, check, modal, t]);
const items = [ useEffect(() => {
appVersion, const items = [
{ appVersion,
key: 'divider_1', {
type: 'divider', key: 'divider_1',
}, type: 'divider',
editProfile,
changePassword,
{
key: 'divider_2',
type: 'divider',
},
switchRole,
languageSettings,
{
key: 'divider_3',
type: 'divider',
},
...controlApp,
{
key: 'signout',
label: t('Sign out'),
onClick: async () => {
await api.auth.signOut();
navigate(`/signin?redirect=${encodeURIComponent(redirectUrl)}`);
}, },
}, editProfile,
]; changePassword,
{
key: 'divider_2',
type: 'divider',
},
switchRole,
{
key: 'divider_3',
type: 'divider',
},
...controlApp,
{
key: 'signout',
label: t('Sign out'),
onClick: async () => {
await api.auth.signOut();
navigate(`/signin?redirect=${encodeURIComponent(redirectUrl)}`);
},
},
];
items.forEach((item) => { items.forEach((item) => {
if (item) { if (item) {
addMenuItem(item); addMenuItem(item);
}
});
if (languageSettings) {
addMenuItem(languageSettings, { before: 'divider_3' });
} }
}); }, [
addMenuItem,
api.auth,
appVersion,
changePassword,
controlApp,
editProfile,
languageSettings,
navigate,
redirectUrl,
switchRole,
t,
]);
return <Menu items={getMenuItems()} />; return <Menu items={getMenuItems()} />;
}; };

View File

@ -2,7 +2,19 @@ import { error } from '@nocobase/utils/client';
import { ItemType } from 'antd/es/menu/hooks/useItems'; import { ItemType } from 'antd/es/menu/hooks/useItems';
import React, { createContext, useCallback, useContext, useRef } from 'react'; import React, { createContext, useCallback, useContext, useRef } from 'react';
type menuItemsKey = 'version' | 'profile' | 'password' | 'role' | 'language' | 'cache' | 'reboot' | 'signout'; type menuItemsKey =
| 'version'
| 'profile'
| 'password'
| 'role'
| 'language'
| 'cache'
| 'reboot'
| 'signout'
| 'divider_1'
| 'divider_2'
| 'divider_3'
| 'divider_4';
interface OptionsOfAddMenuItem { interface OptionsOfAddMenuItem {
before?: menuItemsKey; before?: menuItemsKey;

View File

@ -13,8 +13,7 @@ export function useUpdateThemeSettings() {
return; return;
} }
try { try {
await api.resource('users').update({ await api.resource('users').updateProfile({
filterByTk: currentUser.data.data.id,
values: { values: {
systemSettings: { systemSettings: {
...currentUser.data.data.systemSettings, ...currentUser.data.data.systemSettings,

View File

@ -43,8 +43,8 @@ const CustomThemeProvider = React.memo((props) => {
useEffect(() => { useEffect(() => {
// 在页面右上角中添加一个 Theme 菜单项 // 在页面右上角中添加一个 Theme 菜单项
addMenuItem(themeItem, { after: 'role' }); addMenuItem(themeItem, { before: 'divider_3' });
}, [themeItem]); }, [addMenuItem, themeItem]);
const settings = useMemo(() => { const settings = useMemo(() => {
return { return {