React-admin: [FEATURE] Add multiple projects support

Created on 17 May 2017  路  7Comments  路  Source: marmelab/react-admin

Is there any support for multiple projects per user in admin-on-rest?
For example: User logged in -> select project in navbar menu / main card -> view will be changed to selected project and all requests will be sent to this selected project

Great project guys!

Most helpful comment

@pjhile regarding your need to be able to define rest client by resource, I've faced a similar issue and made a simple package that might solve yours.
https://www.npmjs.com/package/aor-rest-client-router

const restRouter = restClientRouter({
    'posts': restClient1,
    'users': restClient2
});

const App = () => (
    <Admin restClient={restRouter}>
        <Resource name="posts" list={PostList} />
        <Resource name="users" list={UserList} />
    </Admin>
);

All 7 comments

This, or possibly being able to define the restClient by Resource instead of by Admin.

You'll have to write a custom app for that.

@pjhile regarding your need to be able to define rest client by resource, I've faced a similar issue and made a simple package that might solve yours.
https://www.npmjs.com/package/aor-rest-client-router

const restRouter = restClientRouter({
    'posts': restClient1,
    'users': restClient2
});

const App = () => (
    <Admin restClient={restRouter}>
        <Resource name="posts" list={PostList} />
        <Resource name="users" list={UserList} />
    </Admin>
);

@MhdSyrwan Thanks for that solution! How would you handle a common duplicate endpoint like 'users'? Can I buy you a beer?

@pjhile You're welcome :smile:
Actually, in my case I'm using (planning to use) a centralized user management server like open-id providers since i'm preparing the interface to communicate with a set of integrated micro-services.

However, the case of duplication may happen in many other ways. I'm afraid that it would cause other issues with admin-on-react itself.

Currently I have the following proposal:

const restRouter = restClientRouter({
    'posts': 'service1'
}, {
  service1: restClient1,
  service2: restClient2,
  service3: restClient3
});

const App = () => (
    <Admin restClient={restRouter}>
        <Resource name="posts" list={PostList} />
        <Resource name="service2://users" list={User1List} />
        <Resource name="service3://users" list={User2List} />
    </Admin>
);

The new proposal would have 2 ways to route the resources

  • Via the prefix service://
  • Via the routing table (the first parameter)

Might be nice to be able to define a default client and only override it for the resources which need a custom one. Nice idea btw :)

Updated Repo & Package:
@pjhile you can now deal with duplicate resource names.
@djhi I've used an ordered rule list instead of the mapping object, now we can set a default service/client by adding a * named rule at last.

New sample code

const restRouter = restClientRouter({
    rules: [
        ['posts',                 'service1'],
        ['users',                 'service2'],
        ['*',                     'service4']
    ],
    services: {
        service1: jsonRestClient('posts-server.dev'),
        service2: jsonRestClient('users-server.dev'),
        service3: jsonRestClient('comments-server.dev'),
        service4: jsonRestClient('profiles-server.dev'),
    }
});

const App = () => (
    <Admin restClient={restRouter}>
        <Resource name="posts" list={PostList} />        <!-- Will route to service1 -->
        <Resource name="users" list={UserList} />        <!-- Will route to service2 -->
        <Resource name="service3://comments"  
                            list={CommentList} />        <!-- Will route to service3 (explicit route) -->
        <Resource name="profiles" list={ProfileList} />  <!-- Will route to service4 (via the wildcard '*' rule) -->
    </Admin>
);

You can see the readme file for more details.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pixelscripter picture pixelscripter  路  3Comments

marknelissen picture marknelissen  路  3Comments

fzaninotto picture fzaninotto  路  3Comments

mbj36 picture mbj36  路  3Comments

waynebloss picture waynebloss  路  3Comments