From f9cb4c1abd40ccd6e0e1ecc3edd2b4f595a3284d Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 24 Jul 2023 09:36:08 +0300 Subject: [PATCH] Fixed: More translations for columns --- frontend/src/Components/Filter/Builder/FilterBuilderRow.js | 6 ++++-- frontend/src/Components/Form/SelectInput.js | 4 ++-- frontend/src/Components/Menu/FilterMenuContent.js | 2 +- frontend/src/Components/Table/Column.ts | 4 +++- frontend/src/Components/Table/Table.js | 2 +- frontend/src/Components/Table/TableHeaderCell.js | 7 +++++-- .../Components/Table/TableOptions/TableOptionsColumn.js | 4 ++-- .../Table/TableOptions/TableOptionsColumnDragSource.js | 4 ++-- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/frontend/src/Components/Filter/Builder/FilterBuilderRow.js b/frontend/src/Components/Filter/Builder/FilterBuilderRow.js index 61108b865..e8561613c 100644 --- a/frontend/src/Components/Filter/Builder/FilterBuilderRow.js +++ b/frontend/src/Components/Filter/Builder/FilterBuilderRow.js @@ -210,9 +210,11 @@ class FilterBuilderRow extends Component { const selectedFilterBuilderProp = this.selectedFilterBuilderProp; const keyOptions = filterBuilderProps.map((availablePropFilter) => { + const { name, label } = availablePropFilter; + return { - key: availablePropFilter.name, - value: availablePropFilter.label + key: name, + value: typeof label === 'function' ? label() : label }; }).sort((a, b) => a.value.localeCompare(b.value)); diff --git a/frontend/src/Components/Form/SelectInput.js b/frontend/src/Components/Form/SelectInput.js index 0a60ffe1e..553501afc 100644 --- a/frontend/src/Components/Form/SelectInput.js +++ b/frontend/src/Components/Form/SelectInput.js @@ -61,7 +61,7 @@ class SelectInput extends Component { value={key} {...otherOptionProps} > - {optionValue} + {typeof optionValue === 'function' ? optionValue() : optionValue} ); }) @@ -75,7 +75,7 @@ SelectInput.propTypes = { className: PropTypes.string, disabledClassName: PropTypes.string, name: PropTypes.string.isRequired, - value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.func]).isRequired, values: PropTypes.arrayOf(PropTypes.object).isRequired, isDisabled: PropTypes.bool, hasError: PropTypes.bool, diff --git a/frontend/src/Components/Menu/FilterMenuContent.js b/frontend/src/Components/Menu/FilterMenuContent.js index 1fdb2476f..516fbb648 100644 --- a/frontend/src/Components/Menu/FilterMenuContent.js +++ b/frontend/src/Components/Menu/FilterMenuContent.js @@ -33,7 +33,7 @@ class FilterMenuContent extends Component { selectedFilterKey={selectedFilterKey} onPress={onFilterSelect} > - {filter.label} + {typeof filter.label === 'function' ? filter.label() : filter.label} ); }) diff --git a/frontend/src/Components/Table/Column.ts b/frontend/src/Components/Table/Column.ts index 8c2122c65..31a696df7 100644 --- a/frontend/src/Components/Table/Column.ts +++ b/frontend/src/Components/Table/Column.ts @@ -1,8 +1,10 @@ import React from 'react'; +type PropertyFunction = () => T; + interface Column { name: string; - label: string | React.ReactNode; + label: string | PropertyFunction | React.ReactNode; columnLabel?: string; isSortable?: boolean; isVisible: boolean; diff --git a/frontend/src/Components/Table/Table.js b/frontend/src/Components/Table/Table.js index befc8219a..8afbf9ea0 100644 --- a/frontend/src/Components/Table/Table.js +++ b/frontend/src/Components/Table/Table.js @@ -107,7 +107,7 @@ function Table(props) { {...getTableHeaderCellProps(otherProps)} {...column} > - {column.label} + {typeof column.label === 'function' ? column.label() : column.label} ); }) diff --git a/frontend/src/Components/Table/TableHeaderCell.js b/frontend/src/Components/Table/TableHeaderCell.js index 21766978b..b0ed5c571 100644 --- a/frontend/src/Components/Table/TableHeaderCell.js +++ b/frontend/src/Components/Table/TableHeaderCell.js @@ -30,6 +30,7 @@ class TableHeaderCell extends Component { const { className, name, + label, columnLabel, isSortable, isVisible, @@ -53,7 +54,8 @@ class TableHeaderCell extends Component { {...otherProps} component="th" className={className} - title={columnLabel} + label={typeof label === 'function' ? label() : label} + title={typeof columnLabel === 'function' ? columnLabel() : columnLabel} onPress={this.onPress} > {children} @@ -77,7 +79,8 @@ class TableHeaderCell extends Component { TableHeaderCell.propTypes = { className: PropTypes.string, name: PropTypes.string.isRequired, - columnLabel: PropTypes.string, + label: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.node]), + columnLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), isSortable: PropTypes.bool, isVisible: PropTypes.bool, isModifiable: PropTypes.bool, diff --git a/frontend/src/Components/Table/TableOptions/TableOptionsColumn.js b/frontend/src/Components/Table/TableOptions/TableOptionsColumn.js index 2d91c7c63..402ef5ae1 100644 --- a/frontend/src/Components/Table/TableOptions/TableOptionsColumn.js +++ b/frontend/src/Components/Table/TableOptions/TableOptionsColumn.js @@ -35,7 +35,7 @@ function TableOptionsColumn(props) { isDisabled={isModifiable === false} onChange={onVisibleChange} /> - {label} + {typeof label === 'function' ? label() : label} { @@ -56,7 +56,7 @@ function TableOptionsColumn(props) { TableOptionsColumn.propTypes = { name: PropTypes.string.isRequired, - label: PropTypes.string.isRequired, + label: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired, isVisible: PropTypes.bool.isRequired, isModifiable: PropTypes.bool.isRequired, index: PropTypes.number.isRequired, diff --git a/frontend/src/Components/Table/TableOptions/TableOptionsColumnDragSource.js b/frontend/src/Components/Table/TableOptions/TableOptionsColumnDragSource.js index 100559660..77d18463f 100644 --- a/frontend/src/Components/Table/TableOptions/TableOptionsColumnDragSource.js +++ b/frontend/src/Components/Table/TableOptions/TableOptionsColumnDragSource.js @@ -112,7 +112,7 @@ class TableOptionsColumnDragSource extends Component {