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 | 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | import { FileModel, TableCellInfo, TableSort } from '@tmk/ui-kit'
import { Nullable, TFunction } from '@/shared/@types'
import { Column } from 'rc-table'
import dayjs from 'dayjs'
import { ChangeLogItem, ChangeLogValue, NewValue } from '@/entities/change-log'
import { ASC_CHANGELOG_COLLECTION_ORDER, DEFAULT_CHANGELOG_COLLECTION_ORDER } from '../../lib/constants'
import { ChangeLogOperationEnum } from '../../lib/types'
import { DATE_WITH_TIME_FORMAT } from '@/shared/config'
import { reorderObjectFields } from '@/shared/helpers'
import { getJournalOperationOrder } from '@/entities/pipe'
import { Document } from '@/entities/documents'
import { getTwoStatesSort } from '@/shared/lib'
import { RESET } from 'jotai/utils'
import { SetStateAction } from 'jotai'
export const getChangeLogTableColumns = ({
t,
sort,
setSort,
files,
isFilesLoading,
documents,
isLoadingDocuments,
}: {
t: TFunction
sort: Nullable<string>
setSort: (update: typeof RESET | SetStateAction<Nullable<string>>) => void
files?: FileModel[]
isFilesLoading?: boolean
documents?: Document[]
isLoadingDocuments?: boolean
}) => (
<>
<Column
title={
<TableSort
defaultSort={DEFAULT_CHANGELOG_COLLECTION_ORDER}
className='pl-8 text-min-semibold !text-black'
field='loggedAt'
value={sort}
onChange={() =>
setSort(prev =>
getTwoStatesSort(
prev,
DEFAULT_CHANGELOG_COLLECTION_ORDER,
ASC_CHANGELOG_COLLECTION_ORDER,
'order[loggedAt]'
)
)
}
title={t('Date and time')}
/>
}
width={100}
render={(operation: ChangeLogItem) => (
<TableCellInfo className='block h-full pt-4 align-baseline'>
{dayjs(operation.loggedAt).format(DATE_WITH_TIME_FORMAT)}
</TableCellInfo>
)}
/>
<Column
title={
<TableCellInfo className='text-min-semibold !text-black inline-block w-20 whitespace-pre-wrap'>
{t('Operation')}
</TableCellInfo>
}
dataIndex='action'
key='action'
width={100}
render={(action: string) => (
<TableCellInfo className='block h-full pt-4 align-baseline'>{t(action)}</TableCellInfo>
)}
/>
<Column
title={<TableCellInfo className='text-min-semibold !text-black'>{t('User')}</TableCellInfo>}
width={150}
dataIndex='displayName'
key='displayName'
render={(displayName: string) => (
<TableCellInfo className='block h-full pt-4 align-baseline'>{displayName}</TableCellInfo>
)}
/>
<Column
title={
<TableCellInfo className='text-min-semibold !text-black inline-block whitespace-pre-wrap'>
{t('New Value')}
</TableCellInfo>
}
width={250}
render={(operation: ChangeLogItem) => {
const operationFieldsOrders = getJournalOperationOrder(operation.action as ChangeLogOperationEnum)
return ChangeLogOperationEnum.ACTION_CREATE === operation.action ? (
t('Object has been uploaded to the system')
) : (
<ChangeLogValue
value={
operationFieldsOrders
? (reorderObjectFields(operation.data, operationFieldsOrders) as NewValue)
: (operation.data as NewValue)
}
t={t}
files={files}
isFilesLoading={isFilesLoading}
documents={documents}
isLoadingDocuments={isLoadingDocuments}
/>
)
}}
/>
<Column
title={<TableCellInfo className='text-min-semibold !text-black'>{t('Old Value')}</TableCellInfo>}
width={200}
render={(operation: ChangeLogItem) => {
const operationFieldsOrders = getJournalOperationOrder(operation.action as ChangeLogOperationEnum)
return (
<ChangeLogValue
value={
operationFieldsOrders
? (reorderObjectFields(operation.lastData, operationFieldsOrders) as NewValue)
: (operation.lastData as NewValue)
}
t={t}
files={files}
isFilesLoading={isFilesLoading}
documents={documents}
isLoadingDocuments={isLoadingDocuments}
/>
)
}}
/>
</>
)
|