/** * * TableRow * */ import React from 'react'; import { Link } from 'react-router'; import _ from 'lodash'; import styles from './styles.scss'; class TableRow extends React.Component { // eslint-disable-line react/prefer-stateless-function constructor(props) { super(props); this.goEditPage = this.goEditPage.bind(this); } /** * Redirect to the edit page */ goEditPage() { this.context.router.push(this.props.destination); } /** * Return a formatted value according to the * data type and value stored in database * * @param type {String} Data type * @param value {*} Value stored in database * @returns {*} */ getDisplayedValue(type, value) { switch (type) { case 'string': return !_.isEmpty(value) ? value.toString() : '-'; case 'integer': return !_.isEmpty(value) ? Number(value) : '-'; default: return '-'; } } render() { // Generate cells const cells = this.props.headers.map((header, i) => { // Default content let content = this.getDisplayedValue(header.type, this.props.record[header.name]); // Display a link if the current column is the `id` column if (header.name === this.props.primaryKey) { content = ( {this.getDisplayedValue(header.type, this.props.record[header.name])} ); } return (