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

fix(table): column配置不写key,使用request方法出现错误 #3816

Merged
merged 1 commit into from Oct 14, 2021

Conversation

gexin1
Copy link
Contributor

@gexin1 gexin1 commented Oct 11, 2021

使用request方法table渲染时会造成数据重复请求
使用request方法table渲染数据出现错误

@github-actions
Copy link

github-actions bot commented Oct 11, 2021

⚡️ Deploying PR Preview...

@gexin1
Copy link
Contributor Author

gexin1 commented Oct 11, 2021

这个功能还是挺常见的
希望在文档上给个note,避免开发者使用以前的版本出现问题

  const columns = [
    {
      // 需要添加key属性
      key:'type',
      title: '类型',
      dataIndex: 'type',
      valueType: 'select',
      param: {},
      request: async()=>[],
    },
  ];

@gexin1 gexin1 changed the title fix(compiler): column配置不写key,使用request方法出现错误 fix(table): column配置不写key,使用request方法出现错误 Oct 11, 2021
@chenshuai2144
Copy link
Contributor

这个改动有点没看懂,有相关的issue 吗?

@gexin1
Copy link
Contributor Author

gexin1 commented Oct 13, 2021

 {
      title: '类型',
      dataIndex: 'type',
      valueType: 'select',
      param: {},
      request: async()=>[],
}

如果我不写key这个属性

{
    proFieldProps: {
      emptyText: config.columnEmptyText,
      proFieldKey: columnProps?.key
        ? `table-field-${columnProps?.key || columnProps?.dataIndex?.toString()}`
        : undefined,
}

proFieldKey 为undefined

export const useFieldFetchData = (
  props: FieldSelectProps & {
    proFieldKey?: React.Key;
  },
): [boolean, SelectProps<any>['options'], (keyWord?: string) => void, () => void] => {
  const [keyWords, setKeyWords] = useState<string | undefined>(undefined);


  // 这里就没有key 就出出现问题


field select
  /** Key 是用来缓存请求的,如果不在是有问题 */
  const [cacheKey] = useState(() => {
    if (props.proFieldKey) {
      return props.proFieldKey.toString();
    }
    if (props.request) {
      testId += 1;
      return testId.toString();
    }
    return 'no-fetch';
  });

@gexin1
Copy link
Contributor Author

gexin1 commented Oct 13, 2021

如果没有解释清楚的话 我可以提供一个小的demo

@gexin1
Copy link
Contributor Author

gexin1 commented Oct 13, 2021

codesandbox demo
WX20211013-170847@2x

1 similar comment
@gexin1
Copy link
Contributor Author

gexin1 commented Oct 13, 2021

codesandbox demo
WX20211013-170847@2x

@chenshuai2144
Copy link
Contributor

了解了,判断的确是不健壮

@codecov
Copy link

codecov bot commented Oct 14, 2021

Codecov Report

Merging #3816 (929c0b1) into master (2e535dc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3816   +/-   ##
=======================================
  Coverage   98.98%   98.98%           
=======================================
  Files         179      179           
  Lines        5810     5816    +6     
  Branches     2085     2091    +6     
=======================================
+ Hits         5751     5757    +6     
  Misses         59       59           
Impacted Files Coverage Δ
packages/table/src/utils/cellRenderToFromItem.tsx 100.00% <100.00%> (ø)
packages/list/src/Item.tsx 98.63% <0.00%> (ø)
packages/table/src/components/ToolBar/index.tsx 100.00% <0.00%> (ø)
...kages/table/src/components/ColumnSetting/index.tsx 97.82% <0.00%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e535dc...929c0b1. Read the comment docs.

@chenshuai2144 chenshuai2144 merged commit a3b7f63 into ant-design:master Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants