diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 1aee6e5a8f..5ed5efb1f4 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 9ed12c93b1..a0f1dc8a9c 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); - }} - /> -
+ /> ); }