All files / app/src/entities/accounting-object-import/ui/import-table get-import-table.tsx

77.06% Statements 84/109
100% Branches 1/1
9.09% Functions 1/11
77.06% Lines 84/109

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 1341x                   1x 2x 2x   2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x                     2x 2x 2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x                       2x 2x 2x 2x                   2x 2x    
import { Button, DEFAULT_DATE_FORMAT, File, FileModel, TableCellInfo } from '@tmk/ui-kit'
import { Import, ImportStatus, ImportStatusEnum, Initiator } from '@/entities/accounting-object-import'
import { TFunction } from '@/shared/@types'
import { Column } from 'rc-table'
import cn from 'classnames'
import dayjs from 'dayjs'
import TrashIcon from '@/shared/assets/icons/common/TrashIcon.svg'
import EditIcon from '@/shared/assets/icons/common/edit.svg'
import { ACCOUNTING_OBJECTS_PAGE } from '../../../accounting-object'
 
export const getImportTableColumns = (
  t: TFunction,
  handleDelete: (id: string, status: ImportStatusEnum | undefined) => void
) => (
  <>
    <Column
      title={
        <TableCellInfo className='pl-4 text-min-semibold !text-black'>{t('accounting-object:Status')}</TableCellInfo>
      }
      dataIndex='status'
      key='status'
      width={140}
      render={(status: ImportStatusEnum) => (status ? <ImportStatus className='ml-4' status={status} /> : '-')}
    />
    <Column
      title={
        <TableCellInfo className='text-min-semibold !text-black inline-block w-16 whitespace-pre-wrap'>
          {t('accounting-object:Import_date')}
        </TableCellInfo>
      }
      dataIndex='dateUpdate'
      key='dateUpdate'
      width={100}
      render={(dateUpdate: string) => <TableCellInfo>{dayjs(dateUpdate).format(DEFAULT_DATE_FORMAT)}</TableCellInfo>}
    />
    <Column
      title={
        <TableCellInfo className='text-min-semibold !text-black inline-block w-20 whitespace-pre-wrap'>
          {t('Last_change')}
        </TableCellInfo>
      }
      dataIndex='dateUpdate'
      key='dateUpdate'
      width={100}
      render={(dateUpdate: string) => <TableCellInfo>{dayjs(dateUpdate).format(DEFAULT_DATE_FORMAT)}</TableCellInfo>}
    />
    <Column
      title={
        <TableCellInfo className='text-min-semibold !text-black'>
          {t('accounting-object:Accounting_type')}
        </TableCellInfo>
      }
      width={250}
      render={(record: Import) => (
        <div className='flex flex-col justify-center items-start'>
          <span>
            {record?.accountingObjectType && t('accounting-object:' + record?.accountingObjectType)}{' '}
            {record?.manufacturer?.manufacturerCompany?.name}
          </span>
          <span>
            {`⌀${record?.diameter?.value} - ${record?.side?.value} - ${record?.strengthGroup?.name} - ${record?.connection?.name}`}
          </span>
        </div>
      )}
    />
    <Column
      title={
        <TableCellInfo className='text-min-semibold !text-black inline-block w-20 whitespace-pre-wrap'>
          {t('Processed_successfully')}
        </TableCellInfo>
      }
      dataIndex='successCount'
      key='successCount'
      width={120}
      render={(successCount: number) => <TableCellInfo>{successCount}</TableCellInfo>}
    />
    <Column
      title={
        <TableCellInfo className='text-min-semibold !text-black inline-block w-24 whitespace-pre-wrap'>
          {t('Processed_with_error')}
        </TableCellInfo>
      }
      dataIndex='errorCount'
      key='errorCount'
      width={120}
      render={(errorCount: number) => <span className={cn({ 'text-red': errorCount })}>{errorCount || '-'}</span>}
    />
    <Column
      title={<TableCellInfo className='text-min-semibold !text-black'>{t('User')}</TableCellInfo>}
      dataIndex='initiator'
      key='initiator'
      width={100}
      render={(initiator: Initiator) => <TableCellInfo>{initiator?.displayName}</TableCellInfo>}
    />
    <Column
      title={<TableCellInfo className='text-min-semibold !text-black'>{t('File')}</TableCellInfo>}
      dataIndex='file'
      key='file'
      width={200}
      render={(file: FileModel) =>
        file && <File file={file} t={t} truncateMaxWidth={170} truncateClassName='truncate !line-clamp-none !block' />
      }
    />
    <Column
      width={40}
      render={record => (
        <Button
          variant='icon'
          href={
            ImportStatusEnum.SUCCESS === record.status
              ? `${ACCOUNTING_OBJECTS_PAGE}/pipes/edit?accountingObjectImport=${record.id}`
              : `/imports/${record.id}/edit`
          }
        >
          <EditIcon className='fill-blue-dark' />
        </Button>
      )}
    />
    <Column
      width={40}
      render={(record: Import) => (
        <Button
          variant='icon'
          onClick={() => {
            handleDelete(record['@id'], record?.status)
          }}
        >
          <TrashIcon className='fill-blue-dark' />
        </Button>
      )}
    />
  </>
)