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

Tests remaing field value in card view for null #419

Merged
merged 3 commits into from
May 17, 2017
Merged

Tests remaing field value in card view for null #419

merged 3 commits into from
May 17, 2017

Conversation

jholmes033169
Copy link
Contributor

- 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:

{ entry.getIn(['data', f.get('name')], '').toString() }

but now is changed to:

{ entry.getIn(['data', f.get('name')], '')?entry.getIn(['data', f.get('name')], '').toString():'' }

- 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)

cute-animal-10

@jholmes033169 jholmes033169 changed the title Tests left over field value for null Tests remaing field value in card view for null May 14, 2017
Copy link
Contributor

@erquhart erquhart left a 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.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

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():'' }
Copy link
Contributor

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().

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erquhart erquhart requested a review from Benaiah May 17, 2017 01:53
@calavera
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants