Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with non-paginated feathers services #101

Closed
roelnoort opened this issue May 30, 2019 · 5 comments · Fixed by #104
Closed

Working with non-paginated feathers services #101

roelnoort opened this issue May 30, 2019 · 5 comments · Fixed by #104

Comments

@roelnoort
Copy link

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
Copy link
Owner

josx commented May 30, 2019

Can you post here the complete log or error?

@roelnoort
Copy link
Author

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
Copy link
Owner

josx commented May 31, 2019

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:

  • Please add a test
  • Dont repeat code (as above)

Would be great if you can do a PR.

@josx
Copy link
Owner

josx commented Jun 11, 2019

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

@josx
Copy link
Owner

josx commented Jun 14, 2019

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

@josx josx closed this as completed in #104 Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants