josx / ra-data-feathers

A feathers rest client for react-admin
MIT License
157 stars 58 forks source link

Working with non-paginated feathers services #101

Closed roelnoort closed 5 years ago

roelnoort commented 5 years ago

Hi, when working with non-paginated feathers services I am getting the error "Cannot read property 'map' of undefined".

Does ra-data-feathers support working with non-paginated requests, maybe by setting an option in for the feathers services that do not have pagination?

josx commented 5 years ago

Can you post here the complete log or error?

roelnoort commented 5 years ago

What I do is:

  1. Login
  2. The app loads my first view which is non-paginated
  3. An error appears on the bottom of the screen. I'll include an image here. error-on-non-paginated-service

In the developer console the only thing that appears is this line:

Warning: Missing translation for key: "Cannot read property 'map' of undefined"

I traced this error by copying the source code for restClient.js and running it from my computer rather than from the npm package.

This brings me to the mapResponse function which crashes in the line marked below:

      case GET_LIST:
        response.data = response.data.map((_item) => {    // crashes on this line
          const item = _item;
          if (idKey !== 'id') {
            item.id = _item[idKey];
          }
          return _item;
        });
        return response;

For non-paginated requests the response.data field does not exists. So this line ends up calling .map on an undefined object. Like the error states. Hope this is clear.

Note: right now I fixed the error by changing the above code to:

        if (response.data) {
          response.data = response.data.map((_item) => {
            const item = _item
            if (idKey !== 'id') {
              item.id = _item[idKey]
            }
            return _item
          })
        } else {
          response.total = response.length
          response.data = response.map((_item) => {
            const item = _item
            if (idKey !== 'id') {
              item.id = _item[idKey]
            }
            return _item
          })
        }

However, I want to be sure that there isn't a way that non-paginated requests are already supported. I also do prefer to work on the npm packager rather than on a local copy/fork of it. I'd be happy to submit a PR if that helps and my suggestion seems viable to you.

josx commented 5 years ago

It seems that we didnt use non paginated services in feathers So I think your idea to support it is needed.

Some tips for the PR:

Would be great if you can do a PR.

josx commented 5 years ago

@roelnoort do you have an update on this? if not maybe someone else can take it

josx commented 5 years ago

@roelnoort here a PR #104 Can you check it out, if it solves your issue?