import { FC, ReactNode } from 'react'; import { isEmpty } from 'ramda'; import classNames from 'classnames'; import { SelectedServer } from '../servers/data'; import { ShortUrlsList as ShortUrlsListState } from './reducers/shortUrlsList'; import { ShortUrlsRowProps } from './helpers/ShortUrlsRow'; import { OrderableFields, ShortUrlsListParams } from './reducers/shortUrlsListParams'; import './ShortUrlsTable.scss'; export interface ShortUrlsTableProps { orderByColumn?: (column: OrderableFields) => () => void; renderOrderIcon?: (column: OrderableFields) => ReactNode; shortUrlsList: ShortUrlsListState; selectedServer: SelectedServer; refreshList?: Function; shortUrlsListParams?: ShortUrlsListParams; className?: string; } export const ShortUrlsTable = (ShortUrlsRow: FC) => ({ orderByColumn, renderOrderIcon, shortUrlsList, refreshList, shortUrlsListParams, selectedServer, className, }: ShortUrlsTableProps) => { const { error, loading, shortUrls } = shortUrlsList; const orderableColumnsClasses = classNames('short-urls-table__header-cell', { 'short-urls-table__header-cell--with-action': !!orderByColumn, }); const tableClasses = classNames('table table-striped table-hover', className); const renderShortUrls = () => { if (error) { return ( Something went wrong while loading short URLs :( ); } if (loading) { return Loading...; } if (!loading && isEmpty(shortUrlsList)) { return No results found; } return shortUrls?.data.map((shortUrl) => ( )); }; return ( {renderShortUrls()}
{renderOrderIcon?.('dateCreated')} Created at {renderOrderIcon?.('shortCode')} Short URL {renderOrderIcon?.('longUrl')} Long URL Tags {renderOrderIcon?.('visits')} Visits  
); };