-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Tests remaing field value in card view for null #419
Conversation
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! Just a couple small changes needed and we're good to merge.
example/config.yml
Outdated
@@ -15,6 +15,7 @@ collections: # A list of collections the CMS should be able to edit | |||
- {label: "Publish Date", name: "date", widget: "datetime", format: "YYYY-MM-DD hh:mma"} | |||
- {label: "Cover Image", name: "image", widget: "image", required: false, tagname: ""} | |||
- {label: "Body", name: "body", widget: "markdown"} | |||
- {label: "Some Field", name: "somefield", widget: "string", required: false} # Testing empty 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.
We've been using the example case as a testbed more often, and I think it's an anti-pattern overall - let's remove the example changes and just implement the fix for now.
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 just removed the new test content that was in there... it was there for the other PR I did with the space in the image file name issue, and I just reused it to test this one. It's gone now.
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.
Can you remove this line?
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.
Ack! Sorry about that. Done.
@@ -57,7 +57,7 @@ export default class EntryListing extends React.Component { | |||
: inferedFields.remainingFields && inferedFields.remainingFields.map(f => ( | |||
<p key={f.get('name')} className={styles.cardList}> | |||
<span className={styles.cardListLabel}>{f.get('label')}:</span>{' '} | |||
{ entry.getIn(['data', f.get('name')], '').toString() } | |||
{ entry.getIn(['data', f.get('name')], '')?entry.getIn(['data', f.get('name')], '').toString():'' } |
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.
We can improve readability plus shorten a bit: (entry.getIn(['data', f.get('name')]) || '').toString()
.
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.
LGTM
LGTM |
- Summary
In the current behavior, the CMS encounters a problem, while displaying "remaining fields" in a card, as it encounters a field with a value of "null" explicitly set in the front matter... blank works, but not null. The console errors with "Cannot read property 'toString' of null at EntryListing.js:60" and the CMS app will no longer respond until refreshed.
A null value occurs whenever a non-required field is skipped during post entry. This might not be intended behavior for persisting a post, but regardless, it should be handled.
The offending line originally read:
but now is changed to:
- Test plan
A post in the local content (index:1) was given a field of somefield: null and a corresponding field in the config was added to match it... and it was set required: false.
The app no longer crashes and all tests pass.
- Description for the changelog
Card remaining fields now are checked for null values.
- A picture of a cute animal (not mandatory but encouraged)