From 9107e86cf435e2f27886854634e06e5d7ca36a64 Mon Sep 17 00:00:00 2001 From: Janry Date: Mon, 11 Jul 2022 11:46:46 +0800 Subject: [PATCH] fix(antd/next): fix array components lose reactive (#3266) --- packages/antd/src/array-cards/index.tsx | 2 +- packages/antd/src/array-collapse/index.tsx | 5 ++++- packages/antd/src/array-items/index.tsx | 2 +- packages/antd/src/array-table/index.tsx | 8 ++++---- packages/next/src/array-cards/index.tsx | 2 +- packages/next/src/array-collapse/index.tsx | 2 +- packages/next/src/array-items/index.tsx | 2 +- packages/next/src/array-table/index.tsx | 8 ++++---- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/antd/src/array-cards/index.tsx b/packages/antd/src/array-cards/index.tsx index 0ac97885c3e..a926a211110 100644 --- a/packages/antd/src/array-cards/index.tsx +++ b/packages/antd/src/array-cards/index.tsx @@ -106,7 +106,7 @@ export const ArrayCards: ComposedArrayCards = observer((props) => { dataSource[index]} + record={() => field.value?.[index]} > dataSource[index]}> + field.value?.[index]} + > { dataSource[index]} + record={() => field.value?.[index]} >
diff --git a/packages/antd/src/array-table/index.tsx b/packages/antd/src/array-table/index.tsx index a44486254cf..ff6283cf5eb 100644 --- a/packages/antd/src/array-table/index.tsx +++ b/packages/antd/src/array-table/index.tsx @@ -122,7 +122,7 @@ const useArrayTableSources = () => { } const useArrayTableColumns = ( - dataSource: any[], + field: ArrayField, sources: ObservableColumnSource[] ): TableProps['columns'] => { return sources.reduce((buf, { name, columnProps, schema, display }, key) => { @@ -133,9 +133,9 @@ const useArrayTableColumns = ( key, dataIndex: name, render: (value: any, record: any) => { - const index = dataSource.indexOf(record) + const index = field?.value?.indexOf(record) const children = ( - dataSource[index]}> + field?.value?.[index]}> ) @@ -295,7 +295,7 @@ export const ArrayTable: ComposedArrayTable = observer( const prefixCls = usePrefixCls('formily-array-table') const dataSource = Array.isArray(field.value) ? field.value.slice() : [] const sources = useArrayTableSources() - const columns = useArrayTableColumns(dataSource, sources) + const columns = useArrayTableColumns(field, sources) const pagination = isBool(props.pagination) ? {} : props.pagination const addition = useAddition() const defaultRowKey = (record: any) => { diff --git a/packages/next/src/array-cards/index.tsx b/packages/next/src/array-cards/index.tsx index 16cb5af9c57..ac1932f6b8c 100644 --- a/packages/next/src/array-cards/index.tsx +++ b/packages/next/src/array-cards/index.tsx @@ -159,7 +159,7 @@ export const ArrayCards: ComposedArrayCards = observer((props) => { dataSource[index]} + record={() => field.value?.[index]} > dataSource[index]} + record={() => field.value?.[index]} > {content} diff --git a/packages/next/src/array-items/index.tsx b/packages/next/src/array-items/index.tsx index b730927b740..adb7621a020 100644 --- a/packages/next/src/array-items/index.tsx +++ b/packages/next/src/array-items/index.tsx @@ -99,7 +99,7 @@ export const ArrayItems: ComposedArrayItems = observer((props) => { dataSource[index]} + record={() => field.value?.[index]} >
diff --git a/packages/next/src/array-table/index.tsx b/packages/next/src/array-table/index.tsx index b52bb2a66aa..58d78589e60 100644 --- a/packages/next/src/array-table/index.tsx +++ b/packages/next/src/array-table/index.tsx @@ -120,7 +120,7 @@ const useArrayTableSources = () => { } const useArrayTableColumns = ( - dataSource: any[], + field: ArrayField, sources: ObservableColumnSource[] ): TableProps['columns'] => { return sources.reduce((buf, { name, columnProps, schema, display }, key) => { @@ -131,12 +131,12 @@ const useArrayTableColumns = ( key, dataIndex: name, cell: (value: any, _: number, record: any) => { - const index = dataSource.indexOf(record) + const index = field.value?.indexOf(record) const children = ( dataSource[index]} + record={() => field.value?.[index]} > @@ -299,7 +299,7 @@ export const ArrayTable: ComposedArrayTable = observer( const prefixCls = usePrefixCls('formily-array-table') const dataSource = Array.isArray(field.value) ? field.value.slice() : [] const sources = useArrayTableSources() - const columns = useArrayTableColumns(dataSource, sources) + const columns = useArrayTableColumns(field, sources) const pagination = isBool(props.pagination) ? {} : props.pagination const addition = useAddition()