fix(db-mongodb): removes precedence of regular chars over international chars in sort (#6923)

## Description

Fixes #6719 

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
This commit is contained in:
Patrik
2024-07-22 16:55:35 -04:00
committed by GitHub
parent 6d7ef919cb
commit 0058660b3f
7 changed files with 93 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import {
blocksWithLocalizedSameName,
defaultLocale,
englishTitle,
hungarianLocale,
localizedPostsSlug,
localizedSortSlug,
portugueseLocale,
@@ -80,6 +81,11 @@ export default buildConfigWithDefaults({
name: 'description',
type: 'text',
},
{
name: 'localizedDescription',
localized: true,
type: 'text',
},
{
name: 'localizedCheckbox',
localized: true,
@@ -321,6 +327,11 @@ export default buildConfigWithDefaults({
label: 'Arabic',
rtl: true,
},
{
code: hungarianLocale,
label: 'Hungarian',
rtl: false,
},
],
},
onInit: async (payload) => {
@@ -381,6 +392,7 @@ export default buildConfigWithDefaults({
title: relationEnglishTitle2,
},
})
await payload.update({
id: localizedPost.id,
collection,

View File

@@ -13,7 +13,7 @@ import { RESTClient } from '../helpers/rest'
import { arrayCollectionSlug } from './collections/Array'
import { nestedToArrayAndBlockCollectionSlug } from './collections/NestedToArrayAndBlock'
import configPromise from './config'
import { defaultLocale, localizedSortSlug } from './shared'
import { defaultLocale, hungarianLocale, localizedSortSlug } from './shared'
import {
englishTitle,
localizedPostsSlug,
@@ -292,6 +292,69 @@ describe('Localization', () => {
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id)
})
})
if (['mongoose'].includes(process.env.PAYLOAD_DATABASE)) {
describe('Localized sorting', () => {
let localizedAccentPostOne: LocalizedPost
let localizedAccentPostTwo: LocalizedPost
beforeEach(async () => {
// @ts-expect-error Force typing
localizedAccentPostOne = await payload.create({
collection,
data: {
title: 'non accent post',
localizedDescription: 'something',
},
locale: englishLocale,
})
// @ts-expect-error Force typing
localizedAccentPostTwo = await payload.create({
collection,
data: {
title: 'accent post',
localizedDescription: 'veterinarian',
},
locale: englishLocale,
})
await payload.update({
id: localizedAccentPostOne.id,
collection,
data: {
title: 'non accent post',
localizedDescription: 'valami',
},
locale: hungarianLocale,
})
await payload.update({
id: localizedAccentPostTwo.id,
collection,
data: {
title: 'accent post',
localizedDescription: 'állatorvos',
},
locale: hungarianLocale,
})
})
it('should sort alphabetically even with accented letters', async () => {
const sortByDescriptionQuery = await payload.find({
collection,
sort: 'description',
where: {
title: {
like: 'accent',
},
},
locale: hungarianLocale,
})
expect(sortByDescriptionQuery.docs[0].id).toEqual(localizedAccentPostTwo.id)
})
})
}
})
describe('Localized Sort Count', () => {

View File

@@ -8,6 +8,7 @@ export const relationSpanishTitle2 = `${relationSpanishTitle}2`
export const defaultLocale = 'en'
export const spanishLocale = 'es'
export const portugueseLocale = 'pt'
export const hungarianLocale = 'hu'
// Slugs
export const localizedPostsSlug = 'localized-posts'