-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: update form handling and configuration structure #227
base: 0.2.x-dev
Are you sure you want to change the base?
Conversation
187e5b3
to
4a34b5a
Compare
* @param errorBody 错误信息体 | ||
* @returns 格式化后的错误信息 | ||
*/ | ||
formatError?: (errorBody: unknown) => string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorBody 有可能给出实际的类型定义吗?
export type WithId<T> = T & { id: string }; | ||
|
||
export type DefaultFormConfig<Model extends ResourceModel = ResourceModel> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
叫Default感觉和下面的Common不太好区分,他们关系是什么?
@@ -230,6 +153,40 @@ export function FormModal(props: FormModalProps) { | |||
} | |||
return ''; | |||
}, [action, config.formConfig]); | |||
const formEle = useMemo(() => { | |||
if (config.formConfig && (config.formConfig?.formType === FormType.FORM || 'fields' in config.formConfig)) { | |||
return <RefineFormContainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
两种表单的参数共同的部分可以提取出来,维护起来更清晰一点
- Refactored form configuration to use `FormContainerType` and `FormType` enums for better clarity. - Introduced `RefineFormContainer` and `YamlFormContainer` components to streamline form rendering logic. - Updated various components to utilize the new form configuration structure, ensuring consistent form behavior across the application. - Enhanced type safety by integrating `CommonFormConfig` and `DefaultFormConfig` into resource configurations. - Adjusted form handling in `useRefineForm` and `useFieldsConfig` to accommodate the new structure. - Updated resource pages to pass the correct configuration to forms, ensuring proper initialization and rendering.
4a34b5a
to
0e7146b
Compare
背景
之前 formConfig 中把 RefineForm 和 YAMLForm 的配置字段混杂在一起,不容易分清哪些字段分别是针对哪种表单类型生效的。
解决方案
表单配置调整
现在在 formConfig 需明确声明表单类型,然后根据表单类型的不同填写不同的配置。
FormModal 调整
现在将表单的渲染逻辑拆分到 RefineFormContainer 和 YamlFormContainer 内部,并将对应的 formConfig 通过参数传入,这样在 RefineFormContainer 和 YamlFormContainer 不用先判断表单类型再获取配置字段。
config 改为通过参数传入
由于 FormModal 支持传入
resource
来定义当前是哪个资源的表单,用来在当前资源页面打开其他资源的表单,所以 FormModal 内部使用的 config 都改为通过参数传入,而不是通过useContext
和useResource
进行获取。