Skip to content

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.

refactor(ui): Modify the input type name

robin4f0ec66710d2
diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx
index 1b4c4e3d..658689a8 100644
--- a/ui/src/components/SchemaForm/index.tsx
+++ b/ui/src/components/SchemaForm/index.tsx
@@ -29,7 +29,7 @@ export interface JSONSchema {
};
}
-export interface UIOptions {
+export interface BaseUIOptions {
empty?: string;
className?: string | string[];
validator?: (
@@ -37,9 +37,9 @@ export interface UIOptions {
formData?,
) => Promise<string | true | void> | true | string;
}
-export interface InputOptions extends UIOptions {
+export interface InputOptions extends BaseUIOptions {
placeholder?: string;
- type?:
+ inputType?:
| 'color'
| 'date'
| 'datetime-local'
@@ -55,27 +55,37 @@ export interface InputOptions extends UIOptions {
| 'url'
| 'week';
}
-export interface SelectOptions extends UIOptions {}
-export interface UploadOptions extends UIOptions {
+export interface SelectOptions extends BaseUIOptions {}
+export interface UploadOptions extends BaseUIOptions {
acceptType?: string;
imageType?: Type.UploadType;
}
-export interface SwitchOptions extends UIOptions {}
+export interface SwitchOptions extends BaseUIOptions {}
-export interface TimezoneOptions extends UIOptions {
+export interface TimezoneOptions extends BaseUIOptions {
placeholder?: string;
}
-export interface CheckboxOptions extends UIOptions {}
+export interface CheckboxOptions extends BaseUIOptions {}
-export interface RadioOptions extends UIOptions {}
+export interface RadioOptions extends BaseUIOptions {}
-export interface TextareaOptions extends UIOptions {
+export interface TextareaOptions extends BaseUIOptions {
placeholder?: string;
rows?: number;
}
+export type UIOptions =
+ | InputOptions
+ | SelectOptions
+ | UploadOptions
+ | SwitchOptions
+ | TimezoneOptions
+ | CheckboxOptions
+ | RadioOptions
+ | TextareaOptions;
+
export type UIWidget =
| 'textarea'
| 'input'
@@ -88,15 +98,7 @@ export type UIWidget =
export interface UISchema {
[key: string]: {
'ui:widget'?: UIWidget;
- 'ui:options'?:
- | InputOptions
- | SelectOptions
- | UploadOptions
- | SwitchOptions
- | TimezoneOptions
- | CheckboxOptions
- | RadioOptions
- | TextareaOptions;
+ 'ui:options'?: UIOptions;
};
}
@@ -515,10 +517,10 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
<Form.Control
name={key}
placeholder={options?.placeholder || ''}
- type={options?.type || 'text'}
+ type={options?.inputType || 'text'}
value={formData[key]?.value || ''}
onChange={handleInputChange}
- style={options?.type === 'color' ? { width: '6rem' } : {}}
+ style={options?.inputType === 'color' ? { width: '6rem' } : {}}
isInvalid={formData[key].isInvalid}
/>
<Form.Control.Feedback type="invalid">
diff --git a/ui/src/hooks/useChangePasswordModal/index.tsx b/ui/src/hooks/useChangePasswordModal/index.tsx
index 6c8b6d90..f04ac535 100644
--- a/ui/src/hooks/useChangePasswordModal/index.tsx
+++ b/ui/src/hooks/useChangePasswordModal/index.tsx
@@ -37,7 +37,7 @@ const useChangePasswordModal = (props: IProps = {}) => {
const uiSchema: UISchema = {
password: {
'ui:options': {
- type: 'password',
+ inputType: 'password',
validator: (value) => {
const MIN_LENGTH = 8;
const MAX_LENGTH = 32;
diff --git a/ui/src/hooks/useUserModal/index.tsx b/ui/src/hooks/useUserModal/index.tsx
index 8e7984a2..1f20ef15 100644
--- a/ui/src/hooks/useUserModal/index.tsx
+++ b/ui/src/hooks/useUserModal/index.tsx
@@ -57,7 +57,7 @@ const useAddUserModal = (props: IProps = {}) => {
},
email: {
'ui:options': {
- type: 'email',
+ inputType: 'email',
validator: (value) => {
if (value && !pattern.email.test(value)) {
return t('form.fields.email.msg');
@@ -68,7 +68,7 @@ const useAddUserModal = (props: IProps = {}) => {
},
password: {
'ui:options': {
- type: 'password',
+ inputType: 'password',
validator: (value) => {
const MIN_LENGTH = 8;
const MAX_LENGTH = 32;
diff --git a/ui/src/pages/Admin/General/index.tsx b/ui/src/pages/Admin/General/index.tsx
index 2b748fe2..4b3342a0 100644
--- a/ui/src/pages/Admin/General/index.tsx
+++ b/ui/src/pages/Admin/General/index.tsx
@@ -51,7 +51,7 @@ const General: FC = () => {
const uiSchema: UISchema = {
site_url: {
'ui:options': {
- type: 'url',
+ inputType: 'url',
validator: (value) => {
let url: URL | undefined;
try {
@@ -75,7 +75,7 @@ const General: FC = () => {
},
contact_email: {
'ui:options': {
- type: 'email',
+ inputType: 'email',
validator: (value) => {
if (!Pattern.email.test(value)) {
return t('contact_email.validate');
diff --git a/ui/src/pages/Admin/Plugins/Config/index.tsx b/ui/src/pages/Admin/Plugins/Config/index.tsx
index ff4ff3cd..32f223af 100644
--- a/ui/src/pages/Admin/Plugins/Config/index.tsx
+++ b/ui/src/pages/Admin/Plugins/Config/index.tsx
@@ -9,6 +9,7 @@ import { useToast } from '@/hooks';
import type * as Types from '@/common/interface';
import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
import { useQueryPluginConfig, updatePluginConfig } from '@/services';
+import { InputOptions } from '@/components/SchemaForm';
const Config = () => {
const { t } = useTranslation('translation');
@@ -44,6 +45,11 @@ const Config = () => {
}
if (item.ui_options) {
+ if ((item.ui_options as InputOptions & { input_type })?.input_type) {
+ (item.ui_options as InputOptions).inputType = (
+ item.ui_options as InputOptions & { input_type }
+ ).input_type;
+ }
uiSchema[item.name] = {
'ui:options': item.ui_options,
};
diff --git a/ui/src/pages/Admin/Smtp/index.tsx b/ui/src/pages/Admin/Smtp/index.tsx
index 3a678889..c39591c5 100644
--- a/ui/src/pages/Admin/Smtp/index.tsx
+++ b/ui/src/pages/Admin/Smtp/index.tsx
@@ -69,7 +69,7 @@ const Smtp: FC = () => {
const uiSchema: UISchema = {
from_email: {
'ui:options': {
- type: 'email',
+ inputType: 'email',
},
},
encryption: {
@@ -89,7 +89,7 @@ const Smtp: FC = () => {
},
smtp_password: {
'ui:options': {
- type: 'password',
+ inputType: 'password',
validator: (value: string, formData) => {
if (formData.smtp_authentication.value) {
if (!value) {
@@ -105,7 +105,7 @@ const Smtp: FC = () => {
},
smtp_port: {
'ui:options': {
- type: 'number',
+ inputType: 'number',
validator: (value) => {
if (!/^[1-9][0-9]*$/.test(value) || Number(value) > 65535) {
return t('smtp_port.msg');
@@ -116,7 +116,7 @@ const Smtp: FC = () => {
},
test_email_recipient: {
'ui:options': {
- type: 'email',
+ inputType: 'email',
validator: (value) => {
if (value && !pattern.email.test(value)) {
return t('test_email_recipient.msg');
diff --git a/ui/src/pages/Admin/Themes/index.tsx b/ui/src/pages/Admin/Themes/index.tsx
index 5c78bf3b..2be3e8e1 100644
--- a/ui/src/pages/Admin/Themes/index.tsx
+++ b/ui/src/pages/Admin/Themes/index.tsx
@@ -50,7 +50,7 @@ const Index: FC = () => {
},
primary_color: {
'ui:options': {
- type: 'color',
+ inputType: 'color',
},
},
};