diff --git a/src/components/Table/EditableTable.jsx b/src/components/Table/EditableTable.jsx index 538bbd2..c911d19 100755 --- a/src/components/Table/EditableTable.jsx +++ b/src/components/Table/EditableTable.jsx @@ -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 [] diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index f43ae1d..b03b8de 100755 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -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' diff --git a/src/pages/AdminPanel/ClusterController.jsx b/src/pages/AdminPanel/ClusterController.jsx index 544109d..1260c94 100755 --- a/src/pages/AdminPanel/ClusterController.jsx +++ b/src/pages/AdminPanel/ClusterController.jsx @@ -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'} /> diff --git a/src/pages/AdminPanel/CompanyController.jsx b/src/pages/AdminPanel/CompanyController.jsx index a6176ac..fedfb5b 100755 --- a/src/pages/AdminPanel/CompanyController.jsx +++ b/src/pages/AdminPanel/CompanyController.jsx @@ -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'} /> diff --git a/src/pages/AdminPanel/CompanyTypeController.jsx b/src/pages/AdminPanel/CompanyTypeController.jsx index 7274fdc..e7d20ea 100755 --- a/src/pages/AdminPanel/CompanyTypeController.jsx +++ b/src/pages/AdminPanel/CompanyTypeController.jsx @@ -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'} /> diff --git a/src/pages/AdminPanel/DepositController.jsx b/src/pages/AdminPanel/DepositController.jsx index bdc19a0..d9eff66 100755 --- a/src/pages/AdminPanel/DepositController.jsx +++ b/src/pages/AdminPanel/DepositController.jsx @@ -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'} /> diff --git a/src/pages/AdminPanel/PermissionController.jsx b/src/pages/AdminPanel/PermissionController.jsx index ef68fe8..50fe296 100755 --- a/src/pages/AdminPanel/PermissionController.jsx +++ b/src/pages/AdminPanel/PermissionController.jsx @@ -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'} /> diff --git a/src/pages/AdminPanel/RoleController.jsx b/src/pages/AdminPanel/RoleController.jsx index da247b8..e226b4d 100755 --- a/src/pages/AdminPanel/RoleController.jsx +++ b/src/pages/AdminPanel/RoleController.jsx @@ -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'} /> diff --git a/src/pages/AdminPanel/UserController/index.jsx b/src/pages/AdminPanel/UserController/index.jsx index f9891d5..df2a9e3 100755 --- a/src/pages/AdminPanel/UserController/index.jsx +++ b/src/pages/AdminPanel/UserController/index.jsx @@ -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} diff --git a/src/pages/AdminPanel/WellController/index.jsx b/src/pages/AdminPanel/WellController/index.jsx index 4bbf0aa..dadf24a 100755 --- a/src/pages/AdminPanel/WellController/index.jsx +++ b/src/pages/AdminPanel/WellController/index.jsx @@ -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'} diff --git a/src/pages/Telemetry/Operations/DrillerList.jsx b/src/pages/Telemetry/Operations/DrillerList.jsx index b53c27a..c3f078d 100644 --- a/src/pages/Telemetry/Operations/DrillerList.jsx +++ b/src/pages/Telemetry/Operations/DrillerList.jsx @@ -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} /> diff --git a/src/pages/Telemetry/Operations/DrillerSchedule.jsx b/src/pages/Telemetry/Operations/DrillerSchedule.jsx index fe65e2b..5b9ba48 100644 --- a/src/pages/Telemetry/Operations/DrillerSchedule.jsx +++ b/src/pages/Telemetry/Operations/DrillerSchedule.jsx @@ -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} />