A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(SchemaForm): Move the `label` field to the `switch` component configuration item, which is only used by this component
haitaoo41404070a70a
diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsxindex f811e81b..6c245d24 100644--- a/ui/src/components/SchemaForm/index.tsx+++ b/ui/src/components/SchemaForm/index.tsx@@ -20,7 +20,6 @@ export interface JSONSchema {[key: string]: {type: 'string' | 'boolean' | 'number';title: string;- label?: string;description?: string;enum?: Array<string | boolean | number>;enumNames?: string[];@@ -61,7 +60,9 @@ export interface UploadOptions extends BaseUIOptions {imageType?: Type.UploadType;}-export interface SwitchOptions extends BaseUIOptions {}+export interface SwitchOptions extends BaseUIOptions {+ label?: string;+}export interface TimezoneOptions extends BaseUIOptions {placeholder?: string;@@ -172,7 +173,6 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (isInvalid: false,value: metaProp.enum?.[0],};- console.log('formData[k]: ', k, formData[k]);}});};@@ -348,13 +348,13 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (useImperativeHandle(ref, () => ({validator,}));-+ console.log('uiSchema: ', uiSchema);return (<Form noValidate onSubmit={handleSubmit}>{keys.map((key) => {- const { title, description, label } = properties[key];- const { 'ui:widget': widget = 'input' } = uiSchema[key] || {};-+ const { title, description } = properties[key];+ const { 'ui:widget': widget = 'input', 'ui:options': uiOpt } =+ uiSchema[key] || {};if (widget === 'select') {return (<Form.Group@@ -435,7 +435,7 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (id={`switch-${title}`}name={key}type="switch"- label={label}+ label={(uiOpt as SwitchOptions)?.label}checked={formData[key]?.value || ''}feedback={formData[key]?.errorMsg}feedbackType="invalid"diff --git a/ui/src/pages/Admin/Login/index.tsx b/ui/src/pages/Admin/Login/index.tsxindex 4e3b93e2..33cf73de 100644--- a/ui/src/pages/Admin/Login/index.tsx+++ b/ui/src/pages/Admin/Login/index.tsx@@ -19,14 +19,12 @@ const Index: FC = () => {allow_new_registrations: {type: 'boolean',title: t('membership.title'),- label: t('membership.label'),description: t('membership.text'),default: false,},login_required: {type: 'boolean',title: t('private.title'),- label: t('private.label'),description: t('private.text'),default: false,},@@ -35,9 +33,15 @@ const Index: FC = () => {const uiSchema: UISchema = {allow_new_registrations: {'ui:widget': 'switch',+ 'ui:options': {+ label: t('membership.label'),+ },},login_required: {'ui:widget': 'switch',+ 'ui:options': {+ label: t('private.label'),+ },},};const [formData, setFormData] = useState(initFormData(schema));diff --git a/ui/src/pages/Admin/Smtp/index.tsx b/ui/src/pages/Admin/Smtp/index.tsxindex c39591c5..3a625157 100644--- a/ui/src/pages/Admin/Smtp/index.tsx+++ b/ui/src/pages/Admin/Smtp/index.tsx@@ -47,7 +47,6 @@ const Smtp: FC = () => {smtp_authentication: {type: 'boolean',title: t('smtp_authentication.title'),- label: t('smtp_authentication.label'),enum: [true, false],enumNames: [t('smtp_authentication.yes'), t('smtp_authentication.no')],},@@ -102,6 +101,9 @@ const Smtp: FC = () => {},smtp_authentication: {'ui:widget': 'switch',+ 'ui:options': {+ label: t('smtp_authentication.label'),+ },},smtp_port: {'ui:options': {diff --git a/ui/src/pages/Admin/Write/index.tsx b/ui/src/pages/Admin/Write/index.tsxindex 1df9788f..6020a4d8 100644--- a/ui/src/pages/Admin/Write/index.tsx+++ b/ui/src/pages/Admin/Write/index.tsx@@ -27,7 +27,6 @@ const Index: FC = () => {required_tag: {type: 'boolean',title: t('required_tag.title'),- label: t('required_tag.label'),description: t('required_tag.text'),},reserved_tags: {@@ -46,6 +45,9 @@ const Index: FC = () => {},required_tag: {'ui:widget': 'switch',+ 'ui:options': {+ label: t('required_tag.label'),+ },},reserved_tags: {'ui:widget': 'textarea',diff --git a/ui/src/pages/Users/Settings/Notification/index.tsx b/ui/src/pages/Users/Settings/Notification/index.tsxindex e970fd18..28869caf 100644--- a/ui/src/pages/Users/Settings/Notification/index.tsx+++ b/ui/src/pages/Users/Settings/Notification/index.tsx@@ -17,7 +17,6 @@ const Index = () => {notice_switch: {type: 'boolean',title: t('email.label'),- label: t('email.radio'),default: false,},},@@ -25,6 +24,9 @@ const Index = () => {const uiSchema: UISchema = {notice_switch: {'ui:widget': 'switch',+ 'ui:options': {+ label: t('email.radio'),+ },},};const [formData, setFormData] = useState<FormDataType>(initFormData(schema));