All files / app/src/features/measure/lib get-measures-table-columns.tsx

1.26% Statements 2/158
100% Branches 0/0
0% Functions 0/1
1.26% Lines 2/158

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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 1931x                             1x                                                                                                                                                                                                                                                                                                                                                                  
import { Nullable, TFunction } from '@/shared/@types'
import { RESET } from 'jotai/utils'
import { SetStateAction } from 'react'
import { Column } from 'rc-table'
import { Checkbox, Tooltip } from '@/shared/ui'
import { MeasurePipe } from '@/features/measure'
import { TableCellInfo, TableSort } from '@tmk/ui-kit'
import dayjs from 'dayjs'
import { DEFAULT_DATE_FORMAT } from '@/shared/config'
import { DocumentFile } from '@/entities/change-log'
import InfoIcon from '@/shared/assets/icons/common/passport.svg'
import { getIdFromIRI } from '@/shared/helpers'
import { getFileFromFiles } from '@/entities/files'
import { FileModel } from '@/shared/@types'
 
export const getMeasuresTableColumns = ({
  t,
  ordersSort,
  setOrdersSort,
  setSelectedOperation,
  selectedMeasures,
  dataLength,
  files,
  isFilesLoading,
}: {
  t: TFunction
  ordersSort: Nullable<string>
  setOrdersSort: (update: typeof RESET | SetStateAction<Nullable<string>>) => void
  setSelectedOperation?: (checked: boolean, type: 'operation' | 'all', id?: string) => void
  selectedMeasures: string[]
  dataLength: number
  files?: FileModel[]
  isFilesLoading?: boolean
}) => {
  return (
    <>
      <Column
        title={
          <Checkbox
            name='all'
            onChange={e => {
              setSelectedOperation?.(e.target.checked, 'all')
            }}
            checked={selectedMeasures?.length === dataLength}
          />
        }
        key='selected'
        render={(measure: MeasurePipe) => (
          <Checkbox
            name={measure.id}
            onChange={e => {
              setSelectedOperation?.(e.target.checked, 'operation', measure.id)
            }}
            checked={selectedMeasures?.includes(measure.id)}
          />
        )}
        width={50}
        onCell={() => ({
          onClick: e => {
            e.stopPropagation()
          },
        })}
      />
      <Column
        title={<span className='text-min-semibold'>{t('accounting-object:Warehouse')}</span>}
        width={120}
        render={(measure: MeasurePipe) => (
          <TableCellInfo className='text-min'>{measure?.warehouse?.name}</TableCellInfo>
        )}
      />
      <Column
        title={<span className='text-min-semibold'>{t('accounting-object:Client')}</span>}
        width={120}
        render={(measure: MeasurePipe) => (
          <TableCellInfo className='text-min'>{measure?.warehouseContract?.contract?.client?.name}</TableCellInfo>
        )}
      />
      <Column
        title={<span className='text-min-semibold'>{t('accounting-object:Measure_name')}</span>}
        width={120}
        render={(measure: MeasurePipe) => (
          <div className='flex flex-col gap-y-2.5'>
            <span className='text-min-semibold'>{measure?.name}</span>
            {measure.status === 'blocked' && (
              <div className='flex items-center gap-x-2.5'>
                <Tooltip
                  isActive={measure.status === 'blocked'}
                  label={t('The objects have been modified to this extent.')}
                >
                  <InfoIcon className='fill-red stroke-red' />
                </Tooltip>
                <span className='text-min text-red'>{t('Blocked_objects_changed')}</span>
              </div>
            )}
            <span className='text-min'>
              {t('Deposit')}:<span className='text-min-semibold'>{measure?.deposit?.name}</span>
            </span>
            <span className='text-min'>
              {t('Bush')}:<span className='text-min-semibold'>{measure?.bush?.number}</span>
            </span>
            <span className='text-min'>
              {t('well')}:<span className='text-min-semibold'>{measure?.well?.number}</span>
            </span>
          </div>
        )}
      />
      <Column
        title={<span className='text-min-semibold'>{t('accounting-object:Accounting_type')}</span>}
        width={260}
        render={(measure: MeasurePipe) => (
          <div className='flex flex-col gap-y-2.5'>
            {measure?.metadata?.sortament?.map(sortament => (
              <div className='flex flex-col gap-y-2.5' key={sortament?.sortName}>
                <h2>{t(`accounting-object:${sortament?.pipeType}`)}</h2>
                <h2 className='text-main'>{sortament?.sortName}</h2>
              </div>
            ))}
          </div>
        )}
      />
      <Column
        title={<span className='text-min-semibold'>{t('accounting-object:Result')}</span>}
        width={320}
        render={(measure: MeasurePipe) => (
          <div className='flex flex-col gap-y-2.5'>
            <span className='text-min'>
              {t('Fact. length WITH LOSS OF LENGTH IN HIV.')}:{' '}
              <span className='text-min-semibold'>
                {measure?.actualLengthWithMakeUpLoss} {t('common:m')}
              </span>
            </span>
            <span className='text-min'>
              {t('Fact. length WITHOUT LOSS OF LENGTH WHEN SCREWING.')}:{' '}
              <span className='text-min-semibold'>
                {measure?.actualLength} {t('common:m')}
              </span>
            </span>
            <span className='text-min'>
              {t('Fact_weight')}:{' '}
              <span className='text-min-semibold'>
                {measure?.actualWeight} {t('common:t')}
              </span>
            </span>
            <span className='text-min'>
              {t('Pipes_count')}:{' '}
              <span className='text-min-semibold'>
                {measure?.itemsCount} {t('common:pcs')}
              </span>
            </span>
          </div>
        )}
      />
      <Column
        title={<span className='text-min-semibold'>{t('common:File')}</span>}
        width={100}
        render={(measure: MeasurePipe) => (
          <DocumentFile
            id={getIdFromIRI(measure?.file) as string}
            isNeedDocument={false}
            isFileFromParent
            fileFromParent={getFileFromFiles(files, measure.file)}
            isLoadingFileFromParent={isFilesLoading}
          />
        )}
        onCell={() => ({
          onClick: e => {
            e.preventDefault()
            e.stopPropagation()
          },
        })}
      />
      <Column
        title={
          <TableSort
            className='!text-black !text-min-semibold'
            field='date'
            value={ordersSort}
            onChange={setOrdersSort}
            title={t('Date of operation')}
          />
        }
        width={180}
        render={(measure: MeasurePipe) => dayjs(measure?.date).format(DEFAULT_DATE_FORMAT)}
      />
      <Column
        title={<span className='text-min-semibold'>{t('accounting-object:responsible_person')}</span>}
        width={110}
        render={(measure: MeasurePipe) => <TableCellInfo>{measure?.performedBy?.displayName}</TableCellInfo>}
      />
    </>
  )
}