Skip to content

Commit

Permalink
fix(antd/next): fix array components lose reactive (#3266)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jul 11, 2022
1 parent 57510b4 commit 9107e86
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/antd/src/array-cards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const ArrayCards: ComposedArrayCards = observer((props) => {
<ArrayBase.Item
key={index}
index={index}
record={() => dataSource[index]}
record={() => field.value?.[index]}
>
<Card
{...props}
Expand Down
5 changes: 4 additions & 1 deletion packages/antd/src/array-collapse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
address: `${path}.**`,
})
return (
<ArrayBase.Item index={index} record={() => dataSource[index]}>
<ArrayBase.Item
index={index}
record={() => field.value?.[index]}
>
<RecursionField
schema={items}
name={index}
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/src/array-items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const ArrayItems: ComposedArrayItems = observer((props) => {
<ArrayBase.Item
key={index}
index={index}
record={() => dataSource[index]}
record={() => field.value?.[index]}
>
<SortableItem key={`item-${index}`} index={index}>
<div className={`${prefixCls}-item-inner`}>
Expand Down
8 changes: 4 additions & 4 deletions packages/antd/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const useArrayTableSources = () => {
}

const useArrayTableColumns = (
dataSource: any[],
field: ArrayField,
sources: ObservableColumnSource[]
): TableProps<any>['columns'] => {
return sources.reduce((buf, { name, columnProps, schema, display }, key) => {
Expand All @@ -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 = (
<ArrayBase.Item index={index} record={() => dataSource[index]}>
<ArrayBase.Item index={index} record={() => field?.value?.[index]}>
<RecursionField schema={schema} name={index} onlyRenderProperties />
</ArrayBase.Item>
)
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/array-cards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const ArrayCards: ComposedArrayCards = observer((props) => {
<ArrayBase.Item
key={index}
index={index}
record={() => dataSource[index]}
record={() => field.value?.[index]}
>
<Card
contentHeight="auto"
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/array-collapse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
<ArrayBase.Item
index={index}
key={index}
record={() => dataSource[index]}
record={() => field.value?.[index]}
>
{content}
</ArrayBase.Item>
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/array-items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const ArrayItems: ComposedArrayItems = observer((props) => {
<ArrayBase.Item
key={index}
index={index}
record={() => dataSource[index]}
record={() => field.value?.[index]}
>
<SortableItem key={`item-${index}`} index={index}>
<div className={`${prefixCls}-item-inner`}>
Expand Down
8 changes: 4 additions & 4 deletions packages/next/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 = (
<ArrayBase.Item
key={index}
index={index}
record={() => dataSource[index]}
record={() => field.value?.[index]}
>
<RecursionField schema={schema} name={index} onlyRenderProperties />
</ArrayBase.Item>
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 9107e86

Please sign in to comment.