Search code examples
javascriptreactjsadmin-on-rest

How can I use both Resource and MenuItem in Admin menu


So I have Admin with all the resources that I need and it works great. But I also need one little menu item that would just open a simple form with a button.

I created Menu.js like it's described here:

https://marmelab.com/admin-on-rest//AdminResource.html#menu

And added it to my admin.

But after that I see only items that I have in that Menu, but not resources. How can I have them both: Resources and MenuItems in that menu?


Solution

  • Have a look at the framework's Menu.js for inspiration.

    • You need to loop through the passed in resources param and create <MenuItem>s for each resource
    • Add your own <MenuItem>s
    • Add the {logout} if you are using authentication

    Ie:

    import React from 'react';
    import MenuItem from 'material-ui/MenuItem';
    import { Link } from 'react-router-dom';
    
    export default ({ resources, onMenuTap, logout }) => (
        <div>
            { resources.map(resource => {
              return <MenuItem
                key={resource.name}
                containerElement={<Link to={`/${resource.name}`} />}
                primaryText={resource.options.label}
                onTouchTap={onMenuTap}
              />
            })}
    
            <MenuItem key="download" containerElement={<Link to="/download" />} primaryText="Download" onTouchTap={onMenuTap} />
    
            {logout}
        </div>
    );