import { IFetchDataForViewItemResult } from 'data/IFetchDataForViewItemResult' ; import { Icon } from 'office-ui-fabric-react/lib/Icon' ; import { formatDate , tryParseCurrency } from 'pp365-shared/lib/helpers' ; import { ProjectColumn } from 'pp365-shared/lib/models' ; import React from 'react' ; import { IPortfolioOverviewProps } from '../types' ; import { TitleColumn } from './TitleColumn' ; import { IRenderItemColumnProps } from './IRenderItemColumnProps' ; import { TagsColumn } from './TagsColumn' ; import { UserColumn } from './UserColumn' ; /**
 * Mapping for rendering of the different data types
 */ const renderDataTypeMap = { user : ( props ) => < UserColumn { ... props } / > , date : ( { columnValue : colValue } ) => < span > { formatDate ( colValue ) } < /span>, currency : ( { columnValue : colValue } ) => ( < span > { tryParseCurrency ( colValue , '' ) } < /span>), tags : ( props ) => < TagsColumn { ... props } / > } ; param item param column param props export function renderItemColumn ( item , column , props ) { const columnValue = item [ column . fieldName ] ; if ( ! columnValue ) return null ; switch ( column . fieldName ) { case 'Title' : { return < TitleColumn props = { props } item = { item } / > ; } } if ( renderDataTypeMap [ column . dataType ] ) { return renderDataTypeMap [ column . dataType ] ( { column , columnValue } ) ; } const config = column . config ? column . config [ columnValue ] : null ; if ( config ) { return ( < span > < Icon iconName = { config . iconName } style = { { color : config . color , marginRight : 4 } } /> < span > { columnValue } < /span> < /span>); } return < span > { columnValue } < /span>; }