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 clear value for relational interfaces #13224

Merged
merged 7 commits into from
Jun 8, 2022
Merged

Fix clear value for relational interfaces #13224

merged 7 commits into from
Jun 8, 2022

Conversation

azrikahar
Copy link
Contributor

Fixes #12854

Problem

Currently "to many" relational interfaces (or ones using useRelationMultiple) requires the initial payload to at least be an empty array. When the props.value is undefined, it is defaulted to an empty array as well.

However when we use Clear Value, it emits null value (not undefined), which breaks them:

chrome_yG90ec5nnB.mp4

Solution

Now useRelationMultiple will clear the value properly, and ensure it being undefined or [] depending on the initial value to not stage any edits.

However if there are any existing values (not newly created or updated ones, those will still be cleared), we will stage them for deletion instead.

chrome_PDOTQ8oCT5.mp4

Copy link
Member

@rijkvanzanten rijkvanzanten left a comment

Choose a reason for hiding this comment

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

However if there are any existing values (not newly created or updated ones, those will still be cleared), we will stage them for deletion instead.

I'm wondering if this is needed. The API will also clear everything if null is submitted IIRC, so we might be able to just have the app handle null as [], and be done 🤔

@azrikahar
Copy link
Contributor Author

However if there are any existing values (not newly created or updated ones, those will still be cleared), we will stage them for deletion instead.

I'm wondering if this is needed. The API will also clear everything if null is submitted IIRC, so we might be able to just have the app handle null as [], and be done 🤔

It was initially due to the existing items persisting visually after being cleared:

chrome_nHAGsAHKZE.mp4

hence I opted to use the current approach. I do agree it'll feel more like the previous interaction if we fully clear the items, so I tried to implement it here but there's a slight issue where the Add Existing drawer will still filter out existing items:

chrome_Sl3Xx3CDxz.mp4

It's due to the following filter to exclude an existing entry's relational items:

const selectFilter: Filter = {
[reverseRelation]: {
_none: {
[relationInfo.value.reverseJunctionField.field]: {
_eq: props.primaryKey,
},
},
},
};

So not sure how to "toggle" this off after a user clears the value to full empty to ensure they can select the existing items again, at least without even more changes I presume 🤔 (and will need to "toggle" this on back again when user uses Undo Value)

@rijkvanzanten rijkvanzanten added this to the v9-next milestone Jun 8, 2022
@rijkvanzanten rijkvanzanten merged commit ef2b629 into main Jun 8, 2022
@rijkvanzanten rijkvanzanten deleted the issue/12854 branch June 8, 2022 14:16
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clear value causing error for relational fields
2 participants