Skip to content

Commit 39ad31a

Browse files
authored
fix: add locale support to relationship filter options in WhereBuilder (#11783)
### What? This PR fixes a bug in the relationship filter UI where no options are displayed when working in a non-default locale with localized collections. The query to fetch relationship options wasn't including the current locale parameter, causing the select dropdown to appear empty. ### Why? When using localized collections with relationship fields: 1. If you create entries (e.g., Categories) only in a non-default locale 2. Set the global locale to that non-default locale 3. Try to filter another collection by its relationship to those Categories The filter dropdown would be empty, despite Categories existing in that locale. This was happening because the `loadOptions` method in the RelationshipFilter component didn't include the current locale in its query. ### How? The fix is implemented in `packages/ui/src/elements/WhereBuilder/Condition/Relationship/index.tsx` by: 1. Adding the `useLocale` hook to get the current locale in the RelationshipFilter component 2. Including this locale in the query parameters when fetching relationship options ![Before: Dropdown showing relationship options as empty options](https://github.com/user-attachments/assets/b796840b-9001-4f38-98c4-7b37ee4121d7) ![After: Dropdown properly showing relationship options in non-default locale](https://github.com/user-attachments/assets/a2f58d52-881e-49f7-b4dd-4b4ec7d07f10) Fixes #11782 Discussion: https://discord.com/channels/967097582721572934/1350888604150534164
1 parent 1d25b16 commit 39ad31a

File tree

1 file changed

+3
-0
lines changed
  • packages/ui/src/elements/WhereBuilder/Condition/Relationship

1 file changed

+3
-0
lines changed

packages/ui/src/elements/WhereBuilder/Condition/Relationship/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Props, ValueWithRelation } from './types.js'
1010
import { useDebounce } from '../../../../hooks/useDebounce.js'
1111
import { useEffectEvent } from '../../../../hooks/useEffectEvent.js'
1212
import { useConfig } from '../../../../providers/Config/index.js'
13+
import { useLocale } from '../../../../providers/Locale/index.js'
1314
import { useTranslation } from '../../../../providers/Translation/index.js'
1415
import { ReactSelect } from '../../../ReactSelect/index.js'
1516
import optionsReducer from './optionsReducer.js'
@@ -43,6 +44,7 @@ export const RelationshipFilter: React.FC<Props> = (props) => {
4344
const [errorLoading, setErrorLoading] = useState('')
4445
const [hasLoadedFirstOptions, setHasLoadedFirstOptions] = useState(false)
4546
const { i18n, t } = useTranslation()
47+
const locale = useLocale()
4648

4749
const relationSlugs = hasMultipleRelations ? relationTo : [relationTo]
4850

@@ -98,6 +100,7 @@ export const RelationshipFilter: React.FC<Props> = (props) => {
98100
const query = {
99101
depth: 0,
100102
limit: maxResultsPerRequest,
103+
locale: locale.code,
101104
page: loadedRelationship.nextPage,
102105
select: {
103106
[fieldToSearch]: true,

0 commit comments

Comments
 (0)