mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-23 15:20:33 +03:00
Fix missing translation error in console. Closes #1038
This commit is contained in:
parent
66b31644fa
commit
986473393f
ui/src/common
@ -1,6 +1,7 @@
|
||||
import React from 'react'
|
||||
import { Chip, makeStyles } from '@material-ui/core'
|
||||
import { useTranslate } from 'react-admin'
|
||||
import inflection from 'inflection'
|
||||
|
||||
const useQuickFilterStyles = makeStyles((theme) => ({
|
||||
chip: {
|
||||
@ -8,9 +9,20 @@ const useQuickFilterStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}))
|
||||
|
||||
export const QuickFilter = ({ source, label }) => {
|
||||
export const QuickFilter = ({ source, resource, label, defaultValue }) => {
|
||||
const translate = useTranslate()
|
||||
const classes = useQuickFilterStyles()
|
||||
const lbl = label || `resources.song.fields.${source}`
|
||||
return <Chip className={classes.chip} label={translate(lbl)} />
|
||||
let lbl = label || source
|
||||
if (typeof lbl === 'string' || lbl instanceof String) {
|
||||
if (label) {
|
||||
lbl = translate(lbl, {
|
||||
_: inflection.humanize(inflection.underscore(lbl)),
|
||||
})
|
||||
} else {
|
||||
lbl = translate(`resources.${resource}.fields.${source}`, {
|
||||
_: inflection.humanize(inflection.underscore(source)),
|
||||
})
|
||||
}
|
||||
}
|
||||
return <Chip className={classes.chip} label={lbl} />
|
||||
}
|
||||
|
33
ui/src/common/QuickFilter.test.js
Normal file
33
ui/src/common/QuickFilter.test.js
Normal file
@ -0,0 +1,33 @@
|
||||
import * as React from 'react'
|
||||
import { cleanup, render } from '@testing-library/react'
|
||||
import { QuickFilter } from './QuickFilter'
|
||||
import StarIcon from '@material-ui/icons/Star'
|
||||
|
||||
describe('QuickFilter', () => {
|
||||
afterEach(cleanup)
|
||||
|
||||
it('renders label if provided', () => {
|
||||
const { getByText } = render(
|
||||
<QuickFilter resource={'song'} source={'name'} label={'MyLabel'} />
|
||||
)
|
||||
expect(getByText('MyLabel')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders resource translation if label is not provided', () => {
|
||||
const { getByText } = render(
|
||||
<QuickFilter resource={'song'} source={'name'} />
|
||||
)
|
||||
expect(getByText('resources.song.fields.name')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders a component label', () => {
|
||||
const { getByTestId } = render(
|
||||
<QuickFilter
|
||||
resource={'song'}
|
||||
source={'name'}
|
||||
label={<StarIcon data-testid="label-icon-test" />}
|
||||
/>
|
||||
)
|
||||
expect(getByTestId('label-icon-test')).not.toBeNull()
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user