keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.62k stars 2.21k forks source link

externalLink in `nav` doesn't work without being an array and renders a create button and count #4915

Open laurenskling opened 5 years ago

laurenskling commented 5 years ago

Expected behavior

According to docs https://github.com/keystonejs/keystone/blob/master/docs/documentation/Configuration/AdminUI-Options.md#navigation I can add an external link. I would expect to see a tile that goes to the link, but does not contain list things like items count and an add button.

Actual/Current behavior

You can only add an external link by putting the object into an array. Because this code: https://github.com/keystonejs/keystone/blob/master/lib/core/initNav.js#L32 will not wrap the Object with an array, and https://github.com/keystonejs/keystone/blob/master/lib/core/initNav.js#L40 _.map will actually map over the Object itself, thus crashing on line 42.

When rendering the tile, https://github.com/keystonejs/keystone/blob/master/admin/client/App/screens/Home/components/Lists.js#L18 this code will see no listData (because there is no list for it) and fallback isNoCreate to false, thus rendering a create button. The count is always rendered, which doesn't really make sense with a externalLink.

Steps to reproduce the actual/current behavior

The example will break:

keystone.set('nav', {
    'posts': ['posts', 'post-categories'],
    'galleries': 'galleries',
    'enquiries': 'enquiries',
    'users': 'users',
    'externalLink': {
        label: 'Keystone',
        key: 'keystone',
        path: 'http://keystonejs.com/'
    }
});

It builds with the array fix and will show count and add button:

keystone.set('nav', {
    'posts': ['posts', 'post-categories'],
    'galleries': 'galleries',
    'enquiries': 'enquiries',
    'users': 'users',
    'externalLink': [{
        label: 'Keystone',
        key: 'keystone',
        path: 'http://keystonejs.com/'
    }]
});

Environment

Software Version
Keystone 4.0.0
Node.js 10.15.1
Browser latest Chrome
scipe commented 5 years ago

Hi @laurenskling. Did you working on it or I can check and create PR?

laurenskling commented 5 years ago

@scipe i actually did work on it a while ago, now you mention it. I got some stuff fixed for this, but I wasn't too happy with the look. A block without a count and button will be way smaller... I'll set up a PR today, you can see