Skip to content

Commit

Permalink
fix(core): use translation strings for boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Oct 15, 2024
1 parent 57ba0ba commit 4020788
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useMemo} from 'react'
import {styled} from 'styled-components'

import {TextWithTone} from '../../../../../../components'
import {useTranslation} from '../../../../../../i18n'
import {type TFunction, useTranslation} from '../../../../../../i18n'
import {Translate, type TranslateComponentMap} from '../../../../../../i18n/Translate'
import {isRecord} from '../../../../../../util'
import {useSearchState} from '../../contexts/search/useSearchState'
Expand Down Expand Up @@ -80,13 +80,16 @@ export function FilterLabel({filter, fontSize = 1, showContent = true}: FilterLa
t={t}
i18nKey={operator?.descriptionKey}
components={components}
values={getFilterValues(filter)}
values={getFilterValues(filter, t)}
/>
</Flex>
)
}

function getFilterValues(filter: SearchFilter): SearchFilterValues {
function getFilterValues(
filter: SearchFilter,
t: TFunction<'translation', undefined>,
): SearchFilterValues {
const values: SearchFilterValues = {}
if (typeof filter.value === 'number') {
values.count = filter.value
Expand All @@ -96,7 +99,7 @@ function getFilterValues(filter: SearchFilter): SearchFilterValues {
}
if (typeof filter.value === 'boolean') {
// Cast boolean into a string value
values.value = filter.value.toString()
values.value = filter.value ? t('search.filter-boolean-true') : t('search.filter-boolean-false')
}
if (isRecord(filter.value) && 'from' in filter.value && isStringOrNumber(filter.value.from)) {
values.from = filter.value.from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('FilterLabel', () => {

expect(screen.getByText('Title')).toBeInTheDocument()
expect(screen.getByText('is')).toBeInTheDocument()
expect(screen.getByText('true')).toBeInTheDocument()
expect(screen.getByText('True')).toBeInTheDocument()
})

test('renders only the field when showContent is false', async () => {
Expand All @@ -76,7 +76,7 @@ describe('FilterLabel', () => {

expect(screen.getByText('Title')).toBeInTheDocument()
expect(screen.queryByText('is')).not.toBeInTheDocument()
expect(screen.queryByText('true')).not.toBeInTheDocument()
expect(screen.queryByText('True')).not.toBeInTheDocument()
})

test('handles missing operator descriptionKey', async () => {
Expand Down Expand Up @@ -105,6 +105,6 @@ describe('FilterLabel', () => {

expect(screen.getByText('Title')).toBeInTheDocument()
expect(screen.queryByText('is')).not.toBeInTheDocument()
expect(screen.queryByText('Test Value')).not.toBeInTheDocument()
expect(screen.queryByText('True')).not.toBeInTheDocument()
})
})

0 comments on commit 4020788

Please sign in to comment.