fix: record picker cannot select from different pages (#623)
related issue #563
This commit is contained in:
parent
c51c6c097f
commit
a521231a25
@ -1,4 +1,5 @@
|
|||||||
import { RecursionField, useFieldSchema } from '@formily/react';
|
import { ArrayField } from '@formily/core';
|
||||||
|
import { RecursionField, useField, useFieldSchema } from '@formily/react';
|
||||||
import { Select } from 'antd';
|
import { Select } from 'antd';
|
||||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
||||||
import { useTableSelectorProps as useTsp } from '../../../block-provider/TableSelectorProvider';
|
import { useTableSelectorProps as useTsp } from '../../../block-provider/TableSelectorProvider';
|
||||||
@ -7,23 +8,36 @@ import { FormProvider, SchemaComponentOptions } from '../../core';
|
|||||||
import { useCompile } from '../../hooks';
|
import { useCompile } from '../../hooks';
|
||||||
import { ActionContext, useActionContext } from '../action';
|
import { ActionContext, useActionContext } from '../action';
|
||||||
import { useFieldNames } from './useFieldNames';
|
import { useFieldNames } from './useFieldNames';
|
||||||
|
import { differenceBy, unionBy } from 'lodash';
|
||||||
|
|
||||||
const RecordPickerContext = createContext(null);
|
const RecordPickerContext = createContext(null);
|
||||||
|
|
||||||
const useTableSelectorProps = () => {
|
const useTableSelectorProps = () => {
|
||||||
const { multiple, value, setSelectedRows, selectedRows } = useContext(RecordPickerContext);
|
const field = useField<ArrayField>();
|
||||||
|
const { multiple, value, setSelectedRows, selectedRows: rcSelectRows } = useContext(RecordPickerContext);
|
||||||
const { onRowSelectionChange, rowKey, ...others } = useTsp();
|
const { onRowSelectionChange, rowKey, ...others } = useTsp();
|
||||||
|
console.log('useTableSelectorProps', field.value, value);
|
||||||
return {
|
return {
|
||||||
...others,
|
...others,
|
||||||
rowKey,
|
rowKey,
|
||||||
rowSelection: {
|
rowSelection: {
|
||||||
type: multiple ? 'checkbox' : 'radio',
|
type: multiple ? 'checkbox' : 'radio',
|
||||||
defaultSelectedRowKeys: selectedRows?.map((item) => item[rowKey||'id']),
|
// defaultSelectedRowKeys: selectedRows?.map((item) => item[rowKey||'id']),
|
||||||
selectedRowKeys: selectedRows?.map((item) => item[rowKey||'id']),
|
selectedRowKeys: rcSelectRows?.map((item) => item[rowKey||'id']),
|
||||||
},
|
},
|
||||||
onRowSelectionChange(selectedRowKeys, selectedRows) {
|
onRowSelectionChange(selectedRowKeys, selectedRows) {
|
||||||
onRowSelectionChange?.(selectedRowKeys, selectedRows);
|
if (multiple) {
|
||||||
setSelectedRows?.(selectedRows);
|
const scopeRows = field.value || [];
|
||||||
|
const allSelectedRows = rcSelectRows || [];
|
||||||
|
const otherRows = differenceBy(allSelectedRows, scopeRows, rowKey||'id');
|
||||||
|
const unionSelectedRows = unionBy(otherRows, selectedRows, rowKey||'id');
|
||||||
|
const unionSelectedRowKeys = unionSelectedRows.map((item) => item[rowKey||'id'])
|
||||||
|
setSelectedRows?.(unionSelectedRows);
|
||||||
|
onRowSelectionChange?.(unionSelectedRowKeys, unionSelectedRows);
|
||||||
|
} else {
|
||||||
|
setSelectedRows?.(selectedRows);
|
||||||
|
onRowSelectionChange?.(selectedRowKeys, selectedRows);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -78,8 +92,6 @@ export const InputRecordPicker: React.FC<any> = (props) => {
|
|||||||
}
|
}
|
||||||
}, [value])
|
}, [value])
|
||||||
|
|
||||||
useEffect(() => {})
|
|
||||||
|
|
||||||
const getValue = () => {
|
const getValue = () => {
|
||||||
if (multiple == null) return null;
|
if (multiple == null) return null;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user