-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Support displayFields in the Relation widget #1303
Conversation
By only changing the |
Deploy preview for cms-demo ready! Built with commit 0d9f19a |
Deploy preview for netlify-cms-www ready! Built with commit 0d9f19a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, I love the simplicity of your approach. Can you push a commit that updates the first field in the kitchen sink example to use this? That way we can try it out in the deploy preview.
@@ -90,7 +90,14 @@ class RelationControl extends Component { | |||
|
|||
renderSuggestion = (suggestion) => { | |||
const { field } = this.props; | |||
const valueField = field.get('valueField'); | |||
const valueField = field.get('displayFields').toJS() || field.get('valueField'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would error out if displayFields
isn't a list. Instead of converting to JS, just leave the value as is and switch your Array.isArray
check to List.isList
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Thanks for the suggestions @erquhart. I have updated the PR with your feedback. |
Can you add it to the example so we can try it out in the deploy preview? The relevant config field is here: https://github.com/netlify/netlify-cms/blob/1.6.0/example/config.yml#L73-L78 |
I had a typo in my previous PR. Should be fixed now and live on the preview site. I guess I can't access the CMS from my GitHub username which makes sense. |
Found an error - try typing "post" into the relation field in the deploy preview, you'll get this error:
Which means each |
Ok, thanks for your patience @erquhart. My patch was to wrap all items in I opted to use this approach over I am punting on objects, they render as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're there! Just a few documentation change requests.
searchFields: ["name", "twitterHandle"] | ||
valueField: "name" | ||
``` | ||
The generated UI input will search the authors collection by name and twitterHandle as the user types. On selection, the author name will be saved for the field. | ||
The generated UI input will search the authors collection by name and twitterHandle as the user types. Each collection will be represented by the author's handle and follower count. On selection, the author name will be saved for the field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine this change into the first sentence, so the first sentence reads:
The generated UI input will search the authors collection by name and twitterHandle, and display each author's handle and follower count.
@@ -22,7 +23,8 @@ The relation widget allows you to reference items from another collection. It pr | |||
name: "author" | |||
widget: "relation" | |||
collection: "authors" | |||
displayFields: ["twitterHandle", "followerCount"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop this to the bottom (optional field).
@@ -13,6 +13,7 @@ The relation widget allows you to reference items from another collection. It pr | |||
- **Options:** | |||
- `default`: accepts any widget data type; defaults to an empty string | |||
- `collection`: (**required**) name of the collection being referenced (string) | |||
- `displayFields`: list of one or more names of fields in the referenced collection that will render in the autocomplete menu of the control. The value field is used by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace last sentence with:
Defaults to
valueField
.
@erquhart updated |
Do you have any idea on when this PR can be merged in? I'd really like to start benefiting from this feature ASAP. |
@talves @tech4him1 @Benaiah need one more approval here Sent with GitHawk |
@zurawiki just merged the changes, thanks for the PR! |
* Support displayFields in the Relation widget * Fix typo * Wrap display fields in String constructors * 📝 Documentation updates
- Summary
Some relation objects I have are stored by an
id
field to guarantee each object has a unique value. Myid
s are random hashes though and they are not very informative, especially looking through the autocomplete options.By adding the
displayFields
option, we can render information of the object that is more useful to the user. In my case I can display the title and author, which helps distinguish posts with the same title.- Test plan
Manual testing works
The test suite passes using
yarn test
- Description for the changelog
The relation widget now supports custom display fields