payload icon indicating copy to clipboard operation
payload copied to clipboard

[3.0] isSortable not working as expected on relationship field

Open joedawson opened this issue 9 months ago • 3 comments

Link to reproduction

No response

Describe the Bug

When using the isSortable admin config option with a relationship field (whilst also using hasMany), I expect to be able to sort the selected items.

However this is not the case and the select menu functions as a typical hasMany select and items cannot be dragged/sorted.

Screenshot_2024-05-02_at_11 35 38

To Reproduce

I have a posts collection with the following field for related categories:

{
  name: 'categories',
  label: 'Categories',
  type: 'relationship',
  relationTo: 'categories',
  hasMany: true,
  admin: {
    isSortable: true,
  },
},

I would expect the Categories field to be sortable.

Payload Version

3.0.0-beta.21

Adapters and Plugins

No response

joedawson avatar May 02 '24 17:05 joedawson

I have exactly the same problem, 3.0.0-b24 in my case

tomekwlod avatar May 10 '24 08:05 tomekwlod

Hi @joedawson , I'm taking a look at this!

kendelljoseph avatar May 10 '24 17:05 kendelljoseph

Any news on this one?

tomekwlod avatar May 15 '24 13:05 tomekwlod

Thanks for fixing @JarrodMFlesch - confirming this works now in 3.0.0-beta.37.

joedawson avatar May 29 '24 15:05 joedawson

Not really much of an issue for my use case currently, but I think there may have been a knock-on issue as a result of this fix.

Fields are sortable, regardless of whether isSortable is set or is false - resulting in hasMany fields always being sortable. I tested this with relationship and select field types.

Again, not really an issue for me currently (personally, I would likely set it to true in most scenarios) - however I don't suspect this is intended.

{
  name: 'topics',
  label: 'Topics',
  type: 'relationship',
  relationTo: 'topics',
  hasMany: true,
  admin: {
    isSortable: false, // still sortable
  },
},
{
  name: 'my_select',
  label: 'Select stuff',
  type: 'select',
  options: [
    // ...
  ],
  hasMany: true,
  admin: {
    // omitting isSortable entirely, still sortable - however unsure of the default but suspect it would be false.
  }
},

joedawson avatar May 29 '24 15:05 joedawson

@joedawson good catch. I don't think this was caused bc of the fix, more so, it was able to be reproduced bc of the fix. Since you were not able to sort before and now you can. I can look into this 👍

JarrodMFlesch avatar May 29 '24 18:05 JarrodMFlesch

@joedawson PR here.

JarrodMFlesch avatar May 29 '24 18:05 JarrodMFlesch

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

github-actions[bot] avatar Sep 07 '24 03:09 github-actions[bot]