forked from ddrilling/asb_cloud_front
* Исправлена обработка методов в EditableTable
* Удалено лишнее использование Menu.Item * Добавлена обработка прав категорий в Documents
This commit is contained in:
parent
c2338c98ab
commit
8f5b48355d
@ -19,10 +19,8 @@ export type PrivateMenuLinkProps = Partial<ItemType> & Omit<LinkProps, 'to'> & R
|
|||||||
permissions?: string[]
|
permissions?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PrivateMenuLink = memo<PrivateMenuLinkProps>(({ content, danger, icon, path = '', title, ...other }) => (
|
export const PrivateMenuLink = memo<PrivateMenuLinkProps>(({ content, path = '', title, ...other }) => (
|
||||||
<Menu.Item icon={icon ?? content?.icon} danger={danger}>
|
<Link to={path} {...other}>{title ?? content?.title}</Link>
|
||||||
<Link to={path} {...other}>{title ?? content?.title}</Link>
|
|
||||||
</Menu.Item>
|
|
||||||
))
|
))
|
||||||
|
|
||||||
const PrivateMenuMain = memo<PrivateMenuProps>(({ selectable, mode, selectedKeys, root, children, ...other }) => {
|
const PrivateMenuMain = memo<PrivateMenuProps>(({ selectable, mode, selectedKeys, root, children, ...other }) => {
|
||||||
@ -55,7 +53,6 @@ const PrivateMenuMain = memo<PrivateMenuProps>(({ selectable, mode, selectedKeys
|
|||||||
if (visible || hasPermission(permissions))
|
if (visible || hasPermission(permissions))
|
||||||
return {
|
return {
|
||||||
...child.props,
|
...child.props,
|
||||||
icon: null,
|
|
||||||
key,
|
key,
|
||||||
label: <PrivateMenuLink {...child.props} path={path} />,
|
label: <PrivateMenuLink {...child.props} path={path} />,
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,9 @@ export const EditableTable = memo(({
|
|||||||
const [data, setData] = useState(tryAddKeys(dataSource))
|
const [data, setData] = useState(tryAddKeys(dataSource))
|
||||||
const [editingKey, setEditingKey] = useState('')
|
const [editingKey, setEditingKey] = useState('')
|
||||||
|
|
||||||
const onAdd = useMemo(() => typeof onRowAdd === 'function' ? onRowAdd : makeTableAction(onRowAdd), [onRowAdd])
|
const onAdd = useMemo(() => onRowAdd && typeof onRowAdd !== 'function' ? makeTableAction(onRowAdd) : onRowAdd, [onRowAdd])
|
||||||
const onEdit = useMemo(() => typeof onRowEdit === 'function' ? onRowEdit : makeTableAction(onRowEdit), [onRowEdit])
|
const onEdit = useMemo(() => onRowEdit && typeof onRowEdit !== 'function' ? makeTableAction(onRowEdit) : onRowEdit, [onRowEdit])
|
||||||
const onDelete = useMemo(() => typeof onRowDelete === 'function' ? onRowDelete : makeTableAction(onRowDelete), [onRowDelete])
|
const onDelete = useMemo(() => onRowDelete && typeof onRowDelete !== 'function' ? makeTableAction(onRowDelete) : onRowDelete, [onRowDelete])
|
||||||
|
|
||||||
const isEditing = useCallback((record) => record?.key === editingKey, [editingKey])
|
const isEditing = useCallback((record) => record?.key === editingKey, [editingKey])
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import { UploadForm } from '@components/UploadForm'
|
|||||||
import { CompanyView, UserView } from '@components/views'
|
import { CompanyView, UserView } from '@components/views'
|
||||||
import { invokeWebApiWrapperAsync, downloadFile, formatBytes } from '@components/factory'
|
import { invokeWebApiWrapperAsync, downloadFile, formatBytes } from '@components/factory'
|
||||||
import { EditableTable, makeColumn, makeDateColumn, makeNumericColumn, makePaginationObject } from '@components/Table'
|
import { EditableTable, makeColumn, makeDateColumn, makeNumericColumn, makePaginationObject } from '@components/Table'
|
||||||
|
import { unique } from '@utils/filters'
|
||||||
import { hasPermission } from '@utils'
|
import { hasPermission } from '@utils'
|
||||||
import { FileService } from '@api'
|
import { FileService } from '@api'
|
||||||
|
|
||||||
@ -46,8 +47,8 @@ export const DocumentsTemplate = ({ idCategory, idWell: wellId, mimeTypes, heade
|
|||||||
const uploadUrl = useMemo(() => `/api/well/${idWell}/files/?idCategory=${idCategory}`, [idWell, idCategory])
|
const uploadUrl = useMemo(() => `/api/well/${idWell}/files/?idCategory=${idCategory}`, [idWell, idCategory])
|
||||||
|
|
||||||
const mergedColumns = useMemo(() => [...columns, ...(customColumns ?? [])], [customColumns])
|
const mergedColumns = useMemo(() => [...columns, ...(customColumns ?? [])], [customColumns])
|
||||||
const companies = useMemo(() => [...new Set(files.map(file => file.company))].filter(company => company), [files])
|
const companies = useMemo(() => files.map(file => file?.author?.company?.caption).filter(Boolean).filter(unique), [files])
|
||||||
const filenames = useMemo(() => [...new Set(files.map(file => file.name))].filter(name => name), [files])
|
const filenames = useMemo(() => files.map(file => file.name).filter(Boolean).filter(unique), [files])
|
||||||
|
|
||||||
const update = useCallback(() => {
|
const update = useCallback(() => {
|
||||||
let begin = null
|
let begin = null
|
||||||
|
@ -11,17 +11,19 @@ import DocumentsTemplate from './DocumentsTemplate'
|
|||||||
|
|
||||||
const { Content } = Layout
|
const { Content } = Layout
|
||||||
|
|
||||||
|
const makeDocCat = (id, key, title, permissions = ['File.get']) => ({ id, key, title, permissions })
|
||||||
|
|
||||||
export const documentCategories = [
|
export const documentCategories = [
|
||||||
{ id: 1, key: 'fluidService', title: 'Растворный сервис' },
|
makeDocCat(1 , 'fluidService' , 'Растворный сервис' ),
|
||||||
{ id: 2, key: 'cementing', title: 'Цементирование' },
|
makeDocCat(2 , 'cementing' , 'Цементирование' ),
|
||||||
{ id: 3, key: 'nnb', title: 'ННБ' },
|
makeDocCat(3 , 'nnb' , 'ННБ' ),
|
||||||
{ id: 4, key: 'gti', title: 'ГТИ' },
|
makeDocCat(4 , 'gti' , 'ГТИ' ),
|
||||||
{ id: 5, key: 'documentsForWell', title: 'Документы по скважине' },
|
makeDocCat(5 , 'documentsForWell', 'Документы по скважине' ),
|
||||||
{ id: 6, key: 'supervisor', title: 'Супервайзер' },
|
makeDocCat(6 , 'supervisor' , 'Супервайзер' ),
|
||||||
{ id: 7, key: 'master', title: 'Мастер' },
|
makeDocCat(7 , 'master' , 'Мастер' ),
|
||||||
{ id: 8, key: 'toolService', title: 'Долотный сервис' },
|
makeDocCat(8 , 'toolService' , 'Долотный сервис' ),
|
||||||
{ id: 9, key: 'drillService', title: 'Буровой подрядчик' },
|
makeDocCat(9 , 'drillService' , 'Буровой подрядчик' ),
|
||||||
{ id: 9, key: 'closingService', title: 'Сервис по заканчиванию скважины' },
|
makeDocCat(10, 'closingService' , 'Сервис по заканчиванию скважины'),
|
||||||
]
|
]
|
||||||
|
|
||||||
const MenuDocuments = memo(() => {
|
const MenuDocuments = memo(() => {
|
||||||
@ -35,9 +37,9 @@ const MenuDocuments = memo(() => {
|
|||||||
{documentCategories.map(category => (
|
{documentCategories.map(category => (
|
||||||
<PrivateMenu.Link
|
<PrivateMenu.Link
|
||||||
key={`${category.key}`}
|
key={`${category.key}`}
|
||||||
className={'ant-menu-item'}
|
|
||||||
icon={<FolderOutlined/>}
|
icon={<FolderOutlined/>}
|
||||||
title={category.title}
|
title={category.title}
|
||||||
|
permissions={category.permissions}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</PrivateMenu>
|
</PrivateMenu>
|
||||||
|
Loading…
Reference in New Issue
Block a user