From 58bfa2d96efd6d14410cb9c453b8291b90008562 Mon Sep 17 00:00:00 2001 From: "Brady Stroud [SSW]" Date: Thu, 24 Jun 2021 22:49:06 +1000 Subject: [PATCH] feat: make search optional --- .../src/components/Collection/Collection.js | 4 + .../src/components/Collection/Sidebar.js | 18 ++-- .../Collection/__tests__/Sidebar.spec.js | 12 +++ .../__snapshots__/Sidebar.spec.js.snap | 92 +++++++++++++++++++ website/content/docs/configuration-options.md | 14 +++ 5 files changed, 132 insertions(+), 8 deletions(-) diff --git a/packages/netlify-cms-core/src/components/Collection/Collection.js b/packages/netlify-cms-core/src/components/Collection/Collection.js index b314426f..f0edb0a1 100644 --- a/packages/netlify-cms-core/src/components/Collection/Collection.js +++ b/packages/netlify-cms-core/src/components/Collection/Collection.js @@ -77,6 +77,7 @@ export class Collection extends React.Component { collection, collections, collectionName, + isSearchEnabled, isSearchResults, isSingleSearchResult, searchTerm, @@ -111,6 +112,7 @@ export class Collection extends React.Component { @@ -149,6 +151,7 @@ export class Collection extends React.Component { function mapStateToProps(state, ownProps) { const { collections } = state; + const isSearchEnabled = state.config && state.config.search != false; const { isSearchResults, match, t } = ownProps; const { name, searchTerm = '', filterTerm = '' } = match.params; const collection = name ? collections.get(name) : collections.first(); @@ -164,6 +167,7 @@ function mapStateToProps(state, ownProps) { collection, collections, collectionName: name, + isSearchEnabled, isSearchResults, searchTerm, filterTerm, diff --git a/packages/netlify-cms-core/src/components/Collection/Sidebar.js b/packages/netlify-cms-core/src/components/Collection/Sidebar.js index ae1e59b8..e7389fa5 100644 --- a/packages/netlify-cms-core/src/components/Collection/Sidebar.js +++ b/packages/netlify-cms-core/src/components/Collection/Sidebar.js @@ -70,6 +70,7 @@ export class Sidebar extends React.Component { static propTypes = { collections: ImmutablePropTypes.map.isRequired, collection: ImmutablePropTypes.map, + isSearchEnabled: PropTypes.bool, searchTerm: PropTypes.string, filterTerm: PropTypes.string, t: PropTypes.func.isRequired, @@ -103,17 +104,18 @@ export class Sidebar extends React.Component { }; render() { - const { collections, collection, searchTerm, t, filterTerm } = this.props; - + const { collections, collection, isSearchEnabled, searchTerm, t, filterTerm } = this.props; return ( {t('collection.sidebar.collections')} - searchCollections(query, collection)} - /> + {isSearchEnabled && ( + searchCollections(query, collection)} + /> + )} {collections .toList() diff --git a/packages/netlify-cms-core/src/components/Collection/__tests__/Sidebar.spec.js b/packages/netlify-cms-core/src/components/Collection/__tests__/Sidebar.spec.js index 6fee99cf..1fa04cb8 100644 --- a/packages/netlify-cms-core/src/components/Collection/__tests__/Sidebar.spec.js +++ b/packages/netlify-cms-core/src/components/Collection/__tests__/Sidebar.spec.js @@ -20,6 +20,7 @@ jest.mock('../../../actions/collections'); describe('Sidebar', () => { const props = { searchTerm: '', + isSearchEnabled: true, t: jest.fn(key => key), }; it('should render sidebar with a simple collection', () => { @@ -72,4 +73,15 @@ describe('Sidebar', () => { expect(asFragment()).toMatchSnapshot(); }); + + it('should render sidebar without search', () => { + const collections = fromJS([{ name: 'posts', label: 'Posts' }]).toOrderedMap(); + const { asFragment } = render( + + + , + ); + + expect(asFragment()).toMatchSnapshot(); + }); }); diff --git a/packages/netlify-cms-core/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap b/packages/netlify-cms-core/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap index 62947e8f..6d5f2978 100644 --- a/packages/netlify-cms-core/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap +++ b/packages/netlify-cms-core/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap @@ -214,3 +214,95 @@ exports[`Sidebar should render sidebar with a simple collection 1`] = ` `; + +exports[`Sidebar should render sidebar without search 1`] = ` + + .emotion-6 { + box-shadow: 0 2px 6px 0 rgba(68,74,87,0.05),0 1px 3px 0 rgba(68,74,87,0.1); + border-radius: 5px; + background-color: #fff; + width: 250px; + padding: 8px 0 12px; + position: fixed; + max-height: calc(100vh - 112px); + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; +} + +.emotion-0 { + font-size: 23px; + font-weight: 600; + padding: 0; + margin: 18px 12px 12px; + color: #313d3e; +} + +.emotion-4 { + margin: 16px 0 0; + list-style: none; + overflow: auto; +} + +.emotion-2 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + font-size: 14px; + font-weight: 500; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + padding: 8px 12px; + border-left: 2px solid #fff; + z-index: -1; +} + +.emotion-2 mocked-icon { + margin-right: 8px; + -webkit-flex-shrink: 0; + -ms-flex-negative: 0; + flex-shrink: 0; +} + +.emotion-2:hover, +.emotion-2:active, +.emotion-2.sidebar-active { + color: #3a69c7; + background-color: #e8f5fe; + border-left-color: #4863c6; +} + + + +`; diff --git a/website/content/docs/configuration-options.md b/website/content/docs/configuration-options.md index 7c6500be..7563e6c8 100644 --- a/website/content/docs/configuration-options.md +++ b/website/content/docs/configuration-options.md @@ -159,6 +159,20 @@ When a translation for the selected locale is missing the English one will be us show_preview_links: false ``` +## Search + +The search functionally requires loading all collection(s) entries, which can exhaust rate limits on large repositories. +It can be disabled by setting the top level `search` property to `false`. + +Defaults to `true` + +**Example:** + +```yaml +search: false +``` + + ## Slug Type The `slug` option allows you to change how filenames for entries are created and sanitized. It also applies to filenames of media inserted via the default media library.\