From 88b6c633afb4ba50fe46c0fef753bd209f832e67 Mon Sep 17 00:00:00 2001 From: Shashank Bairy R Date: Wed, 22 Apr 2020 12:32:13 +0000 Subject: [PATCH] feat: add hide property to collections (#3618) (#3643) --- packages/netlify-cms-core/src/components/App/App.js | 7 ++++++- .../netlify-cms-core/src/components/Collection/Sidebar.js | 7 ++++++- packages/netlify-cms-core/src/constants/configSchema.js | 1 + website/content/docs/configuration-options.md | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/netlify-cms-core/src/components/App/App.js b/packages/netlify-cms-core/src/components/App/App.js index eedfc15e..1d8e9eb1 100644 --- a/packages/netlify-cms-core/src/components/App/App.js +++ b/packages/netlify-cms-core/src/components/App/App.js @@ -50,7 +50,12 @@ const ErrorCodeBlock = styled.pre` `; const getDefaultPath = collections => { - return `/collections/${collections.first().get('name')}`; + const first = collections.filter(collection => collection.get('hide') !== true).first(); + if (first) { + return `/collections/${first.get('name')}`; + } else { + throw new Error('Could not find a non hidden collection'); + } }; const RouteInCollection = ({ collections, render, ...props }) => { diff --git a/packages/netlify-cms-core/src/components/Collection/Sidebar.js b/packages/netlify-cms-core/src/components/Collection/Sidebar.js index a124c885..ea954921 100644 --- a/packages/netlify-cms-core/src/components/Collection/Sidebar.js +++ b/packages/netlify-cms-core/src/components/Collection/Sidebar.js @@ -133,7 +133,12 @@ class Sidebar extends React.Component { value={query} /> - {collections.toList().map(this.renderLink)} + + {collections + .toList() + .filter(collection => collection.get('hide') !== true) + .map(this.renderLink)} + ); } diff --git a/packages/netlify-cms-core/src/constants/configSchema.js b/packages/netlify-cms-core/src/constants/configSchema.js index 3b746c3b..90edb03e 100644 --- a/packages/netlify-cms-core/src/constants/configSchema.js +++ b/packages/netlify-cms-core/src/constants/configSchema.js @@ -118,6 +118,7 @@ const getConfigSchema = () => ({ preview_path_date_field: { type: 'string' }, create: { type: 'boolean' }, publish: { type: 'boolean' }, + hide: { type: 'boolean' }, editor: { type: 'object', properties: { diff --git a/website/content/docs/configuration-options.md b/website/content/docs/configuration-options.md index aeab7fed..224c3070 100644 --- a/website/content/docs/configuration-options.md +++ b/website/content/docs/configuration-options.md @@ -195,6 +195,7 @@ The `collections` setting is the heart of your Netlify CMS configuration, as it * `filter`: optional filter for `folder` collections; details in [Collection Types](../collection-types) * `create`: for `folder` collections only; `true` allows users to create new items in the collection; defaults to `false` * `publish`: for `publish_mode: editorial_workflow` only; `false` hides UI publishing controls for a collection; defaults to `true` +* `hide`: `true` hides a collection in the CMS UI; defaults to `false`. Useful when using the relation widget to hide referenced collections. * `delete`: `false` prevents users from deleting items in a collection; defaults to `true` * `extension`: see detailed description below * `format`: see detailed description below