Skip to content

fix: orderable collection not working when collection has group or tab field #12129

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/drizzle/src/transform/read/traverseFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export const traverseFields = <T extends Record<string, unknown>>({
if (isLocalized && locale) {
delete table._locale
}
ref[refKey] = traverseFields<Record<string, unknown>>({
const fieldRef = traverseFields<Record<string, unknown>>({
adapter,
blocks,
config,
Expand All @@ -666,10 +666,12 @@ export const traverseFields = <T extends Record<string, unknown>>({
withinArrayOrBlockLocale: locale || withinArrayOrBlockLocale,
})

if ('_order' in ref) {
delete ref._order
if ('_order' in fieldRef && field.name !== 'version' && field.type === 'group') {
delete fieldRef._order
}

ref[refKey] = fieldRef

return
}

Expand Down
10 changes: 10 additions & 0 deletions test/sort/collections/Orderable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ export const OrderableCollection: CollectionConfig = {
name: 'title',
type: 'text',
},
{
type: 'group',
name: 'meta',
fields: [
{
name: 'tag',
type: 'text',
},
],
},
{
name: 'orderableField',
type: 'relationship',
Expand Down
8 changes: 4 additions & 4 deletions test/sort/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ async function seedSortable(payload: Payload) {
const joinA = await payload.create({ collection: 'orderable-join', data: { title: 'Join A' } })

await createData(payload, 'orderable', [
{ title: 'A', orderableField: joinA.id },
{ title: 'B', orderableField: joinA.id },
{ title: 'C', orderableField: joinA.id },
{ title: 'D', orderableField: joinA.id },
{ title: 'A', orderableField: joinA.id, meta: { tag: 'a' } },
{ title: 'B', orderableField: joinA.id, meta: { tag: 'a' } },
{ title: 'C', orderableField: joinA.id, meta: { tag: 'a' } },
{ title: 'D', orderableField: joinA.id, meta: { tag: 'a' } },
])

await payload.create({ collection: 'orderable-join', data: { title: 'Join B' } })
Expand Down
Loading