import classNames from 'classnames'; import { isEmpty } from 'ramda'; import type { ReactNode } from 'react'; import type { ShortUrlsOrderableFields } from './data'; import type { ShortUrlsRowType } from './helpers/ShortUrlsRow'; import type { ShortUrlsList as ShortUrlsListState } from './reducers/shortUrlsList'; import './ShortUrlsTable.scss'; interface ShortUrlsTableProps { orderByColumn?: (column: ShortUrlsOrderableFields) => () => void; renderOrderIcon?: (column: ShortUrlsOrderableFields) => ReactNode; shortUrlsList: ShortUrlsListState; onTagClick?: (tag: string) => void; className?: string; } export const ShortUrlsTable = (ShortUrlsRow: ShortUrlsRowType) => ({ orderByColumn, renderOrderIcon, shortUrlsList, onTagClick, className, }: ShortUrlsTableProps) => { const { error, loading, shortUrls } = shortUrlsList; const actionableFieldClasses = classNames({ 'short-urls-table__header-cell--with-action': !!orderByColumn }); const orderableColumnsClasses = classNames('short-urls-table__header-cell', actionableFieldClasses); const tableClasses = classNames('table table-hover responsive-table short-urls-table', className); const renderShortUrls = () => { if (error) { return ( Something went wrong while loading short URLs :( ); } if (loading) { return Loading...; } if (!loading && isEmpty(shortUrls?.data)) { return No results found; } return shortUrls?.data.map((shortUrl) => ( )); }; return ( {renderShortUrls()}
Created at {renderOrderIcon?.('dateCreated')} Short URL {renderOrderIcon?.('shortCode')} Title {renderOrderIcon?.('title')}   /   Long URL {renderOrderIcon?.('longUrl')} Tags Visits {renderOrderIcon?.('visits')}
); }; export type ShortUrlsTableType = ReturnType;