forked from ddrilling/asb_cloud_front
Удалён метод makeActionHandler
This commit is contained in:
parent
2ad4ac5b23
commit
69fc308352
@ -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) => {
|
||||
if (!items?.length || !items[0])
|
||||
return []
|
||||
|
@ -1,5 +1,5 @@
|
||||
export { makeDateSorter, makeNumericSorter, makeStringSorter, makeTimeSorter } from './sorters'
|
||||
export { EditableTable, makeActionHandler, makeTableAction } from './EditableTable'
|
||||
export { EditableTable, makeTableAction } from './EditableTable'
|
||||
export { DatePickerWrapper } from './DatePickerWrapper'
|
||||
export { TimePickerWrapper } from './TimePickerWrapper'
|
||||
export { DateRangeWrapper } from './DateRangeWrapper'
|
||||
|
@ -5,14 +5,13 @@ import {
|
||||
EditableTable,
|
||||
makeColumn,
|
||||
makeSelectColumn,
|
||||
makeActionHandler,
|
||||
makeStringSorter,
|
||||
defaultPagination,
|
||||
makeTimezoneColumn
|
||||
} from '@components/Table'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { AdminClusterService, AdminDepositService } from '@api'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { min1 } from '@utils/validationRules'
|
||||
|
||||
import { coordsFixed } from './DepositController'
|
||||
@ -74,12 +73,20 @@ const ClusterController = memo(() => {
|
||||
updateTable()
|
||||
}, [updateTable])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminClusterService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateTable,
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminClusterService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: 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 (
|
||||
<>
|
||||
@ -97,9 +104,9 @@ const ClusterController = memo(() => {
|
||||
columns={clusterColumns}
|
||||
dataSource={filteredClusters}
|
||||
pagination={defaultPagination}
|
||||
onRowAdd={hasPermission('AdminCluster.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление куста')}
|
||||
onRowEdit={hasPermission('AdminCluster.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование куста')}
|
||||
onRowDelete={hasPermission('AdminCluster.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление куста')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
tableName={'admin_cluster_controller'}
|
||||
/>
|
||||
</>
|
||||
|
@ -4,14 +4,13 @@ import { Input } from 'antd'
|
||||
import {
|
||||
EditableTable,
|
||||
makeColumn,
|
||||
makeActionHandler,
|
||||
makeStringSorter,
|
||||
makeSelectColumn,
|
||||
defaultPagination
|
||||
} from '@components/Table'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { AdminCompanyService, AdminCompanyTypeService } from '@api'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { min1 } from '@utils/validationRules'
|
||||
|
||||
const CompanyController = memo(() => {
|
||||
@ -58,17 +57,25 @@ const CompanyController = memo(() => {
|
||||
)
|
||||
}, [updateTable])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminCompanyService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: () => invokeWebApiWrapperAsync(
|
||||
updateTable,
|
||||
setShowLoader,
|
||||
`Не удалось обновить список компаний`,
|
||||
'Получение списка компаний'
|
||||
),
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminCompanyService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: () => invokeWebApiWrapperAsync(
|
||||
updateTable,
|
||||
setShowLoader,
|
||||
`Не удалось обновить список компаний`,
|
||||
'Получение списка компаний'
|
||||
),
|
||||
permission: 'AdminCompany.edit'
|
||||
}
|
||||
|
||||
return {
|
||||
add: { ...handlerProps, action: 'insert', actionName: 'Добавление компании' },
|
||||
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование компании' },
|
||||
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление компании', permission: 'AdminCompany.delete' },
|
||||
}
|
||||
}, [updateTable])
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -86,9 +93,9 @@ const CompanyController = memo(() => {
|
||||
loading={showLoader}
|
||||
dataSource={filteredCompanies}
|
||||
pagination={defaultPagination}
|
||||
onRowAdd={hasPermission('AdminCompany.edit') && makeActionHandler('insert', handlerProps, null, 'Добавлениее компаний')}
|
||||
onRowEdit={hasPermission('AdminCompany.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование команий')}
|
||||
onRowDelete={hasPermission('AdminCompany.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление компаний')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
tableName={'admin_company_controller'}
|
||||
/>
|
||||
</>
|
||||
|
@ -1,15 +1,9 @@
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { Input } from 'antd'
|
||||
|
||||
import {
|
||||
EditableTable,
|
||||
makeColumn,
|
||||
makeActionHandler,
|
||||
makeStringSorter,
|
||||
defaultPagination
|
||||
} from '@components/Table'
|
||||
import { EditableTable, makeColumn, makeStringSorter, defaultPagination } from '@components/Table'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { min1 } from '@utils/validationRules'
|
||||
import { AdminCompanyTypeService } from '@api'
|
||||
|
||||
@ -45,12 +39,21 @@ const CompanyTypeController = memo(() => {
|
||||
updateTable()
|
||||
}, [updateTable])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminCompanyTypeService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateTable,
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminCompanyTypeService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
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 (
|
||||
<>
|
||||
@ -68,9 +71,9 @@ const CompanyTypeController = memo(() => {
|
||||
loading={showLoader}
|
||||
pagination={defaultPagination}
|
||||
dataSource={filteredCompanyTypes}
|
||||
onRowAdd={hasPermission('AdminCompanyType.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление типа компаний')}
|
||||
onRowEdit={hasPermission('AdminCompanyType.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование типа компаний')}
|
||||
onRowDelete={hasPermission('AdminCompanyType.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление типа компаний')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
tableName={'admin_company_type_controller'}
|
||||
/>
|
||||
</>
|
||||
|
@ -2,8 +2,8 @@ import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { Input } from 'antd'
|
||||
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { EditableTable, makeColumn, makeActionHandler, defaultPagination, makeTimezoneColumn } from '@components/Table'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { EditableTable, makeColumn, defaultPagination, makeTimezoneColumn } from '@components/Table'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { min1 } from '@utils/validationRules'
|
||||
import { AdminDepositService } from '@api'
|
||||
|
||||
@ -42,12 +42,20 @@ const DepositController = memo(() => {
|
||||
updateTable()
|
||||
}, [updateTable])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminDepositService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateTable,
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminDepositService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: 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 (
|
||||
<>
|
||||
@ -65,9 +73,9 @@ const DepositController = memo(() => {
|
||||
columns={depositColumns}
|
||||
dataSource={filteredDeposits}
|
||||
pagination={defaultPagination}
|
||||
onRowAdd={hasPermission('AdminDeposit.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление месторождения')}
|
||||
onRowEdit={hasPermission('AdminDeposit.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование месторождения')}
|
||||
onRowDelete={hasPermission('AdminDeposit.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление месторождения')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
tableName={'admin_deposit_controller'}
|
||||
/>
|
||||
</>
|
||||
|
@ -1,14 +1,9 @@
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { Input } from 'antd'
|
||||
|
||||
import {
|
||||
EditableTable,
|
||||
makeActionHandler,
|
||||
makeColumn,
|
||||
makeStringSorter
|
||||
} from '@components/Table'
|
||||
import { EditableTable, makeColumn, makeStringSorter } from '@components/Table'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { min1 } from '@utils/validationRules'
|
||||
import { AdminPermissionService } from '@api'
|
||||
|
||||
@ -50,12 +45,20 @@ const PermissionController = memo(() => {
|
||||
updateTable()
|
||||
}, [updateTable])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminPermissionService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateTable
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminPermissionService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: 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 (
|
||||
<>
|
||||
@ -73,9 +76,9 @@ const PermissionController = memo(() => {
|
||||
loading={showLoader}
|
||||
dataSource={filteredPermissions}
|
||||
pagination={{ showSizeChanger: true }}
|
||||
onRowAdd={hasPermission('AdminPermission.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление права')}
|
||||
onRowEdit={hasPermission('AdminPermission.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование права')}
|
||||
onRowDelete={hasPermission('AdminPermission.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление права')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
tableName={'admin_permission_controller'}
|
||||
/>
|
||||
</>
|
||||
|
@ -3,9 +3,9 @@ import { Input } from 'antd'
|
||||
|
||||
import { PermissionView, RoleView } from '@components/views'
|
||||
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 { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { min1 } from '@utils/validationRules'
|
||||
|
||||
const RoleController = memo(() => {
|
||||
@ -50,17 +50,25 @@ const RoleController = memo(() => {
|
||||
)
|
||||
}, [loadRoles])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminUserRoleService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: async () => invokeWebApiWrapperAsync(
|
||||
loadRoles,
|
||||
setShowLoader,
|
||||
`Не удалось загрузить список ролей`,
|
||||
'Получение списка ролей',
|
||||
)
|
||||
}), [loadRoles])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminUserRoleService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: async () => invokeWebApiWrapperAsync(
|
||||
loadRoles,
|
||||
setShowLoader,
|
||||
`Не удалось загрузить список ролей`,
|
||||
'Получение списка ролей',
|
||||
),
|
||||
permission: 'AdminUserRole.edit'
|
||||
}
|
||||
|
||||
return {
|
||||
add: { ...handlerProps, action: 'insert', actionName: 'Добавление роли' },
|
||||
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование роли' },
|
||||
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление роли', permission: 'AdminUserRole.delete' },
|
||||
}
|
||||
}, [loadRoles])
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -77,9 +85,9 @@ const RoleController = memo(() => {
|
||||
columns={columns}
|
||||
loading={showLoader}
|
||||
dataSource={filteredRoles}
|
||||
onRowAdd={hasPermission('AdminUserRole.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление роли')}
|
||||
onRowEdit={hasPermission('AdminUserRole.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование роли')}
|
||||
onRowDelete={hasPermission('AdminUserRole.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление роли')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
tableName={'admin_role_controller'}
|
||||
/>
|
||||
</>
|
||||
|
@ -6,7 +6,6 @@ import { BehaviorSubject, debounceTime, distinctUntilChanged, filter, map } from
|
||||
import {
|
||||
EditableTable,
|
||||
makeSelectColumn,
|
||||
makeActionHandler,
|
||||
makeNumericSorter,
|
||||
defaultPagination,
|
||||
makeTextColumn
|
||||
@ -18,7 +17,7 @@ import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { AdminCompanyService, AdminUserRoleService, AdminUserService } from '@api'
|
||||
import { createLoginRules, nameRules, phoneRules, emailRules } from '@utils/validationRules'
|
||||
import { makeTextOnFilter, makeTextFilters, makeArrayOnFilter } from '@utils/filters'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
|
||||
import RoleTag from './RoleTag'
|
||||
|
||||
@ -175,12 +174,20 @@ const UserController = memo(() => {
|
||||
)
|
||||
}, [])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminUserService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateTable,
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminUserService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: 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])
|
||||
|
||||
@ -199,9 +206,9 @@ const UserController = memo(() => {
|
||||
bordered
|
||||
columns={columns}
|
||||
dataSource={filteredUsers}
|
||||
onRowAdd={hasPermission('AdminUser.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление пользователя')}
|
||||
onRowEdit={hasPermission('AdminUser.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование пользователя')}
|
||||
onRowDelete={hasPermission('AdminUser.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление пользователя')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
additionalButtons={additionalButtons}
|
||||
buttonsWidth={120}
|
||||
pagination={defaultPagination}
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
EditableTable,
|
||||
makeColumn,
|
||||
makeSelectColumn,
|
||||
makeActionHandler,
|
||||
makeStringSorter,
|
||||
makeNumericSorter,
|
||||
makeTagColumn,
|
||||
@ -22,7 +21,7 @@ import {
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { TelemetryView, CompanyView } from '@components/views'
|
||||
import TelemetrySelect from '@components/selectors/TelemetrySelect'
|
||||
import { arrayOrDefault, hasPermission, wrapPrivateComponent } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
|
||||
import { coordsFixed } from '../DepositController'
|
||||
|
||||
@ -121,12 +120,20 @@ const WellController = memo(() => {
|
||||
)
|
||||
}, [updateTable])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: AdminWellService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateTable
|
||||
}), [updateTable])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: AdminWellService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: 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 (
|
||||
<>
|
||||
@ -144,9 +151,9 @@ const WellController = memo(() => {
|
||||
loading={showLoader}
|
||||
dataSource={filteredWells}
|
||||
pagination={defaultPagination}
|
||||
onRowAdd={hasPermission('AdminWell.edit') && makeActionHandler('insert', handlerProps, recordParser, 'Добавление скважины')}
|
||||
onRowEdit={hasPermission('AdminWell.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование скважины')}
|
||||
onRowDelete={hasPermission('AdminWell.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление скважины')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
//additionalButtons={addititonalButtons}
|
||||
buttonsWidth={95}
|
||||
tableName={'admin_well_controller'}
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { memo, useCallback, useMemo, useState } from 'react'
|
||||
import { Button, Modal } from 'antd'
|
||||
|
||||
import { EditableTable, makeActionHandler, makeTextColumn } from '@components/Table'
|
||||
import { getPermissions } from '@utils'
|
||||
import { EditableTable, makeTextColumn } from '@components/Table'
|
||||
import { DrillerService } from '@api'
|
||||
|
||||
const reqRule = [{ message: 'Обязательное поле!', required: true }]
|
||||
@ -19,8 +18,6 @@ export const DrillerList = memo(({ loading, drillers, onChange }) => {
|
||||
const [showLoader, setShowLoader] = useState(false)
|
||||
const [showModal, setShowModal] = useState(false)
|
||||
|
||||
const permissions = useMemo(() => getPermissions('Driller.edit', 'Driller.delete'), [])
|
||||
|
||||
const onModalOpen = useCallback(() => {
|
||||
setShowModal(true)
|
||||
}, [])
|
||||
@ -29,18 +26,20 @@ export const DrillerList = memo(({ loading, drillers, onChange }) => {
|
||||
setShowModal(false)
|
||||
}, [])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: DrillerService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: onChange,
|
||||
}), [onChange])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: DrillerService,
|
||||
setLoader: setShowLoader,
|
||||
onComplete: onChange,
|
||||
permission: 'Driller.edit'
|
||||
}
|
||||
|
||||
const actionHandlers = useMemo(() => ({
|
||||
add: permissions.driller.edit && makeActionHandler('insert', handlerProps),
|
||||
edit: permissions.driller.edit && makeActionHandler('update', handlerProps),
|
||||
delete: permissions.driller.delete && makeActionHandler('delete', handlerProps),
|
||||
}), [permissions, handlerProps])
|
||||
return {
|
||||
add: { ...handlerProps, action: 'insert', actionName: 'Добавление бурильщика' },
|
||||
edit: { ...handlerProps, action: 'update', actionName: 'Редактирование бурильщика' },
|
||||
delete: { ...handlerProps, action: 'delete', actionName: 'Удаление бурильщика', permission: 'Driller.delete' },
|
||||
}
|
||||
}, [updateTable])
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -60,9 +59,9 @@ export const DrillerList = memo(({ loading, drillers, onChange }) => {
|
||||
dataSource={drillers}
|
||||
columns={columns}
|
||||
scroll={{ y: '75vh', scrollToFirstRowOnChange: true }}
|
||||
onRowAdd={actionHandlers.add}
|
||||
onRowEdit={actionHandlers.edit}
|
||||
onRowDelete={actionHandlers.delete}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
rowClassName={rowClassName}
|
||||
/>
|
||||
</Modal>
|
||||
|
@ -7,11 +7,9 @@ import {
|
||||
makeGroupColumn,
|
||||
makeDateColumn,
|
||||
EditableTable,
|
||||
makeActionHandler,
|
||||
makeSelectColumn,
|
||||
} from '@components/Table'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { getPermissions } from '@utils'
|
||||
import { ScheduleService } from '@api'
|
||||
|
||||
const reqRule = [{ message: 'Обязательное поле!', required: true }]
|
||||
@ -23,8 +21,6 @@ export const DrillerSchedule = memo(({ drillers, loading, onChange }) => {
|
||||
|
||||
const idWell = useIdWell()
|
||||
|
||||
const permissions = useMemo(() => getPermissions('Schedule.edit', 'Schedule.delete'), [])
|
||||
|
||||
const updateSchedule = useCallback(async () => invokeWebApiWrapperAsync(
|
||||
async () => {
|
||||
const schedule = await ScheduleService.getByIdWell(idWell)
|
||||
@ -44,20 +40,25 @@ export const DrillerSchedule = memo(({ drillers, loading, onChange }) => {
|
||||
updateSchedule()
|
||||
}, [updateSchedule])
|
||||
|
||||
const scheduleHandlerProps = useMemo(() => ({
|
||||
service: ScheduleService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateSchedule,
|
||||
}), [updateSchedule])
|
||||
|
||||
const newScheduleParser = useCallback((record) => ({ ...record, idWell }), [idWell])
|
||||
|
||||
const actionHandlers = useMemo(() => ({
|
||||
add: permissions.schedule.edit && makeActionHandler('insert', scheduleHandlerProps, newScheduleParser),
|
||||
edit: permissions.schedule.edit && makeActionHandler('update', scheduleHandlerProps),
|
||||
delete: permissions.schedule.delete && makeActionHandler('delete', scheduleHandlerProps),
|
||||
}), [permissions, scheduleHandlerProps, newScheduleParser])
|
||||
const tableHandlers = useMemo(() => {
|
||||
const handlerProps = {
|
||||
service: ScheduleService,
|
||||
setLoader: setShowLoader,
|
||||
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 options = drillers.map(({ id, name, surname, patronymic }) => ({
|
||||
@ -104,9 +105,9 @@ export const DrillerSchedule = memo(({ drillers, loading, onChange }) => {
|
||||
dataSource={schedule}
|
||||
columns={scheduleColumns}
|
||||
scroll={{ y: '75vh', scrollToFirstRowOnChange: true }}
|
||||
onRowAdd={actionHandlers.add}
|
||||
onRowEdit={actionHandlers.edit}
|
||||
onRowDelete={actionHandlers.delete}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
/>
|
||||
</Modal>
|
||||
<Button
|
||||
|
@ -4,14 +4,13 @@ import { useIdWell } from '@asb/context'
|
||||
import {
|
||||
EditableTable,
|
||||
makeSelectColumn,
|
||||
makeActionHandler,
|
||||
makeNumericAvgRange,
|
||||
makeNumericSorter,
|
||||
} from '@components/Table'
|
||||
import LoaderPortal from '@components/LoaderPortal'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { DrillParamsService, WellOperationService } from '@api'
|
||||
import { hasPermission, arrayOrDefault } from '@utils'
|
||||
import { arrayOrDefault } from '@utils'
|
||||
|
||||
|
||||
export const getColumns = async (idWell) => {
|
||||
@ -61,16 +60,23 @@ export const WellDrillParams = memo(() => {
|
||||
})()
|
||||
}, [idWell, updateParams])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: DrillParamsService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateParams,
|
||||
idWell
|
||||
}), [idWell, updateParams])
|
||||
|
||||
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 (
|
||||
<LoaderPortal show={showLoader}>
|
||||
<EditableTable
|
||||
@ -79,9 +85,9 @@ export const WellDrillParams = memo(() => {
|
||||
columns={columns}
|
||||
dataSource={params}
|
||||
tableName={'well_drill_params'}
|
||||
onRowAdd={hasPermission('DrillParams.edit') && makeActionHandler('insert', handlerProps, recordParser, 'Добавление режима бурения')}
|
||||
onRowEdit={hasPermission('DrillParams.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование режима бурения')}
|
||||
onRowDelete={hasPermission('DrillParams.delete') && makeActionHandler('delete', handlerProps, recordParser, 'Удаление режима бурения')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
pagination={false}
|
||||
/>
|
||||
</LoaderPortal>
|
||||
|
@ -9,7 +9,6 @@ import {
|
||||
makeColumn,
|
||||
makeNumericColumnOptions,
|
||||
makeSelectColumn,
|
||||
makeActionHandler,
|
||||
makeDateColumn,
|
||||
makeNumericColumn,
|
||||
makeNumericRender,
|
||||
@ -18,7 +17,7 @@ import {
|
||||
} from '@components/Table'
|
||||
import LoaderPortal from '@components/LoaderPortal'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { arrayOrDefault, wrapPrivateComponent, hasPermission } from '@utils'
|
||||
import { arrayOrDefault, wrapPrivateComponent } from '@utils'
|
||||
import { WellOperationService } from '@api'
|
||||
|
||||
const { TextArea } = Input
|
||||
@ -107,25 +106,34 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => {
|
||||
updateOperations()
|
||||
}, [updateOperations])
|
||||
|
||||
const handlerProps = useMemo(() => ({
|
||||
service: WellOperationService,
|
||||
setLoader: setShowLoader,
|
||||
errorMsg: `Не удалось выполнить операцию`,
|
||||
onComplete: updateOperations,
|
||||
idWell
|
||||
}), [idWell, updateOperations])
|
||||
|
||||
const onRow = useCallback((record) => {
|
||||
if (selectedIds?.includes(record.id))
|
||||
return { style: { background: '#BF0000A0' } }
|
||||
}, [selectedIds])
|
||||
|
||||
const recordParser = (record) => ({
|
||||
const recordParser = useCallback((record) => ({
|
||||
...record,
|
||||
idType,
|
||||
wellDepth: +record.wellDepth,
|
||||
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 (
|
||||
<LoaderPortal show={showLoader}>
|
||||
@ -136,9 +144,9 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => {
|
||||
columns={columns}
|
||||
sticky={true}
|
||||
dataSource={operations}
|
||||
onRowAdd={hasPermission('WellOperation.edit') && makeActionHandler('insertRange', handlerProps, recordParser, 'Добавление операции по скважине')}
|
||||
onRowEdit={hasPermission('WellOperation.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование операции по скважине')}
|
||||
onRowDelete={hasPermission('WellOperation.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление операции по скважине')}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
pagination={{
|
||||
current: pageNumAndPageSize.current,
|
||||
pageSize: pageNumAndPageSize.pageSize,
|
||||
|
Loading…
Reference in New Issue
Block a user