import { FC, ReactNode } from 'react'; import { isEmpty } from 'ramda'; import classNames from 'classnames'; import { SelectedServer } from '../servers/data'; import { supportsShortUrlTitle } from '../utils/helpers/features'; import { ShortUrlsList as ShortUrlsListState } from './reducers/shortUrlsList'; import { ShortUrlsRowProps } from './helpers/ShortUrlsRow'; import { ShortUrlsOrderableFields } from './data'; import './ShortUrlsTable.scss'; export interface ShortUrlsTableProps { orderByColumn?: (column: ShortUrlsOrderableFields) => () => void; renderOrderIcon?: (column: ShortUrlsOrderableFields) => ReactNode; shortUrlsList: ShortUrlsListState; selectedServer: SelectedServer; onTagClick?: (tag: string) => void; className?: string; } export const ShortUrlsTable = (ShortUrlsRow: FC) => ({ orderByColumn, renderOrderIcon, shortUrlsList, onTagClick, selectedServer, 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', className); const supportsTitle = supportsShortUrlTitle(selectedServer); 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 ( {!supportsTitle ? ( ) : ( )} {renderShortUrls()}
Created at {renderOrderIcon?.('dateCreated')} Short URL {renderOrderIcon?.('shortCode')} Long URL {renderOrderIcon?.('longUrl')} Title {renderOrderIcon?.('title')}   /   Long URL {renderOrderIcon?.('longUrl')} Tags Visits {renderOrderIcon?.('visits')}  
); };