From 5b9695e720ccf29629c6ce85f1a3809468d427f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Wed, 8 Nov 2023 09:17:40 +0800 Subject: [PATCH] fix: select item can not be selected in connecting data blocks (#2993) --- .../src/schema-settings/SchemaSettings.tsx | 15 ++-- .../core/client/src/user/LanguageSettings.tsx | 73 +++++++------------ .../src/client/hooks/useThemeSettings.tsx | 29 +++----- 3 files changed, 42 insertions(+), 75 deletions(-) diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 1aee6e5a8..5ed5efb1f 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -725,7 +725,6 @@ SchemaSettings.ConnectDataBlocks = function ConnectDataBlocks(props: { }); dn.refresh(); }} - onClick={(e) => e.stopPropagation()} onMouseEnter={onHover} onMouseLeave={onLeave} /> @@ -750,11 +749,11 @@ SchemaSettings.ConnectDataBlocks = function ConnectDataBlocks(props: { }; SchemaSettings.SelectItem = function SelectItem(props) { - const { title, name, options, value, onChange, onClick, ...others } = props; + const { title, name, options, value, onChange, ...others } = props; return ( - + ); }; @@ -1963,20 +1962,18 @@ export const isPatternDisabled = (fieldSchema: Schema) => { return fieldSchema?.['x-component-props']?.['pattern-disable'] == true; }; -function SelectWithTitle({ +export function SelectWithTitle({ name, title, defaultValue, onChange, options, - onClick, }: { name?: string; title?: any; defaultValue?: any; options?: any; onChange?: (...args: any[]) => void; - onClick?: (...args: any[]) => void; }) { const [open, setOpen] = useState(false); const timerRef = useRef(null); @@ -1986,7 +1983,10 @@ function SelectWithTitle({ role="button" aria-label={name || title} style={{ alignItems: 'center', display: 'flex', justifyContent: 'space-between' }} - onClick={() => setOpen((v) => !v)} + onClick={(e) => { + e.stopPropagation(); + setOpen((v) => !v); + }} onMouseLeave={() => { timerRef.current = setTimeout(() => { setOpen(false); @@ -2002,7 +2002,6 @@ function SelectWithTitle({ onChange={onChange} options={options} style={{ textAlign: 'right', minWidth: 100 }} - onClick={onClick} onMouseEnter={() => { clearTimeout(timerRef.current); }} diff --git a/packages/core/client/src/user/LanguageSettings.tsx b/packages/core/client/src/user/LanguageSettings.tsx index 9ed12c93b..a0f1dc8a9 100644 --- a/packages/core/client/src/user/LanguageSettings.tsx +++ b/packages/core/client/src/user/LanguageSettings.tsx @@ -1,66 +1,45 @@ -import { MenuProps, Select } from 'antd'; -import React, { useMemo, useState } from 'react'; +import { MenuProps } from 'antd'; +import React, { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; -import { useAPIClient, useSystemSettings } from '..'; +import { SelectWithTitle, useAPIClient, useSystemSettings } from '..'; import locale from '../locale'; export const useLanguageSettings = () => { const { t, i18n } = useTranslation(); - const [open, setOpen] = useState(false); const api = useAPIClient(); const { data } = useSystemSettings(); - const enabledLanguages: string[] = data?.data?.enabledLanguages || []; + const enabledLanguages: string[] = useMemo(() => data?.data?.enabledLanguages || [], [data?.data?.enabledLanguages]); const result = useMemo(() => { return { role: 'button', key: 'language', eventKey: 'LanguageSettings', - onClick: () => { - setOpen(true); - }, label: ( -
enabledLanguages.includes(lang)) + .map((lang) => { + return { + label: locale[lang].label, + value: lang, + }; + })} + defaultValue={i18n.language} + onChange={async (lang) => { + await api.resource('users').updateProfile({ + values: { + appLang: lang, + }, + }); + api.auth.setLocale(lang); + await i18n.changeLanguage(lang); + window.location.reload(); }} - > - {t('Language')}{' '} - { - updateUserThemeSettings(value); - }} - /> -
+ /> ); }