如何更改删除确认对话框标题?

How to change the delete confirmation dialog title?

删除确认对话框显示资源名称和#id 作为标题。 如何将此标题更改为在设置了 undoable={false} 的编辑 object 中定义的标题?

对于批量删除确认对话框,它采用资源名称而不是资源标签,如何更改此行为?

DeleteButton / BulkDeleteButton 组件有 confirmTitle / confirmContent 属性,你可以在那里设置自己的标题和内容:

const MyActions = props => (
  <TopToolbar>
    <DeleteButton
      undoable={false}
      confirmTitle={'My Title'}  // 'resources.my_res.delete.title'
      confirmContent={'My Content'}
    />
  </TopToolbar>
)

const MyBulkActionButtons = props => (
  <>
    <BulkDeleteButton
      undoable={false}
      confirmTitle={'My Title'}
      confirmContent={'My Content'}
      {...props}
    />
  </>
)

<List actions={<MyActions />} bulkActionButtons={<MyBulkActionButtons />} />
<Edit actions={<MyActions />} />

这是一个自定义删除按钮,向您展示如何访问要删除的记录的数据以自定义对话框:

import React                    from 'react';
import { DeleteButton }         from 'react-admin';

const CustomDeleteButton = ({ type = 'Item', field, ...props }) => {
  const { record } = props;
  return (
    <DeleteButton
      confirmTitle={`Delete ${type}: ${field ? record[field] : 'this item'} ?`}
      confirmContent={'Are you sure you want to delete this item?'}
      {...props}
    />
  );
}

export default CustomDeleteButton;

以及对其的示例调用

<CustomDeleteButton basePath="/customers" undoable={false} type="Customer" field="cus_name" />

显然,您可以根据自己的需要对其进行定制,并扩展您从记录对象访问的信息 - 只需确保将所有道具传递给 DeleteButton!