Удалён метод makeActionHandler

This commit is contained in:
goodmice 2022-06-10 20:24:21 +05:00
parent 2ad4ac5b23
commit 69fc308352
14 changed files with 239 additions and 204 deletions

View File

@ -43,35 +43,6 @@ export const makeTableAction = ({
) )
) )
// TODO: Remove makeActionHandler
const actions2 = {
insert: (data) => [data],
insertRange: (data) => [[data].flat(1)],
update: (data) => data.id && [data.id, data],
delete: (data) => data.id && [data.id],
}
/**
* @deprecated используйте {@link makeTableAction}
*/
export const makeActionHandler = (action, { idWell, service, setLoader, errorMsg, onComplete }, recordParser, actionName) => service && action && (
(record) => invokeWebApiWrapperAsync(
async () => {
const addIdWell = (...params) => idWell ? [idWell, ...params] : params
if (typeof recordParser === 'function')
record = recordParser(record)
const params = actions2[action]?.(record)
if (params) await service[action](...addIdWell(...params))
await onComplete?.()
},
setLoader,
errorMsg,
actionName
)
)
export const tryAddKeys = (items) => { export const tryAddKeys = (items) => {
if (!items?.length || !items[0]) if (!items?.length || !items[0])
return [] return []

View File

@ -1,5 +1,5 @@
export { makeDateSorter, makeNumericSorter, makeStringSorter, makeTimeSorter } from './sorters' export { makeDateSorter, makeNumericSorter, makeStringSorter, makeTimeSorter } from './sorters'
export { EditableTable, makeActionHandler, makeTableAction } from './EditableTable' export { EditableTable, makeTableAction } from './EditableTable'
export { DatePickerWrapper } from './DatePickerWrapper' export { DatePickerWrapper } from './DatePickerWrapper'
export { TimePickerWrapper } from './TimePickerWrapper' export { TimePickerWrapper } from './TimePickerWrapper'
export { DateRangeWrapper } from './DateRangeWrapper' export { DateRangeWrapper } from './DateRangeWrapper'

View File

@ -5,14 +5,13 @@ import {
EditableTable, EditableTable,
makeColumn, makeColumn,
makeSelectColumn, makeSelectColumn,
makeActionHandler,
makeStringSorter, makeStringSorter,
defaultPagination, defaultPagination,
makeTimezoneColumn makeTimezoneColumn
} from '@components/Table' } from '@components/Table'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { AdminClusterService, AdminDepositService } from '@api' import { AdminClusterService, AdminDepositService } from '@api'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules' import { min1 } from '@utils/validationRules'
import { coordsFixed } from './DepositController' import { coordsFixed } from './DepositController'
@ -74,12 +73,20 @@ const ClusterController = memo(() => {
updateTable() updateTable()
}, [updateTable]) }, [updateTable])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminClusterService, const handlerProps = {
setLoader: setShowLoader, service: AdminClusterService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: updateTable, onComplete: updateTable,
}), [updateTable]) permission: 'AdminCluster.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление куста' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование куста' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление куста', permission: 'AdminCluster.delete' },
}
}, [updateTable])
return ( return (
<> <>
@ -97,9 +104,9 @@ const ClusterController = memo(() => {
columns={clusterColumns} columns={clusterColumns}
dataSource={filteredClusters} dataSource={filteredClusters}
pagination={defaultPagination} pagination={defaultPagination}
onRowAdd={hasPermission('AdminCluster.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление куста')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminCluster.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование куста')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminCluster.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление куста')} onRowDelete={tableHandlers.delete}
tableName={'admin_cluster_controller'} tableName={'admin_cluster_controller'}
/> />
</> </>

View File

@ -4,14 +4,13 @@ import { Input } from 'antd'
import { import {
EditableTable, EditableTable,
makeColumn, makeColumn,
makeActionHandler,
makeStringSorter, makeStringSorter,
makeSelectColumn, makeSelectColumn,
defaultPagination defaultPagination
} from '@components/Table' } from '@components/Table'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { AdminCompanyService, AdminCompanyTypeService } from '@api' import { AdminCompanyService, AdminCompanyTypeService } from '@api'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules' import { min1 } from '@utils/validationRules'
const CompanyController = memo(() => { const CompanyController = memo(() => {
@ -58,17 +57,25 @@ const CompanyController = memo(() => {
) )
}, [updateTable]) }, [updateTable])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminCompanyService, const handlerProps = {
setLoader: setShowLoader, service: AdminCompanyService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: () => invokeWebApiWrapperAsync( onComplete: () => invokeWebApiWrapperAsync(
updateTable, updateTable,
setShowLoader, setShowLoader,
`Не удалось обновить список компаний`, `Не удалось обновить список компаний`,
'Получение списка компаний' 'Получение списка компаний'
), ),
}), [updateTable]) permission: 'AdminCompany.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление компании' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование компании' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление компании', permission: 'AdminCompany.delete' },
}
}, [updateTable])
return ( return (
<> <>
@ -86,9 +93,9 @@ const CompanyController = memo(() => {
loading={showLoader} loading={showLoader}
dataSource={filteredCompanies} dataSource={filteredCompanies}
pagination={defaultPagination} pagination={defaultPagination}
onRowAdd={hasPermission('AdminCompany.edit') && makeActionHandler('insert', handlerProps, null, 'Добавлениее компаний')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminCompany.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование команий')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminCompany.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление компаний')} onRowDelete={tableHandlers.delete}
tableName={'admin_company_controller'} tableName={'admin_company_controller'}
/> />
</> </>

View File

@ -1,15 +1,9 @@
import { memo, useCallback, useEffect, useMemo, useState } from 'react' import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { Input } from 'antd' import { Input } from 'antd'
import { import { EditableTable, makeColumn, makeStringSorter, defaultPagination } from '@components/Table'
EditableTable,
makeColumn,
makeActionHandler,
makeStringSorter,
defaultPagination
} from '@components/Table'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules' import { min1 } from '@utils/validationRules'
import { AdminCompanyTypeService } from '@api' import { AdminCompanyTypeService } from '@api'
@ -45,12 +39,21 @@ const CompanyTypeController = memo(() => {
updateTable() updateTable()
}, [updateTable]) }, [updateTable])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminCompanyTypeService, const handlerProps = {
setLoader: setShowLoader, service: AdminCompanyTypeService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: updateTable, errorMsg: `Не удалось выполнить операцию`,
}), [updateTable]) onComplete: updateTable,
permission: 'AdminCompanyType.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление типа компаний' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование типа компаний' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление типа компаний', permission: 'AdminCompanyType.delete' },
}
}, [updateTable])
return ( return (
<> <>
@ -68,9 +71,9 @@ const CompanyTypeController = memo(() => {
loading={showLoader} loading={showLoader}
pagination={defaultPagination} pagination={defaultPagination}
dataSource={filteredCompanyTypes} dataSource={filteredCompanyTypes}
onRowAdd={hasPermission('AdminCompanyType.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление типа компаний')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminCompanyType.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование типа компаний')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminCompanyType.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление типа компаний')} onRowDelete={tableHandlers.delete}
tableName={'admin_company_type_controller'} tableName={'admin_company_type_controller'}
/> />
</> </>

View File

@ -2,8 +2,8 @@ import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { Input } from 'antd' import { Input } from 'antd'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { EditableTable, makeColumn, makeActionHandler, defaultPagination, makeTimezoneColumn } from '@components/Table' import { EditableTable, makeColumn, defaultPagination, makeTimezoneColumn } from '@components/Table'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules' import { min1 } from '@utils/validationRules'
import { AdminDepositService } from '@api' import { AdminDepositService } from '@api'
@ -42,12 +42,20 @@ const DepositController = memo(() => {
updateTable() updateTable()
}, [updateTable]) }, [updateTable])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminDepositService, const handlerProps = {
setLoader: setShowLoader, service: AdminDepositService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: updateTable, onComplete: updateTable,
}), [updateTable]) permission: 'AdminDeposit.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление месторождения' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование месторождения' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление месторождения', permission: 'AdminDeposit.delete' },
}
}, [updateTable])
return ( return (
<> <>
@ -65,9 +73,9 @@ const DepositController = memo(() => {
columns={depositColumns} columns={depositColumns}
dataSource={filteredDeposits} dataSource={filteredDeposits}
pagination={defaultPagination} pagination={defaultPagination}
onRowAdd={hasPermission('AdminDeposit.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление месторождения')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminDeposit.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование месторождения')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminDeposit.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление месторождения')} onRowDelete={tableHandlers.delete}
tableName={'admin_deposit_controller'} tableName={'admin_deposit_controller'}
/> />
</> </>

View File

@ -1,14 +1,9 @@
import { memo, useCallback, useEffect, useMemo, useState } from 'react' import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { Input } from 'antd' import { Input } from 'antd'
import { import { EditableTable, makeColumn, makeStringSorter } from '@components/Table'
EditableTable,
makeActionHandler,
makeColumn,
makeStringSorter
} from '@components/Table'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules' import { min1 } from '@utils/validationRules'
import { AdminPermissionService } from '@api' import { AdminPermissionService } from '@api'
@ -50,12 +45,20 @@ const PermissionController = memo(() => {
updateTable() updateTable()
}, [updateTable]) }, [updateTable])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminPermissionService, const handlerProps = {
setLoader: setShowLoader, service: AdminPermissionService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: updateTable onComplete: updateTable,
}), [updateTable]) permission: 'AdminPermission.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление разрешения' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование разрешения' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление разрешения', permission: 'AdminPermission.delete' },
}
}, [updateTable])
return ( return (
<> <>
@ -73,9 +76,9 @@ const PermissionController = memo(() => {
loading={showLoader} loading={showLoader}
dataSource={filteredPermissions} dataSource={filteredPermissions}
pagination={{ showSizeChanger: true }} pagination={{ showSizeChanger: true }}
onRowAdd={hasPermission('AdminPermission.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление права')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminPermission.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование права')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminPermission.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление права')} onRowDelete={tableHandlers.delete}
tableName={'admin_permission_controller'} tableName={'admin_permission_controller'}
/> />
</> </>

View File

@ -3,9 +3,9 @@ import { Input } from 'antd'
import { PermissionView, RoleView } from '@components/views' import { PermissionView, RoleView } from '@components/views'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { EditableTable, makeActionHandler, makeTagColumn, makeTextColumn } from '@components/Table' import { EditableTable, makeTagColumn, makeTextColumn } from '@components/Table'
import { AdminPermissionService, AdminUserRoleService } from '@api' import { AdminPermissionService, AdminUserRoleService } from '@api'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { min1 } from '@utils/validationRules' import { min1 } from '@utils/validationRules'
const RoleController = memo(() => { const RoleController = memo(() => {
@ -50,17 +50,25 @@ const RoleController = memo(() => {
) )
}, [loadRoles]) }, [loadRoles])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminUserRoleService, const handlerProps = {
setLoader: setShowLoader, service: AdminUserRoleService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: async () => invokeWebApiWrapperAsync( onComplete: async () => invokeWebApiWrapperAsync(
loadRoles, loadRoles,
setShowLoader, setShowLoader,
`Не удалось загрузить список ролей`, `Не удалось загрузить список ролей`,
'Получение списка ролей', 'Получение списка ролей',
) ),
}), [loadRoles]) permission: 'AdminUserRole.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление роли' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование роли' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление роли', permission: 'AdminUserRole.delete' },
}
}, [loadRoles])
return ( return (
<> <>
@ -77,9 +85,9 @@ const RoleController = memo(() => {
columns={columns} columns={columns}
loading={showLoader} loading={showLoader}
dataSource={filteredRoles} dataSource={filteredRoles}
onRowAdd={hasPermission('AdminUserRole.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление роли')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminUserRole.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование роли')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminUserRole.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление роли')} onRowDelete={tableHandlers.delete}
tableName={'admin_role_controller'} tableName={'admin_role_controller'}
/> />
</> </>

View File

@ -6,7 +6,6 @@ import { BehaviorSubject, debounceTime, distinctUntilChanged, filter, map } from
import { import {
EditableTable, EditableTable,
makeSelectColumn, makeSelectColumn,
makeActionHandler,
makeNumericSorter, makeNumericSorter,
defaultPagination, defaultPagination,
makeTextColumn makeTextColumn
@ -18,7 +17,7 @@ import { invokeWebApiWrapperAsync } from '@components/factory'
import { AdminCompanyService, AdminUserRoleService, AdminUserService } from '@api' import { AdminCompanyService, AdminUserRoleService, AdminUserService } from '@api'
import { createLoginRules, nameRules, phoneRules, emailRules } from '@utils/validationRules' import { createLoginRules, nameRules, phoneRules, emailRules } from '@utils/validationRules'
import { makeTextOnFilter, makeTextFilters, makeArrayOnFilter } from '@utils/filters' import { makeTextOnFilter, makeTextFilters, makeArrayOnFilter } from '@utils/filters'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import RoleTag from './RoleTag' import RoleTag from './RoleTag'
@ -175,12 +174,20 @@ const UserController = memo(() => {
) )
}, []) }, [])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminUserService, const handlerProps = {
setLoader: setShowLoader, service: AdminUserService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: updateTable, onComplete: updateTable,
}), [updateTable]) permission: 'AdminUser.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление пользователя' },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование пользователя' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление пользователя', permission: 'AdminUser.delete' },
}
}, [updateTable])
const onSearchTextChange = useCallback((e) => subject?.next(e?.target?.value), [subject]) const onSearchTextChange = useCallback((e) => subject?.next(e?.target?.value), [subject])
@ -199,9 +206,9 @@ const UserController = memo(() => {
bordered bordered
columns={columns} columns={columns}
dataSource={filteredUsers} dataSource={filteredUsers}
onRowAdd={hasPermission('AdminUser.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление пользователя')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminUser.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование пользователя')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminUser.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление пользователя')} onRowDelete={tableHandlers.delete}
additionalButtons={additionalButtons} additionalButtons={additionalButtons}
buttonsWidth={120} buttonsWidth={120}
pagination={defaultPagination} pagination={defaultPagination}

View File

@ -12,7 +12,6 @@ import {
EditableTable, EditableTable,
makeColumn, makeColumn,
makeSelectColumn, makeSelectColumn,
makeActionHandler,
makeStringSorter, makeStringSorter,
makeNumericSorter, makeNumericSorter,
makeTagColumn, makeTagColumn,
@ -22,7 +21,7 @@ import {
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { TelemetryView, CompanyView } from '@components/views' import { TelemetryView, CompanyView } from '@components/views'
import TelemetrySelect from '@components/selectors/TelemetrySelect' import TelemetrySelect from '@components/selectors/TelemetrySelect'
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { coordsFixed } from '../DepositController' import { coordsFixed } from '../DepositController'
@ -121,12 +120,20 @@ const WellController = memo(() => {
) )
}, [updateTable]) }, [updateTable])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: AdminWellService, const handlerProps = {
setLoader: setShowLoader, service: AdminWellService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: updateTable onComplete: updateTable,
}), [updateTable]) permission: 'AdminWell.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление скважины', recordParser },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование скважины', recordParser },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление скважины', permission: 'AdminWell.delete' },
}
}, [updateTable])
return ( return (
<> <>
@ -144,9 +151,9 @@ const WellController = memo(() => {
loading={showLoader} loading={showLoader}
dataSource={filteredWells} dataSource={filteredWells}
pagination={defaultPagination} pagination={defaultPagination}
onRowAdd={hasPermission('AdminWell.edit') && makeActionHandler('insert', handlerProps, recordParser, 'Добавление скважины')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('AdminWell.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование скважины')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('AdminWell.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление скважины')} onRowDelete={tableHandlers.delete}
//additionalButtons={addititonalButtons} //additionalButtons={addititonalButtons}
buttonsWidth={95} buttonsWidth={95}
tableName={'admin_well_controller'} tableName={'admin_well_controller'}

View File

@ -1,8 +1,7 @@
import { memo, useCallback, useMemo, useState } from 'react' import { memo, useCallback, useMemo, useState } from 'react'
import { Button, Modal } from 'antd' import { Button, Modal } from 'antd'
import { EditableTable, makeActionHandler, makeTextColumn } from '@components/Table' import { EditableTable, makeTextColumn } from '@components/Table'
import { getPermissions } from '@utils'
import { DrillerService } from '@api' import { DrillerService } from '@api'
const reqRule = [{ message: 'Обязательное поле!', required: true }] const reqRule = [{ message: 'Обязательное поле!', required: true }]
@ -19,8 +18,6 @@ export const DrillerList = memo(({ loading, drillers, onChange }) => {
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const [showModal, setShowModal] = useState(false) const [showModal, setShowModal] = useState(false)
const permissions = useMemo(() => getPermissions('Driller.edit', 'Driller.delete'), [])
const onModalOpen = useCallback(() => { const onModalOpen = useCallback(() => {
setShowModal(true) setShowModal(true)
}, []) }, [])
@ -29,18 +26,20 @@ export const DrillerList = memo(({ loading, drillers, onChange }) => {
setShowModal(false) setShowModal(false)
}, []) }, [])
const handlerProps = useMemo(() => ({ const tableHandlers = useMemo(() => {
service: DrillerService, const handlerProps = {
setLoader: setShowLoader, service: DrillerService,
errorMsg: `Не удалось выполнить операцию`, setLoader: setShowLoader,
onComplete: onChange, onComplete: onChange,
}), [onChange]) permission: 'Driller.edit'
}
const actionHandlers = useMemo(() => ({ return {
add: permissions.driller.edit && makeActionHandler('insert', handlerProps), add: { ...handlerProps, action: 'insert', actionName: 'Добавление бурильщика' },
edit: permissions.driller.edit && makeActionHandler('update', handlerProps), edit: { ...handlerProps, action: 'update', actionName: 'Редактирование бурильщика' },
delete: permissions.driller.delete && makeActionHandler('delete', handlerProps), delete: { ...handlerProps, action: 'delete', actionName: 'Удаление бурильщика', permission: 'Driller.delete' },
}), [permissions, handlerProps]) }
}, [updateTable])
return ( return (
<> <>
@ -60,9 +59,9 @@ export const DrillerList = memo(({ loading, drillers, onChange }) => {
dataSource={drillers} dataSource={drillers}
columns={columns} columns={columns}
scroll={{ y: '75vh', scrollToFirstRowOnChange: true }} scroll={{ y: '75vh', scrollToFirstRowOnChange: true }}
onRowAdd={actionHandlers.add} onRowAdd={tableHandlers.add}
onRowEdit={actionHandlers.edit} onRowEdit={tableHandlers.edit}
onRowDelete={actionHandlers.delete} onRowDelete={tableHandlers.delete}
rowClassName={rowClassName} rowClassName={rowClassName}
/> />
</Modal> </Modal>

View File

@ -7,11 +7,9 @@ import {
makeGroupColumn, makeGroupColumn,
makeDateColumn, makeDateColumn,
EditableTable, EditableTable,
makeActionHandler,
makeSelectColumn, makeSelectColumn,
} from '@components/Table' } from '@components/Table'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { getPermissions } from '@utils'
import { ScheduleService } from '@api' import { ScheduleService } from '@api'
const reqRule = [{ message: 'Обязательное поле!', required: true }] const reqRule = [{ message: 'Обязательное поле!', required: true }]
@ -23,8 +21,6 @@ export const DrillerSchedule = memo(({ drillers, loading, onChange }) => {
const idWell = useIdWell() const idWell = useIdWell()
const permissions = useMemo(() => getPermissions('Schedule.edit', 'Schedule.delete'), [])
const updateSchedule = useCallback(async () => invokeWebApiWrapperAsync( const updateSchedule = useCallback(async () => invokeWebApiWrapperAsync(
async () => { async () => {
const schedule = await ScheduleService.getByIdWell(idWell) const schedule = await ScheduleService.getByIdWell(idWell)
@ -44,20 +40,25 @@ export const DrillerSchedule = memo(({ drillers, loading, onChange }) => {
updateSchedule() updateSchedule()
}, [updateSchedule]) }, [updateSchedule])
const scheduleHandlerProps = useMemo(() => ({
service: ScheduleService,
setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`,
onComplete: updateSchedule,
}), [updateSchedule])
const newScheduleParser = useCallback((record) => ({ ...record, idWell }), [idWell]) const newScheduleParser = useCallback((record) => ({ ...record, idWell }), [idWell])
const actionHandlers = useMemo(() => ({ const tableHandlers = useMemo(() => {
add: permissions.schedule.edit && makeActionHandler('insert', scheduleHandlerProps, newScheduleParser), const handlerProps = {
edit: permissions.schedule.edit && makeActionHandler('update', scheduleHandlerProps), service: ScheduleService,
delete: permissions.schedule.delete && makeActionHandler('delete', scheduleHandlerProps), setLoader: setShowLoader,
}), [permissions, scheduleHandlerProps, newScheduleParser]) onComplete: () => {
updateSchedule()
onChange?.()
},
permission: 'Schedule.edit',
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление расписания', newScheduleParser },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование расписания' },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление расписания', permission: 'Schedule.delete' },
}
}, [updateSchedule, newScheduleParser])
const scheduleColumns = useMemo(() => { const scheduleColumns = useMemo(() => {
const options = drillers.map(({ id, name, surname, patronymic }) => ({ const options = drillers.map(({ id, name, surname, patronymic }) => ({
@ -104,9 +105,9 @@ export const DrillerSchedule = memo(({ drillers, loading, onChange }) => {
dataSource={schedule} dataSource={schedule}
columns={scheduleColumns} columns={scheduleColumns}
scroll={{ y: '75vh', scrollToFirstRowOnChange: true }} scroll={{ y: '75vh', scrollToFirstRowOnChange: true }}
onRowAdd={actionHandlers.add} onRowAdd={tableHandlers.add}
onRowEdit={actionHandlers.edit} onRowEdit={tableHandlers.edit}
onRowDelete={actionHandlers.delete} onRowDelete={tableHandlers.delete}
/> />
</Modal> </Modal>
<Button <Button

View File

@ -4,14 +4,13 @@ import { useIdWell } from '@asb/context'
import { import {
EditableTable, EditableTable,
makeSelectColumn, makeSelectColumn,
makeActionHandler,
makeNumericAvgRange, makeNumericAvgRange,
makeNumericSorter, makeNumericSorter,
} from '@components/Table' } from '@components/Table'
import LoaderPortal from '@components/LoaderPortal' import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { DrillParamsService, WellOperationService } from '@api' import { DrillParamsService, WellOperationService } from '@api'
import { hasPermission, arrayOrDefault } from '@utils' import { arrayOrDefault } from '@utils'
export const getColumns = async (idWell) => { export const getColumns = async (idWell) => {
@ -61,16 +60,23 @@ export const WellDrillParams = memo(() => {
})() })()
}, [idWell, updateParams]) }, [idWell, updateParams])
const handlerProps = useMemo(() => ({
service: DrillParamsService,
setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`,
onComplete: updateParams,
idWell
}), [idWell, updateParams])
const recordParser = useCallback((record) => ({ ...record, idWell }), [idWell]) const recordParser = useCallback((record) => ({ ...record, idWell }), [idWell])
const tableHandlers = useMemo(() => {
const handlerProps = {
service: DrillParamsService,
setLoader: setShowLoader,
onComplete: updateParams,
permission: 'DrillParams.edit'
}
return {
add: { ...handlerProps, action: 'insert', actionName: 'Добавление режима бурения', recordParser },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование режима бурения', recordParser },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление режима бурения', permission: 'DrillParams.delete' },
}
}, [updateParams, recordParser])
return ( return (
<LoaderPortal show={showLoader}> <LoaderPortal show={showLoader}>
<EditableTable <EditableTable
@ -79,9 +85,9 @@ export const WellDrillParams = memo(() => {
columns={columns} columns={columns}
dataSource={params} dataSource={params}
tableName={'well_drill_params'} tableName={'well_drill_params'}
onRowAdd={hasPermission('DrillParams.edit') && makeActionHandler('insert', handlerProps, recordParser, 'Добавление режима бурения')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('DrillParams.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование режима бурения')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('DrillParams.delete') && makeActionHandler('delete', handlerProps, recordParser, 'Удаление режима бурения')} onRowDelete={tableHandlers.delete}
pagination={false} pagination={false}
/> />
</LoaderPortal> </LoaderPortal>

View File

@ -9,7 +9,6 @@ import {
makeColumn, makeColumn,
makeNumericColumnOptions, makeNumericColumnOptions,
makeSelectColumn, makeSelectColumn,
makeActionHandler,
makeDateColumn, makeDateColumn,
makeNumericColumn, makeNumericColumn,
makeNumericRender, makeNumericRender,
@ -18,7 +17,7 @@ import {
} from '@components/Table' } from '@components/Table'
import LoaderPortal from '@components/LoaderPortal' import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { arrayOrDefault, wrapPrivateComponent, hasPermission } from '@utils' import { arrayOrDefault, wrapPrivateComponent } from '@utils'
import { WellOperationService } from '@api' import { WellOperationService } from '@api'
const { TextArea } = Input const { TextArea } = Input
@ -107,25 +106,34 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => {
updateOperations() updateOperations()
}, [updateOperations]) }, [updateOperations])
const handlerProps = useMemo(() => ({
service: WellOperationService,
setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`,
onComplete: updateOperations,
idWell
}), [idWell, updateOperations])
const onRow = useCallback((record) => { const onRow = useCallback((record) => {
if (selectedIds?.includes(record.id)) if (selectedIds?.includes(record.id))
return { style: { background: '#BF0000A0' } } return { style: { background: '#BF0000A0' } }
}, [selectedIds]) }, [selectedIds])
const recordParser = (record) => ({ const recordParser = useCallback((record) => ({
...record, ...record,
idType, idType,
wellDepth: +record.wellDepth, wellDepth: +record.wellDepth,
durationHours: +record.durationHours durationHours: +record.durationHours
}) }), [idType])
const tableHandlers = useMemo(() => {
const handlerProps = {
service: WellOperationService,
setLoader: setShowLoader,
onComplete: updateOperations,
permission: 'WellOperation.edit',
idRecord: true,
idWell,
}
return {
add: { ...handlerProps, action: 'insertRange', actionName: 'Добавление операции по скважине', recordParser },
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование операции по скважине', recordParser },
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление операции по скважине', permission: 'WellOperation.delete' },
}
}, [updateOperations, idWell, recordParser])
return ( return (
<LoaderPortal show={showLoader}> <LoaderPortal show={showLoader}>
@ -136,9 +144,9 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => {
columns={columns} columns={columns}
sticky={true} sticky={true}
dataSource={operations} dataSource={operations}
onRowAdd={hasPermission('WellOperation.edit') && makeActionHandler('insertRange', handlerProps, recordParser, 'Добавление операции по скважине')} onRowAdd={tableHandlers.add}
onRowEdit={hasPermission('WellOperation.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование операции по скважине')} onRowEdit={tableHandlers.edit}
onRowDelete={hasPermission('WellOperation.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление операции по скважине')} onRowDelete={tableHandlers.delete}
pagination={{ pagination={{
current: pageNumAndPageSize.current, current: pageNumAndPageSize.current,
pageSize: pageNumAndPageSize.pageSize, pageSize: pageNumAndPageSize.pageSize,