Skip to content
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

👑 [需求]ProFormDependency支持跨Form,在FormListContext添加rootName字段? #8938

Closed
hans000 opened this issue Dec 23, 2024 · 1 comment

Comments

@hans000
Copy link
Contributor

hans000 commented Dec 23, 2024

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🔩 所属模块或组件

ProFormDependency, FormListContext

🥰 需求描述

让ProFormDependency支持跨Form组件,主要是在FormListContext中增加一个rootPath之类的字段,让Dependency可以获取到外部Form的path

⛰ 功能需求适用场景

自定义组件中使用到了form form.list,并且为了更好的符合pro-components的规范,想和ProFormList类似只传需要的业务字段

例:ProFormRuleTree的内部状态是通过一个Form管理的,这导致Dependency和Form.Item取到的name是一样的,但是Form.Item需要相对内部的Form,Dependency是需要相对外部的Form(这是由于Dependency的现有代码逻辑决定的,因此想加一个字段做判断)

ProFormRuleTree的部分伪代码,内部通过FormListContext来修改了listName,可以避免用户侧拼接props.path, index

<Form components={false}>
    {...}
<Form>

<RuleItem>
  <FormListContext.Provider
    value={{
      name: [index],
+     rootPath,
+     listName: [...props.path, index],
-      listName: [...rootPath, ...props.path, index],
    }}
  >
    {children}
  </FormListContext.Provider>
</RuleItem>

业务代码

<ProForm> // ---> outter form
  <ProFormRuleTree // ---> inner form
    name={'ruleTree'}
  >
    <Space>
      <ProFormText noStyle name={'name'} />
      <ProFormDependency name={['name']}>
        {
          (record) => {
            console.log(record);
            return <Tag>{record.name}</Tag>;
          }
        }
      </ProFormDependency>
    </Space>
  </ProFormRuleTree>
<ProForm>

🧐 解决方案

FormListContext添加一个字段,比如rootName。如果字段存在则优先把rootName拼接上

// https://github.com/hans000/pro-components/blob/master/packages/form/src/components/Dependency/index.tsx#L83

- const itemName = flattenNames[i]
+ const itemName = formListField.rootName ? [...formListField.rootName, flattenNames[i]] : flattenNames[i];

🚑 其他信息

image
@hans000
Copy link
Contributor Author

hans000 commented Dec 25, 2024

暂时不需要了

@hans000 hans000 closed this as completed Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant