From b7977b136707359298e03e51970cd9105be10a82 Mon Sep 17 00:00:00 2001 From: haitaoo Date: Wed, 29 Mar 2023 17:47:49 +0800 Subject: [PATCH 1/3] fix(admin): The page under the root path can get the correct width --- ui/src/pages/Admin/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/src/pages/Admin/index.tsx b/ui/src/pages/Admin/index.tsx index 8e59bbda..73cf1e6a 100644 --- a/ui/src/pages/Admin/index.tsx +++ b/ui/src/pages/Admin/index.tsx @@ -1,7 +1,7 @@ import { FC, useEffect } from 'react'; import { Container, Row, Col } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; -import { Outlet, useLocation } from 'react-router-dom'; +import { Outlet, useMatch } from 'react-router-dom'; import { cloneDeep } from 'lodash'; @@ -23,7 +23,9 @@ const g10Paths = [ ]; const Index: FC = () => { const { t } = useTranslation('translation', { keyPrefix: 'page_title' }); - const { pathname } = useLocation(); + const pathMatch = useMatch('/admin/:path'); + const curPath = pathMatch?.params.path || 'dashboard'; + const interfaceLang = interfaceStore((_) => _.interface.language); const { data: configurablePlugins, mutate: updateConfigurablePlugins } = useQueryPlugins({ @@ -78,7 +80,7 @@ const Index: FC = () => { - pathname.includes(v)) ? 10 : 6}> + curPath.includes(v)) ? 10 : 6}> From 9a6f7700621e4e449114b6c9029a466fced1c2f1 Mon Sep 17 00:00:00 2001 From: haitaoo Date: Mon, 10 Apr 2023 11:43:42 +0800 Subject: [PATCH 2/3] fix(SchemaForm): Make `setDefaultValueAsDomBehaviour` compatible with empty string values --- ui/src/components/SchemaForm/index.tsx | 17 ++++++----------- ui/src/pages/Admin/Smtp/index.tsx | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx index 6c245d24..ec768298 100644 --- a/ui/src/components/SchemaForm/index.tsx +++ b/ui/src/components/SchemaForm/index.tsx @@ -2,6 +2,7 @@ import { ForwardRefRenderFunction, forwardRef, useImperativeHandle, + useEffect, } from 'react'; import { Form, Button, Stack } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; @@ -155,16 +156,10 @@ const SchemaForm: ForwardRefRenderFunction = ( */ const setDefaultValueAsDomBehaviour = () => { keys.forEach((k) => { - const formVal = formData[k]?.value; + const fieldVal = formData[k]?.value; const metaProp = properties[k]; const uiCtrl = uiSchema[k]?.['ui:widget']; - if ( - !metaProp || - !uiCtrl || - formVal || - formVal === 0 || - formVal === false - ) { + if (!metaProp || !uiCtrl || fieldVal !== undefined) { return; } if (uiCtrl === 'select' && metaProp.enum?.[0] !== undefined) { @@ -176,7 +171,9 @@ const SchemaForm: ForwardRefRenderFunction = ( } }); }; - setDefaultValueAsDomBehaviour(); + useEffect(() => { + setDefaultValueAsDomBehaviour(); + }, [formData]); const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target; @@ -348,7 +345,6 @@ const SchemaForm: ForwardRefRenderFunction = ( useImperativeHandle(ref, () => ({ validator, })); - console.log('uiSchema: ', uiSchema); return (
{keys.map((key) => { @@ -577,7 +573,6 @@ export const initFormData = (schema: JSONSchema): Type.FormDataType => { Object.keys(schema.properties).forEach((key) => { const prop = schema.properties[key]; const defaultVal = prop?.default; - formData[key] = { value: defaultVal, isInvalid: false, diff --git a/ui/src/pages/Admin/Smtp/index.tsx b/ui/src/pages/Admin/Smtp/index.tsx index 3a625157..9750fa8f 100644 --- a/ui/src/pages/Admin/Smtp/index.tsx +++ b/ui/src/pages/Admin/Smtp/index.tsx @@ -33,7 +33,7 @@ const Smtp: FC = () => { description: t('smtp_host.text'), }, encryption: { - type: 'boolean', + type: 'string', title: t('encryption.label'), description: t('encryption.text'), enum: ['SSL', ''], From b4870d066c8fa9daf19c9b46d26964b336c68ead Mon Sep 17 00:00:00 2001 From: haitaoo Date: Mon, 10 Apr 2023 15:59:21 +0800 Subject: [PATCH 3/3] fix(admin/smtp): Make the smtp_authentication field value more accurate --- ui/src/pages/Admin/Smtp/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/pages/Admin/Smtp/index.tsx b/ui/src/pages/Admin/Smtp/index.tsx index 9750fa8f..135862ae 100644 --- a/ui/src/pages/Admin/Smtp/index.tsx +++ b/ui/src/pages/Admin/Smtp/index.tsx @@ -179,7 +179,7 @@ const Smtp: FC = () => { }, [setting]); useEffect(() => { - if (formData.smtp_authentication.value === '') { + if (!/true|false/.test(formData.smtp_authentication.value)) { return; } if (formData.smtp_authentication.value) {