Commit bd254285 authored by Maxym Borodenko's avatar Maxym Borodenko

New `Property` column with translated field names

parent 914e3df0
......@@ -84,6 +84,7 @@
"logDate": "Date",
"action": "Action",
"propertyName": "Property Name",
"property": "Property",
"previousState": "Previous State",
"newState": "New State"
},
......
......@@ -73,6 +73,7 @@
"logDate": "Date",
"action": "Action",
"propertyName": "Property Name",
"property": "Property",
"previousState": "Previous State",
"newState": "New State"
},
......
......@@ -751,12 +751,13 @@ interface ITableRowProps {
toggleRowSelect;
columnClasses: any;
t: any;
}
class TableRow extends React.PureComponent<ITableRowProps & WithStyles> {
class TableRowInternal extends React.PureComponent<ITableRowProps & WithStyles & WithTranslation> {
public render() {
const { index, data, selected, columnsToDisplay, toggleRowSelect, classes, columnClasses } = this.props;
const { index, data, selected, columnsToDisplay, toggleRowSelect, classes, columnClasses, t } = this.props;
// console.log(`Rendering row ${index}`);
return (
<tr className={ selected ? '' : classes.selectedRow }>
......@@ -765,17 +766,17 @@ class TableRow extends React.PureComponent<ITableRowProps & WithStyles> {
</td>
{ columnsToDisplay.map((c) => (
<td key={ c } className={ columnClasses[c] }>
{ this.write(c, data[c], data) }
{ this.write(c, data[c], data, t) }
</td>
)) }
</tr>
)
}
private write(columnKey: string, d: any, row: any[]): React.ReactNode {
private write(columnKey: string, d: any, row: any[], t): React.ReactNode {
// Call render even if cell data is null
if (this.props.columnRenderers[columnKey]) {
return this.props.columnRenderers[columnKey](d, row);
return this.props.columnRenderers[columnKey](d, row, t);
}
// Use custom renderer if provided
if (this.props.defaultRenderer) {
......@@ -796,4 +797,6 @@ class TableRow extends React.PureComponent<ITableRowProps & WithStyles> {
}
}
const TableRow = withTranslation()(TableRowInternal);
export default withUserSettings(withTranslation()(withStyles(styles)(withTheme(Table))));
......@@ -10,7 +10,7 @@ export interface IBasicConfigProps {
columnsRenderers: {
[key: string]: (value: any, rowData: object) => JSX.Element,
};
defaultRenderer?: (value: any, rowData: object) => JSX.Element;
defaultRenderer?: (value: any, rowData: object, t?: any) => JSX.Element;
defaultColumnSettings: {
[key: string]: IColumnConfiguration,
};
......
......@@ -11,6 +11,7 @@ const InventoryAuditLogsTableConfigProps = {
'logDate',
'action',
'propertyName',
'property',
'previousState',
'newState',
'createdBy',
......@@ -22,10 +23,18 @@ const InventoryAuditLogsTableConfigProps = {
},
columnsRenderers: {
logDate: Renderers.DATE_RENDERER,
property: (value, row, t): JSX.Element => {
if (!row || typeof row !== 'object') { return null }
const className = row.classPk.classname.split('.').pop(); // split using dots and get the last element of array
const key = 'propertyName';
const propertyName = row[key];
return propertyName ? t(`client:model.${className}.${propertyName}`) : null
},
},
};
const InventoryAuditLogsTableConfig = new TableConfiguration(InventoryAuditLogsTableConfigProps);
const InventoryAuditLogsTableConfig = new TableConfiguration(InventoryAuditLogsTableConfigProps as any);
interface IInventoryAuditLogsTableProps {
auditLogs: AuditLog[];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment