Skip to content

Commit

Permalink
fix: add missing translations for boolean/select fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Jan 19, 2024
1 parent c37ee2c commit 4c31587
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/backend/decorators/property/property-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class PropertyDecorator {
*
* @returns {Array<{value: string, label: string}>}
*/
availableValues(): null | Array<{ value: string | number; label: string }> {
availableValues(): null | Array<{ value: string | number; label?: string }> {
if (this.options.availableValues) {
return this.options.availableValues
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default interface PropertyOptions {
*/
availableValues?: Array<{
value: string | number;
label: string;
label?: string;
}>;

/**
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/components/property-type/boolean/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mapValue from './map-value.js'
import { FilterPropertyProps } from '../base-property-props.js'
import allowOverride from '../../../hoc/allow-override.js'
import PropertyLabel from '../utils/property-label/property-label.js'
import { useTranslation } from '../../../hooks/index.js'

const boolValue = (s: string): boolean => {
if (/true/i.test(s)) {
Expand All @@ -15,10 +16,11 @@ const boolValue = (s: string): boolean => {

const Filter: React.FC<FilterPropertyProps> = (props) => {
const { property, filter = {}, onChange } = props
const { tp } = useTranslation()
const value = typeof filter[property.path] === 'undefined' ? '' : boolValue(filter[property.path])
const options = [
{ value: true, label: mapValue(true) },
{ value: false, label: mapValue(false) },
{ value: true, label: tp(`${property.path}.true`, property.resourceId, { defaultValue: mapValue(true) }) },
{ value: false, label: tp(`${property.path}.false`, property.resourceId, { defaultValue: mapValue(false) }) },
]
const selected = options.find((o) => o.value === value)
const handleChange = (s) => {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/property-type/default-type/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Edit: FC<CombinedProps> = (props) => {

const SelectEdit: FC<CombinedProps> = (props) => {
const { record, property, onChange } = props
const { translateProperty } = useTranslation()
const { tp } = useTranslation()
if (!property.availableValues) {
return null
}
Expand All @@ -34,7 +34,7 @@ const SelectEdit: FC<CombinedProps> = (props) => {
// eslint-disable-next-line max-len
const availableValues = property.availableValues.map((v) => ({
...v,
label: translateProperty(v.label),
label: tp(`${property.path}.${v.value}`, property.resourceId, { defaultValue: v.label ?? v.value }),
}))
// eslint-disable-next-line eqeqeq
const selected = availableValues.find((av) => av.value == propValue)
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/property-type/default-type/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTranslation } from '../../../hooks/use-translation.js'

const Filter: React.FC<FilterPropertyProps> = (props) => {
const { property, onChange, filter } = props
const { translateProperty } = useTranslation()
const { tp } = useTranslation()

const handleInputChange = (event) => {
onChange(property.path, event.target.value)
Expand All @@ -25,7 +25,7 @@ const Filter: React.FC<FilterPropertyProps> = (props) => {
if (property.availableValues) {
const availableValues = property.availableValues.map((v) => ({
...v,
label: translateProperty(v.label),
label: tp(`${property.path}.${v.value}`, property.resourceId, { defaultValue: v.label ?? v.value }),
}))
const selected = property.availableValues.find((av) => av.value === value)
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface PropertyJSON {
/**
* If property has restricted number of values
*/
availableValues: Array<{label: string; value: string | number}> | null;
availableValues: Array<{label?: string; value: string | number}> | null;
/**
* Property uniq name
*/
Expand Down

0 comments on commit 4c31587

Please sign in to comment.