Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update relation widget docs with filters option, add version tag #58

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion content/docs/widgets/relation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The relation widget allows you to reference items from another collection. It pr
* `min`: minimum number of items; ignored if **multiple** is `false`
* `max`: maximum number of items; ignored if **multiple** is `false`
* `options_length`: accepts integer to override number of options presented to user. Defaults to `20`.
* `filters`: <a href="https://github.com/decaporg/decap-cms/releases/tag/decap-cms%403.1.5" class="version-tag">3.1.5</a> allows adding filters by which the available options are filtered. You can add filters which are a pair of `field` and the allowed `values`, where the widget will only show options (collection items) that satisfy all the filters. A collection item satisfies a filter if the value of `field` is one of the values in `values`.
* **Referencing a folder collection example** (assuming a separate "authors" collection with "name" and "twitterHandle" fields with subfields "first" and "last" for the "name" field):

```yaml
Expand Down Expand Up @@ -60,4 +61,34 @@ The generated UI input will search the authors collection by name, and display e
value_field: "cities.*.id"
```

The generated UI input will search the cities file by city name, and display each city's name. On selection, the city id is saved for the field.
The generated UI input will search the cities file by city name, and display each city's name. On selection, the city id is saved for the field.

* **Filters example**

```yaml
- label: Posts
name: posts
widget: relation
collection: posts
multiple: true
search_fields: [title]
display_fields: [title]
value_field: '{{slug}}'
filters:
- field: draft
values: [false]
```

In this example, the relation widget will only show and allow posts that are not a draft (i.e. `draft` field is `false`). Say, we have 20 posts in the CMS of which 5 have `draft` set to true, then we will only see the other 15 posts as options in the relation widget.

Multiple filters can be added:

```yaml
filters:
- field: draft
values: [false]
- field: title
values: ['post about cats', 'post about dogs']
```

In this case only the posts with `draft` set to `false` and a title that is either 'posts about cats' or 'post about dogs' will be options seen in the relation widget.
14 changes: 14 additions & 0 deletions src/global-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ const globalStyles = css`
text-align: right;
}
}

.version-tag {
&:before {
content: 'New in v';
}
background: ${theme.colors.primaryDark};
color: white;
padding: 0.125em 0.5em;
border-radius: ${theme.radii[1]};
font-size: ${theme.fontsize[1]};
font-weight: 700;
display: inline-block;
margin: 0 0.5em;
}
`;

function GlobalStyles() {
Expand Down