React 管理员导入按钮 referenceManyField?

React admin import button referenceManyField?

我想为我的 React 管理应用程序添加一个导入按钮。

此导入将创建与另一条记录相关的记录。例如,我有一份属于一家公司的合同清单。

我看到了这个回购:https://github.com/benwinding/react-admin-import-csv

我想知道是否有类似的 referenceManyField。

我找到了一个 hacky 解决方案,以防有人感兴趣。

我没有使用 ReferenceManyField,而是在 Show 组件中使用了 List

为了能够做到这一点,我必须覆盖列表的属性以指定我想要引用的资源。

我还必须将显示项目 ID 作为列表组件的道具传递,并按 ID 过滤列表。

let companyId = '';

const ListActions = (props) => {
  const { className } = props;
  return (
    <TopToolbar className={className}>
       <ImportButton {...props} />
    </TopToolbar>
  );
};

export const ContractRow = ({ contractCompanyId }) => {
  companyId = contractCompanyId;
  const fakeProps: ListProps = {
    basePath: '/contracts',
    hasCreate: false,
    hasEdit: false,
    hasList: true,
    hasShow: false,
    location: { pathname: '/', search: '', hash: '', state: undefined },
    match: { path: '/', url: '/', isExact: true, params: {} },
    options: {},
    permissions: null,
    resource: 'contracts',
  };
 
  return (
    <List
      {...fakeProps}
      filter={{ _company_id: contractCompanyId }}
      actions={<ListActions />}
    >
      <Datagrid className={classes.insideTable}>
        <TextField source="name" />
      </Datagrid>
    </List>
  );
};