Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing translations for boolean/select fields #1607

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove label in v8 since all translations are done in the frontend now and keeping a label here seems to be pointless.

}>;

/**
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