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

Fix resource table when working with lists #2122

Merged
merged 2 commits into from
Oct 26, 2020
Merged

Conversation

andresmgot
Copy link
Contributor

Description of the change

At the moment, the code was assuming that there were one resource reference per resource in the state. Sometimes the reference points to a list so there will be more resources than references.

This PR also handles the case in which there are no references at all (but this is not happening IRL).

Applicable issues

),
resources.map((resource, index) => {
// When the resourceRef is a list, the list of references will be just one
const ref = resourceRefs[index] || resourceRefs[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a little ambiguous to me, in that if there were 3 resource refs and 5 resources it would get the refs for the first 3 iterations and then the 0th for the fourth and fifth (not that that's possible for the data you expect). If you expect that the length of resourceRefs will be 1 specifically in this case, why not make that explicit:

const ref = (resourceRefs.length === 1) ? resourceRefs[0] : resourceRefs[index];  

so that if our expectations aren't met, we'll still get an error as we should, rather than masking it with odd behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, yes, it's also more readable that way.

@andresmgot andresmgot merged commit e5a1bea into master Oct 26, 2020
@andresmgot andresmgot deleted the resourceTableList branch November 26, 2020 09:55
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.

An error occurred: Cannot read property 'name' of undefined
2 participants