payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.97k stars 1.59k forks source link

Bulk edit allows selecting unavailable fields #3090

Closed thgh closed 1 year ago

thgh commented 1 year ago

Link to reproduction

UI

To Reproduce

Create a field

{
  name: 'example',
  type: 'text',
  admin: {
    condition: () => false,
  },
},
  1. Select multiple rows
  2. Click the bulk edit button
  3. Find the example field

Expected: cannot find the field Actual: field is selected but nothing happens

Describe the Bug

If payload is smart enough to hide conditioned fields after selecting it, it can be smart enough to remove it from the field selection in the first place.

Payload Version

1.11.3

DanRibbens commented 1 year ago

Hey @thgh,

I'm hesitant to do any removal of fields from the selector. I'll explain a little on how this works and then we can figure out if there is anything to do here.

When bulk editing the UI can only use the fields that you give it. Obviously this has implications for things like field validation and conditions. Since it can't pull all the data for docs to do it dynamically, we're only able to work with the fields you have selected and use that, validation we don't even bother with since it would be incomplete. Conditions we left in. I considered bypassing it entirely, but we opted to say you have to add the fields you depend on for this. A typical use of conditions will have field B depends on the value from field A, so in this case to edit both A and B in your bulk edit to work with the conditional field B.

Your reproduction example isn't realistic since you're only returning false in your condition. If you really did want this, you could disable the field from bulk edit entirely with admin.disableBulkEdit.

Now with that all laid out, I don't know that it would be a great UX for the condition to apply to fields before a user has made selections. It would be a challenge to users to have to pick all the fields that a field depends on, fill it in, then go back to the field selector dropdown to look for the conditional field again, hoping they have met those conditions to then select it.

I'd be more inclined to show a placeholder for the field that indicates that the field is currently not available if the condition fails. That said, it would take a bit of work and I don't feel that this should be prioritized really.

I'm going to close this issue, but we can reopen or spawn a new discussion from this issue if you think there is a feature to be built.

What do you think?

thgh commented 1 year ago

👍 I think a placeholder or warning that the field is hidden would be better UX. (low prio)

github-actions[bot] commented 2 months ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.