josx / ra-data-feathers

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

return object for restClient #40

Closed sarkistlt closed 7 years ago

sarkistlt commented 7 years ago

https://github.com/marmelab/admin-on-rest/pull/385

sarkistlt commented 7 years ago

otherwise I can see in debugger that I have response data in an array, but app shows error Warning: Missing translation for key: "Cannot read property 'map' of undefined"

Here is my code:

helpers.js

import feathers from 'feathers-client';

export const rest = feathers()
  .configure(feathers.hooks())
  .configure(feathers.rest(location.origin).fetch(window.fetch.bind(window)))
  .configure(feathers.authentication({ jwtStrategy: 'jwt', storage: window.localStorage }));

App.jsx

import React from 'react';
import { Admin, Resource } from 'admin-on-rest';
import { authClient, restClient } from 'aor-feathers-client';
import { rest } from '../helpers';
import Products from './components/Products';

const authClientOptions = {
  storageKey: 'feathers-jwt',
  authenticate: { strategy: 'local' },
};

export default () => (
  <Admin
    authClient={authClient(rest, authClientOptions)}
    restClient={restClient(rest)}
  >
    <Resource name="Product" list={Products} />
  </Admin>
);

Products.jsx

import React from 'react';
import { Datagrid, List, TextField } from 'admin-on-rest';

export default (props) => (
  <List title="Products" {...props}>
    <Datagrid>
      <TextField source="id" />
      <TextField source="name" />
      <TextField label="is Sample" source="isSample" />
      <TextField label="is Published" source="isPublished" />
      <TextField label="is Out Of Stock" source="isOutOfStock" />
    </Datagrid>
  </List>
);
sarkistlt commented 7 years ago

my bad, forgot to set pagination option in the service

josx commented 7 years ago

hey no problem, thanks for trying to contribute If you test it and find something is not working as you want please add issue, and much better if you can do a PR ;)