import React from 'react' import {Button, Panel, PanelHeading, PanelBlock} from 'bloomer' import {FaPlus, FaEdit, FaTimes} from 'react-icons/fa' import {Link} from '../components' export interface ICRUDListProps { nameKey: keyof T editLink?: (item: T) => string itemIds: ReadonlyArray itemsById: Record newLink?: string onRemove?: (t: T) => void title: string Info?: React.ComponentType> RowButtons?: React.ComponentType> } export interface ICRUDRowButtons { item: T } export interface ICRUDItemRowProps { Info?: React.ComponentType> RowButtons?: React.ComponentType> nameKey: keyof T editLink?: string item: T onRemove?: (t: T) => void } export interface ICRUDItemInfoProps { item: T nameKey: keyof T } export class CRUDItemInfo extends React.PureComponent> { render() { const {item, nameKey} = this.props return {item[nameKey]} } } export class CRUDItemRow extends React.PureComponent> { handleRemove = () => { const {onRemove, item} = this.props if (onRemove) { onRemove(item) } } render() { const {nameKey, editLink, item} = this.props return (
{this.props.Info ? : item={item} nameKey={nameKey} /> }
{!!this.props.RowButtons && ( )}   {!!editLink && ( )}   {!!this.props.onRemove && ( )}
) } } export class CRUDList extends React.PureComponent> { render() { const {nameKey, editLink, itemIds, itemsById, newLink, title} = this.props return ( {title} {!!newLink && (   New )} {itemIds.map(itemId => { const item = itemsById[itemId] return ( Info={this.props.Info} RowButtons={this.props.RowButtons} nameKey={nameKey} editLink={editLink && editLink(item)} item={item} onRemove={this.props.onRemove} /> ) })} ) } }