import React, { useState } from 'react' import { connect } from '@formily/react-schema-renderer' import moment from 'moment' import { Select, Table } from 'antd' import get from 'lodash/get'; import { mapStyledProps, mapTextComponent, compose, isStr, isArr } from '../shared' import { useRequest } from 'umi'; import api from '@/api-client'; import { Spin } from '@nocobase/client' import { fields2columns, components } from '@/components/views/SortableTable' function DraggableTableComponent(props) { const { mode = 'showInDetail', value, onChange, disabled, rowKey = 'id', fields = [], resourceName, associatedKey, filter, labelField, valueField = 'id', objectValue, placeholder } = props; const { data = [], loading = true, mutate } = useRequest(() => { return api.resource(resourceName).list({ associatedKey, filter, perPage: -1, }); }, { refreshDeps: [resourceName, associatedKey] }); const [selectedRowKeys, setSelectedRowKeys] = useState([]); const onTableChange = (selectedRowKeys: React.ReactText[]) => { onChange(selectedRowKeys); } const tableProps: any = {}; tableProps.rowSelection = { selectedRowKeys: Array.isArray(value) ? value : data.map(item => item[rowKey]), onChange: onTableChange, } const dataSource = data.filter(item => { return get(item, ['component', mode]) }); // const sortIds = get(value, 'sort')||[]; // let values = []; // sortIds.forEach(id => { // const item = dataSource.find(item => item[rowKey] === id); // if (item) { // values.push(item); // } // }); // if (values.length === 0) { // values = dataSource; // } return ( <>