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

Improve relationships #49

Merged
merged 20 commits into from
May 18, 2018
Merged

Improve relationships #49

merged 20 commits into from
May 18, 2018

Conversation

JedWatson
Copy link
Member

WIP

Addresses requirements in #43

@JedWatson JedWatson mentioned this pull request May 15, 2018
@jesstelford
Copy link
Contributor

This looks like you're not using prettier?

prettier isn't in the project - should it be?

Copy link
Member Author

@JedWatson JedWatson left a comment

Choose a reason for hiding this comment

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

@jesstelford some comments for you. Looks good but would be nice to confirm these things 👍

{fields.map((field, index) => {
const { path } = field;

const isLoading = !item.hasOwnProperty(path);
Copy link
Member Author

Choose a reason for hiding this comment

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

What does isLoading mean in this context? not sure the conditions under which this could occur 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, me either. But I was getting errors because item didn't have certain keys on the object, and that component was getting rendered multiple times in quick succession.

This was all occurring immediately after I selected to display a relationship field from the dropdown, so I think it's related to triggering the data fetching query - the data hasn't yet returned, but somewhere up the hierarchy, that field is included in what to render, so it errored.

@@ -36,7 +36,7 @@ import ColumnSelect from './ColumnSelect';
import FilterSelect from './FilterSelect';
import SortSelect, { SortButton } from './SortSelect';

const getQueryArgs = args => {
const getQueryArgs = (args) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not formatted by prettier

getValue = data => {
const { many, path } = this.config;
return data[path] ? data[path] : many ? [] : null;
return data[path] ? data[path].id : many ? [] : null;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this would only work for single relationships, the logic needs to be a bit more sophisticated now:

return many ? data[path].map(i => i.id) : data[path] ? data[path].id : null;

As far as I can tell, for many relationships, GraphQL will always return an array here even if there are no related items, so that should be safe. But needs verification.

Copy link
Contributor

@jesstelford jesstelford May 16, 2018

Choose a reason for hiding this comment

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

Good catch!

Probably time to split it into if/else, and I think this way will work well:

if (!data[path]) {
  return many ? [] : null;
}
return many ? data[path].map(i => i.id) : data[path].id;

edit: Done in 12ba8f7

@jesstelford
Copy link
Contributor

Turns out I need some of the code in this branch for the files fields, so I'm going to base my branch off of improve-relationships until it's merged.

@jesstelford jesstelford force-pushed the improve-relationships branch from 12ba8f7 to 03c808f Compare May 16, 2018 13:00
@jesstelford
Copy link
Contributor

I've rebased improve-relationships onto master branch so it includes all the session work too.

@jesstelford jesstelford force-pushed the improve-relationships branch from 03c808f to dd3b8bc Compare May 16, 2018 13:05
@jesstelford
Copy link
Contributor

Just noticed a bug with creating an item that contains a relationship. Fixed in c6479cc

@JedWatson
Copy link
Member Author

@jesstelford I'm still seeing some bad behaviour in the List screen:

image

This is what's happening for many relationships with no current value, while a single relationship throws the following in the console:

Uncaught TypeError: Cannot read property 'id' of null
    at ../../fields/types/Relationship/views/Cell.js.exports.default (Cell.js:7)

@jesstelford
Copy link
Contributor

I shall fix that this morning 👍

@jesstelford
Copy link
Contributor

@jesstelford jesstelford force-pushed the improve-relationships branch from 1a463bd to c68dbc6 Compare May 17, 2018 01:52
@jesstelford jesstelford force-pushed the improve-relationships branch from 2095680 to 448e484 Compare May 18, 2018 00:18
@jesstelford jesstelford force-pushed the improve-relationships branch from 448e484 to 51c78e2 Compare May 18, 2018 00:19
@jesstelford
Copy link
Contributor

@jed I refactored to use your _label_ code - much nicer! See the diff for that here: keystonejs/keystone-5@19b93f0^1...51c78e2

@jesstelford
Copy link
Contributor

I'm happy with this PR, who wants to merge it for me?

@jesstelford
Copy link
Contributor

relationships-licecap

@jesstelford
Copy link
Contributor

@timleslie gave 👍

@jesstelford jesstelford merged commit e8b9422 into master May 18, 2018
@jesstelford jesstelford deleted the improve-relationships branch May 18, 2018 02:28
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.

2 participants