import { renderActionsAsColumn , renderFlag , renderTagsWithClickHandler , TagClickHandler } from './mappers' ; import { ColumnType } from 'antd/lib/table' ; import { ReactNode } from 'react-markdown' ; export type ColumnConfiguration < RecordType > = { title : string | ReactNode ; dataIndex : string ; key ? : string ; configuration ? : ColumnType < RecordType > ; } ; export function addColumn < RecordType > ( { title , dataIndex , key , configuration , } ) { return { title , dataIndex , key , ellipsis : true , ... configuration , } ; } export function addNumColumn < RecordType > ( { title , dataIndex , key , configuration , } ) { if ( ! configuration ) configuration = { } ; if ( ! configuration . render ) configuration . render = ( num ) => Intl . NumberFormat ( ) . format ( num ) ; configuration . align = 'right' ; return { title , dataIndex , key , ellipsis : true , ... configuration , } ; } export function addFlagColumn < RecordType > ( configuration ) { return { ... addColumn ( configuration ) , ... { render : renderFlag , } , } ; } export function addTagsColumn < RecordType > ( configuration , onActionClick ) { return { ... addColumn ( configuration ) , ... { className : 'tags' , render : renderTagsWithClickHandler ( onActionClick ) , } , } ; } export function addActionsColumn < RecordType > ( configuration , { width , getComponent , } ) { return { ... addColumn ( configuration ) , ... renderActionsAsColumn < RecordType > ( width ) ( getComponent ) , } ; }