如何自定义CRUD响应烤面包机消息[admin-on-rest]

时间:2017-07-25 09:00:42

标签: admin-on-rest

我想在CRUD响应烤面包机中添加服务器响应消息。例如,当我们进行更新时,我们会更新'元素更新'烤面包机消息而不是它我想显示一些动态(非静态)服务器响应消息。

2 个答案:

答案 0 :(得分:1)

目前仅支持错误消息。如果这非常重要,请打开功能请求,我们会考虑它。

答案 1 :(得分:1)

这是一个稍微冗长的方式。但绝对可能。

1)编写自定义的restWrapper或RestClient https://marmelab.com/admin-on-rest/RestClients.html

2)处理请求和响应,如下所示。

function handleRequestAndResponse(url, options={}, showAlert={}) {
  return fetchUtils.fetchJson(url, options)
    .then((response) => {
      const {headers, json} = response;
      //admin on rest needs the {data} key
      const data = {data: json}
      if (headers.get('x-total-count')) {
        data.total = parseInt(headers.get('x-total-count').split('/').pop(), 10)
      }
      // handle get_list responses
      if (!isNaN(parseInt(headers.get('x-total-count'), 10))) {
        return {data: json,
                total: parseInt(headers.get('x-total-count').split('/').pop(), 10)}
      } else {
        return data
      }
  })
}

3)您现在在代码中有一个位置可以拦截来自服务器的数据。在上面的代码中,您可以根据需要定义和拍摄包含数据的操作。创建一个reducer,它从您的操作中获取数据并填充您可以将其称为通知的状态的字段。

4)使用redux-saga select方法 How to get something from the state / store inside a redux-saga function?

您现在可以从商店访问通知数据,并根据您的心脏内容显示自定义烤面包机消息:)