feat: make search optional
This commit is contained in:
parent
af6ae072bc
commit
58bfa2d96e
@ -77,6 +77,7 @@ export class Collection extends React.Component {
|
|||||||
collection,
|
collection,
|
||||||
collections,
|
collections,
|
||||||
collectionName,
|
collectionName,
|
||||||
|
isSearchEnabled,
|
||||||
isSearchResults,
|
isSearchResults,
|
||||||
isSingleSearchResult,
|
isSingleSearchResult,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
@ -111,6 +112,7 @@ export class Collection extends React.Component {
|
|||||||
<Sidebar
|
<Sidebar
|
||||||
collections={collections}
|
collections={collections}
|
||||||
collection={(!isSearchResults || isSingleSearchResult) && collection}
|
collection={(!isSearchResults || isSingleSearchResult) && collection}
|
||||||
|
isSearchEnabled={isSearchEnabled}
|
||||||
searchTerm={searchTerm}
|
searchTerm={searchTerm}
|
||||||
filterTerm={filterTerm}
|
filterTerm={filterTerm}
|
||||||
/>
|
/>
|
||||||
@ -149,6 +151,7 @@ export class Collection extends React.Component {
|
|||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state, ownProps) {
|
||||||
const { collections } = state;
|
const { collections } = state;
|
||||||
|
const isSearchEnabled = state.config && state.config.search != false;
|
||||||
const { isSearchResults, match, t } = ownProps;
|
const { isSearchResults, match, t } = ownProps;
|
||||||
const { name, searchTerm = '', filterTerm = '' } = match.params;
|
const { name, searchTerm = '', filterTerm = '' } = match.params;
|
||||||
const collection = name ? collections.get(name) : collections.first();
|
const collection = name ? collections.get(name) : collections.first();
|
||||||
@ -164,6 +167,7 @@ function mapStateToProps(state, ownProps) {
|
|||||||
collection,
|
collection,
|
||||||
collections,
|
collections,
|
||||||
collectionName: name,
|
collectionName: name,
|
||||||
|
isSearchEnabled,
|
||||||
isSearchResults,
|
isSearchResults,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
filterTerm,
|
filterTerm,
|
||||||
|
@ -70,6 +70,7 @@ export class Sidebar extends React.Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
collections: ImmutablePropTypes.map.isRequired,
|
collections: ImmutablePropTypes.map.isRequired,
|
||||||
collection: ImmutablePropTypes.map,
|
collection: ImmutablePropTypes.map,
|
||||||
|
isSearchEnabled: PropTypes.bool,
|
||||||
searchTerm: PropTypes.string,
|
searchTerm: PropTypes.string,
|
||||||
filterTerm: PropTypes.string,
|
filterTerm: PropTypes.string,
|
||||||
t: PropTypes.func.isRequired,
|
t: PropTypes.func.isRequired,
|
||||||
@ -103,17 +104,18 @@ export class Sidebar extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { collections, collection, searchTerm, t, filterTerm } = this.props;
|
const { collections, collection, isSearchEnabled, searchTerm, t, filterTerm } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarContainer>
|
<SidebarContainer>
|
||||||
<SidebarHeading>{t('collection.sidebar.collections')}</SidebarHeading>
|
<SidebarHeading>{t('collection.sidebar.collections')}</SidebarHeading>
|
||||||
<CollectionSearch
|
{isSearchEnabled && (
|
||||||
searchTerm={searchTerm}
|
<CollectionSearch
|
||||||
collections={collections}
|
searchTerm={searchTerm}
|
||||||
collection={collection}
|
collections={collections}
|
||||||
onSubmit={(query, collection) => searchCollections(query, collection)}
|
collection={collection}
|
||||||
/>
|
onSubmit={(query, collection) => searchCollections(query, collection)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<SidebarNavList>
|
<SidebarNavList>
|
||||||
{collections
|
{collections
|
||||||
.toList()
|
.toList()
|
||||||
|
@ -20,6 +20,7 @@ jest.mock('../../../actions/collections');
|
|||||||
describe('Sidebar', () => {
|
describe('Sidebar', () => {
|
||||||
const props = {
|
const props = {
|
||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
|
isSearchEnabled: true,
|
||||||
t: jest.fn(key => key),
|
t: jest.fn(key => key),
|
||||||
};
|
};
|
||||||
it('should render sidebar with a simple collection', () => {
|
it('should render sidebar with a simple collection', () => {
|
||||||
@ -72,4 +73,15 @@ describe('Sidebar', () => {
|
|||||||
|
|
||||||
expect(asFragment()).toMatchSnapshot();
|
expect(asFragment()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render sidebar without search', () => {
|
||||||
|
const collections = fromJS([{ name: 'posts', label: 'Posts' }]).toOrderedMap();
|
||||||
|
const { asFragment } = render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<Sidebar {...props} collections={collections} isSearchEnabled={false} />
|
||||||
|
</MemoryRouter>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(asFragment()).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -214,3 +214,95 @@ exports[`Sidebar should render sidebar with a simple collection 1`] = `
|
|||||||
</aside>
|
</aside>
|
||||||
</DocumentFragment>
|
</DocumentFragment>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Sidebar should render sidebar without search 1`] = `
|
||||||
|
<DocumentFragment>
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
<aside
|
||||||
|
class="emotion-6 emotion-7"
|
||||||
|
>
|
||||||
|
<h2
|
||||||
|
class="emotion-0 emotion-1"
|
||||||
|
>
|
||||||
|
collection.sidebar.collections
|
||||||
|
</h2>
|
||||||
|
<ul
|
||||||
|
class="emotion-4 emotion-5"
|
||||||
|
>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
class="emotion-2 emotion-3"
|
||||||
|
data-testid="posts"
|
||||||
|
href="/collections/posts"
|
||||||
|
>
|
||||||
|
<mocked-icon
|
||||||
|
type="write"
|
||||||
|
/>
|
||||||
|
Posts
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</aside>
|
||||||
|
</DocumentFragment>
|
||||||
|
`;
|
||||||
|
@ -159,6 +159,20 @@ When a translation for the selected locale is missing the English one will be us
|
|||||||
show_preview_links: false
|
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
|
## 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.\
|
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.\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user