GithubHelp home page GithubHelp logo

cycorld / react-admin-loopback Goto Github PK

View Code? Open in Web Editor NEW

This project forked from darthwesker/react-admin-loopback

0.0 1.0 0.0 37 KB

Packages related to using Loopback with react-admin

License: MIT License

JavaScript 100.00%

react-admin-loopback's Introduction

Loopback Client for react-admin

For using Loopback 3 with react-admin.

Installation

npm install --save react-admin-loopback

Prerequisite

  • Your loopback server must response Content-Range header when querying list. Please use loopback-content-range on your server end.

Usage

// in src/App.js
import React from 'react';
import { Admin, Resource } from 'react-admin';
import loopbackClient, { authProvider } from 'react-admin-loopback';
import { List, Datagrid, TextField, NumberField } from 'react-admin';

import { ShowButton, EditButton, Edit, SimpleForm, DisabledInput, TextInput, NumberInput } from 'react-admin';
import { Create} from 'react-admin';
import { Show, SimpleShowLayout } from 'react-admin';

const BookList = (props) => (
  <List {...props}>
    <Datagrid>
      <ShowButton />
      <EditButton />
      <TextField source="author" />
      <NumberField source="count" />
    </Datagrid>
  </List>
);
export const BookShow = (props) => (
  <Show {...props}>
    <SimpleShowLayout>
      <TextField source="author" />
      <NumberField source="count" />
    </SimpleShowLayout>
  </Show>
);
export const BookEdit = (props) => (
  <Edit {...props}>
    <SimpleForm>
      <DisabledInput source="id" />
      <TextInput source="author" />
      <NumberInput source="count" />
    </SimpleForm>
  </Edit>
);
export const BookCreate = (props) => (
  <Create {...props}>
    <SimpleForm>
      <TextInput source="author" />
      <NumberInput source="count" />
    </SimpleForm>
  </Create>
);
const App = () => (
  <Admin dataProvider={loopbackClient('http://localhost:3000')} authProvider={authProvider('http://localhost:3000/users/login')}>
    <Resource name="books" show={BookShow} create={BookCreate} edit={BookEdit} list={BookList} />
  </Admin>
);

export default App;

The dataProvider supports include:

// dataProvider.js
import loopbackProvider from 'react-admin-loopback';

const dataProvider = loopbackProvider('http://localhost:3000');
export default (type, resource, params) => 
  new Promise(resolve => 
    setTimeout(() => resolve(dataProvider(type, resource, params)), 500)  
  );
import dataProvider from './dataProvider';

...

dataProvider(GET_LIST, 'books', {
  filter: { hide: false },
  sort: { field: 'id', order: 'DESC' },
  pagination: { page: 1, perPage: 0 },
  include: 'users'
}).then(response => {
  ...
});

...

License

This library is licensed under the MIT Licence.

react-admin-loopback's People

Contributors

darthwesker avatar afilp avatar imekinox avatar sghribi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.