From c129889df6971e5d02e4456a1901bb6d9ceabf1c Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Tue, 19 Dec 2023 07:50:53 +0800 Subject: [PATCH] fix: fix switch role and input style (#3226) * fix: fix switch role and input style * refactor: remove useless code --- .../client/src/common/SelectWithTitle.tsx | 44 +++++++++++ packages/core/client/src/common/index.ts | 1 + packages/core/client/src/index.ts | 5 +- .../user-center/__e2e__/settings.test.ts | 9 +++ .../items/DataBlockInitializer.tsx | 4 +- .../src/schema-settings/SchemaSettings.tsx | 42 +---------- .../core/client/src/user/ChangePassword.tsx | 1 - packages/core/client/src/user/CurrentUser.tsx | 3 - packages/core/client/src/user/EditProfile.tsx | 3 +- .../core/client/src/user/LanguageSettings.tsx | 1 - packages/core/client/src/user/SwitchRole.tsx | 74 ++++++------------- 11 files changed, 83 insertions(+), 104 deletions(-) create mode 100644 packages/core/client/src/common/SelectWithTitle.tsx create mode 100644 packages/core/client/src/common/index.ts create mode 100644 packages/core/client/src/modules/user-center/__e2e__/settings.test.ts diff --git a/packages/core/client/src/common/SelectWithTitle.tsx b/packages/core/client/src/common/SelectWithTitle.tsx new file mode 100644 index 0000000000..9e515d1aac --- /dev/null +++ b/packages/core/client/src/common/SelectWithTitle.tsx @@ -0,0 +1,44 @@ +import { Select } from 'antd'; +import React, { useRef, useState } from 'react'; + +export interface SelectWithTitleProps { + title?: any; + defaultValue?: any; + options?: any; + fieldNames?: any; + onChange?: (...args: any[]) => void; +} + +export function SelectWithTitle({ title, defaultValue, onChange, options, fieldNames }: SelectWithTitleProps) { + const [open, setOpen] = useState(false); + const timerRef = useRef(null); + return ( +
{ + e.stopPropagation(); + setOpen((v) => !v); + }} + onMouseLeave={() => { + timerRef.current = setTimeout(() => { + setOpen(false); + }, 200); + }} + > + {title} + { return fieldSchema?.['x-component-props']?.['pattern-disable'] == true; }; -interface SelectWithTitleProps { - title?: any; - defaultValue?: any; - options?: any; - onChange?: (...args: any[]) => void; -} -export function SelectWithTitle({ title, defaultValue, onChange, options }: SelectWithTitleProps) { - const [open, setOpen] = useState(false); - const timerRef = useRef(null); - return ( -
{ - e.stopPropagation(); - setOpen((v) => !v); - }} - onMouseLeave={() => { - timerRef.current = setTimeout(() => { - setOpen(false); - }, 200); - }} - > - {title} - { - api.auth.setRole(roleName); - await api.resource('users').setDefaultRole({ values: { roleName } }); - location.reload(); - window.location.reload(); - }} - onMouseEnter={() => { - clearTimeout(timerRef.current); - }} - /> -
- ); -}