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 many to many (React) #13200

Merged
merged 2 commits into from
Dec 12, 2020
Merged

Conversation

ctamisier
Copy link
Contributor

@ctamisier ctamisier commented Dec 5, 2020

Fix the root issue of #13182
And fix an underlying issue where the relations from a many-to-many are set from the previous save.

the value from AvInput should be set once.

This same "solution" is already applied with: AvForm model={isNew ? {} : fooEntity}

@ctamisier ctamisier changed the title Fix many to many Fix many to many (React) Dec 5, 2020
@ctamisier ctamisier marked this pull request as ready for review December 5, 2020 18:06
}
return [];
};
export const mapIdList = (idList: ReadonlyArray<any>) => idList.filter((entityId: any) => entityId !== '').map((entityId: any) => ({ id: entityId }));
Copy link
Contributor

@qmonmert qmonmert Dec 5, 2020

Choose a reason for hiding this comment

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

and when the idList is undefined ?

@ctamisier
Copy link
Contributor Author

ctamisier commented Dec 5, 2020

It's quite tricky..
Before this PR and before the fix on mapIdList we have this "workflow":
image
First [1, 2, 3] is set to the value of the AvInput (even for a create new Foo, as it gets the previous one (so I just have created a Foo with [1, 2, 3] bars before getting here)...)
Then the reset is called which set the value of the AvInput to undefined.
Then when we save, values.bars is undefined (which leads to the undefined of the idList)
It looks like the AvInput gets messed up when its value changes during component rendering.

With this PR:
image
We set once and only once the value of AvInput which is always false (it could have been always undefined it would have worked as well).
And with this, values.bars is equal to [] which is the same case that when we save a Foo the very first time.

Copy link
Member

@ruddell ruddell left a comment

Choose a reason for hiding this comment

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

Tested locally, looks like a better fix to me. That list should not be undefined. It also fixes the issue with the previously saved options being displayed as selected.

@pascalgrimaud pascalgrimaud merged commit f3bc8b3 into jhipster:main Dec 12, 2020
@ctamisier ctamisier deleted the fix-many-to-many branch December 12, 2020 21:03
@pascalgrimaud pascalgrimaud added this to the 7.0.0-beta.0 milestone Dec 18, 2020
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