forked from ddrilling/asb_cloud_front
Исправлена ошибка с makeActionHandler
This commit is contained in:
parent
d27d3a1632
commit
7c78cb3c32
@ -6,6 +6,13 @@ import { invokeWebApiWrapperAsync } from '../factory'
|
|||||||
|
|
||||||
const newRowKeyValue = 'newRow'
|
const newRowKeyValue = 'newRow'
|
||||||
|
|
||||||
|
const actions = [
|
||||||
|
[['insert'], (data) => [data]],
|
||||||
|
[['insertRange'], (data) => [[data].flat(1)]],
|
||||||
|
[['update', 'put'], (data) => data.id && [data.id, data]],
|
||||||
|
[['delete'], (data) => data.id && [data.id]],
|
||||||
|
]
|
||||||
|
|
||||||
export const makeActionHandler = (action, { idWell, service, setLoader, errorMsg, onComplete }, recordParser) => service && action && (
|
export const makeActionHandler = (action, { idWell, service, setLoader, errorMsg, onComplete }, recordParser) => service && action && (
|
||||||
(record) => invokeWebApiWrapperAsync(
|
(record) => invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
@ -13,21 +20,11 @@ export const makeActionHandler = (action, { idWell, service, setLoader, errorMsg
|
|||||||
if (typeof recordParser === 'function')
|
if (typeof recordParser === 'function')
|
||||||
record = recordParser(record)
|
record = recordParser(record)
|
||||||
|
|
||||||
if (action === 'insert') {
|
const actionId = actions.findIndex((elm) => elm[0].includes(action))
|
||||||
record.key = Date.now()
|
const params = actions[actionId]?.[1](record)
|
||||||
await service.insert(...addIdWell(record))
|
|
||||||
} else if (action === 'insertRange') {
|
if (params) await service[action](...addIdWell(...params))
|
||||||
if (!Array.isArray(record))
|
await onComplete?.()
|
||||||
record = [record]
|
|
||||||
await service.insertRange(...addIdWell(record))
|
|
||||||
} else if (record.id) {
|
|
||||||
if (action === 'update')
|
|
||||||
await service.put(...addIdWell(record.id, record))
|
|
||||||
else if (action === 'delete')
|
|
||||||
await service.delete(...addIdWell(record.id))
|
|
||||||
}
|
|
||||||
if (onComplete)
|
|
||||||
await onComplete()
|
|
||||||
},
|
},
|
||||||
setLoader,
|
setLoader,
|
||||||
errorMsg
|
errorMsg
|
||||||
@ -208,7 +205,7 @@ export const EditableTable = ({
|
|||||||
const mergedColumns = [...columns.map(handleColumn), operationColumn]
|
const mergedColumns = [...columns.map(handleColumn), operationColumn]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form form={form} component={false}>
|
<Form form={form}>
|
||||||
<Table
|
<Table
|
||||||
components={{
|
components={{
|
||||||
body: {
|
body: {
|
||||||
|
@ -118,6 +118,7 @@ export const WellTreeSelector = () => {
|
|||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={value}
|
value={value}
|
||||||
|
style={{ width: '350px' }}
|
||||||
/>
|
/>
|
||||||
</LoaderPortal>
|
</LoaderPortal>
|
||||||
)
|
)
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
} from '../../components/Table'
|
} from '../../components/Table'
|
||||||
import { AdminClusterService, AdminDepositService } from '../../services/api'
|
import { AdminClusterService, AdminDepositService } from '../../services/api'
|
||||||
import { arrayOrDefault } from '../../utils'
|
import { arrayOrDefault } from '../../utils'
|
||||||
import { min3 } from '../../utils/validationRules'
|
import { min1 } from '../../utils/validationRules'
|
||||||
|
|
||||||
import { coordsFixed } from './DepositController'
|
import { coordsFixed } from './DepositController'
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ export default function ClusterController() {
|
|||||||
width: 200,
|
width: 200,
|
||||||
editable: true,
|
editable: true,
|
||||||
sorter: makeStringSorter('caption'),
|
sorter: makeStringSorter('caption'),
|
||||||
formItemRules: min3,
|
formItemRules: min1,
|
||||||
}),
|
}),
|
||||||
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
|
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
|
||||||
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
|
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
|
||||||
@ -72,7 +72,7 @@ export default function ClusterController() {
|
|||||||
columns={clusterColumns}
|
columns={clusterColumns}
|
||||||
dataSource={clusters}
|
dataSource={clusters}
|
||||||
onRowAdd={makeActionHandler('insert', handlerProps)}
|
onRowAdd={makeActionHandler('insert', handlerProps)}
|
||||||
onRowEdit={makeActionHandler('update', handlerProps)}
|
onRowEdit={makeActionHandler('put', handlerProps)}
|
||||||
onRowDelete={makeActionHandler('delete', handlerProps)}
|
onRowDelete={makeActionHandler('delete', handlerProps)}
|
||||||
/>
|
/>
|
||||||
</LoaderPortal>
|
</LoaderPortal>
|
||||||
|
@ -5,14 +5,14 @@ import LoaderPortal from '../../components/LoaderPortal'
|
|||||||
import { EditableTable, makeColumn, makeActionHandler, makeStringSorter } from '../../components/Table'
|
import { EditableTable, makeColumn, makeActionHandler, makeStringSorter } from '../../components/Table'
|
||||||
import { AdminCompanyService } from '../../services/api'
|
import { AdminCompanyService } from '../../services/api'
|
||||||
import { arrayOrDefault } from '../../utils'
|
import { arrayOrDefault } from '../../utils'
|
||||||
import { min3 } from '../../utils/validationRules'
|
import { min1 } from '../../utils/validationRules'
|
||||||
|
|
||||||
const companyColumns = [
|
const companyColumns = [
|
||||||
makeColumn('Название', 'caption', {
|
makeColumn('Название', 'caption', {
|
||||||
width: 200,
|
width: 200,
|
||||||
editable: true,
|
editable: true,
|
||||||
sorter: makeStringSorter('caption'),
|
sorter: makeStringSorter('caption'),
|
||||||
formItemRules: min3,
|
formItemRules: min1,
|
||||||
}),
|
}),
|
||||||
makeColumn('Тип компании', 'companyTypeCaption', {
|
makeColumn('Тип компании', 'companyTypeCaption', {
|
||||||
width: 200,
|
width: 200,
|
||||||
|
@ -4,12 +4,12 @@ import LoaderPortal from '../../components/LoaderPortal'
|
|||||||
import { EditableTable, makeColumn, makeActionHandler } from '../../components/Table'
|
import { EditableTable, makeColumn, makeActionHandler } from '../../components/Table'
|
||||||
import { AdminDepositService } from '../../services/api'
|
import { AdminDepositService } from '../../services/api'
|
||||||
import { arrayOrDefault } from '../../utils'
|
import { arrayOrDefault } from '../../utils'
|
||||||
import { min3 } from '../../utils/validationRules'
|
import { min1 } from '../../utils/validationRules'
|
||||||
|
|
||||||
export const coordsFixed = (coords) => coords?.toPrecision(10)
|
export const coordsFixed = (coords) => coords?.toPrecision(10)
|
||||||
|
|
||||||
const depositColumns = [
|
const depositColumns = [
|
||||||
makeColumn('Название', 'caption', { width: 200, editable: true, formItemRules: min3 }),
|
makeColumn('Название', 'caption', { width: 200, editable: true, formItemRules: min1 }),
|
||||||
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
|
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
|
||||||
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed })
|
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed })
|
||||||
]
|
]
|
||||||
@ -44,7 +44,7 @@ export default function DepositController() {
|
|||||||
columns={depositColumns}
|
columns={depositColumns}
|
||||||
dataSource={deposits}
|
dataSource={deposits}
|
||||||
onRowAdd={makeActionHandler('insert', handlerProps)}
|
onRowAdd={makeActionHandler('insert', handlerProps)}
|
||||||
onRowEdit={makeActionHandler('update', handlerProps)}
|
onRowEdit={makeActionHandler('put', handlerProps)}
|
||||||
onRowDelete={makeActionHandler('delete', handlerProps)}
|
onRowDelete={makeActionHandler('delete', handlerProps)}
|
||||||
/>
|
/>
|
||||||
</LoaderPortal>
|
</LoaderPortal>
|
||||||
|
@ -10,13 +10,14 @@ import {
|
|||||||
} from '../../components/Table'
|
} from '../../components/Table'
|
||||||
import { AdminPermissionService } from '../../services/api'
|
import { AdminPermissionService } from '../../services/api'
|
||||||
import { arrayOrDefault } from '../../utils'
|
import { arrayOrDefault } from '../../utils'
|
||||||
import { min3 } from '../../utils/validationRules'
|
import { min1 } from '../../utils/validationRules'
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
makeColumn('Название', 'name', {
|
makeColumn('Название', 'name', {
|
||||||
editable: true,
|
editable: true,
|
||||||
sorter: makeStringSorter('name'),
|
sorter: makeStringSorter('name'),
|
||||||
formItemRules: min3,
|
isRequired: true,
|
||||||
|
formItemRules: min1,
|
||||||
}),
|
}),
|
||||||
makeColumn('Описание', 'description', {
|
makeColumn('Описание', 'description', {
|
||||||
editable: true,
|
editable: true,
|
||||||
|
@ -6,7 +6,7 @@ import { invokeWebApiWrapperAsync } from '../../components/factory'
|
|||||||
import { EditableTable, makeActionHandler, makeColumn, makeSelectColumn, makeTagColumn } from '../../components/Table'
|
import { EditableTable, makeActionHandler, makeColumn, makeSelectColumn, makeTagColumn } from '../../components/Table'
|
||||||
import { AdminPermissionService, AdminUserRoleService } from '../../services/api'
|
import { AdminPermissionService, AdminUserRoleService } from '../../services/api'
|
||||||
import { arrayOrDefault } from '../../utils'
|
import { arrayOrDefault } from '../../utils'
|
||||||
import { min3 } from '../../utils/validationRules'
|
import { min1 } from '../../utils/validationRules'
|
||||||
|
|
||||||
export const RoleController = memo(() => {
|
export const RoleController = memo(() => {
|
||||||
const [permissions, setPermissions] = useState([])
|
const [permissions, setPermissions] = useState([])
|
||||||
@ -22,12 +22,12 @@ export const RoleController = memo(() => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const options = roles?.map((r) => ({ value: r.id, label: r.caption })) ?? []
|
const options = roles?.map((r) => ({ value: r.id, label: r.caption })) ?? []
|
||||||
setColumns([
|
setColumns([
|
||||||
makeColumn('Название', 'caption', { width: 200, editable: true, formItemRules: min3 }),
|
makeColumn('Название', 'caption', { width: 200, editable: true, formItemRules: min1 }),
|
||||||
makeSelectColumn('Роль-родитель', 'idParent', options, options[0], {
|
makeSelectColumn('Роль-родитель', 'idParent', options, options[0], {
|
||||||
width: 200,
|
width: 200,
|
||||||
editable: true
|
editable: true
|
||||||
}, { allowClear: true }),
|
}, { allowClear: true }),
|
||||||
makeTagColumn('Права доступа', 'permissions', permissions, 'id', 'name', {
|
makeTagColumn('Разрешения', 'permissions', permissions, 'id', 'name', {
|
||||||
width: 200,
|
width: 200,
|
||||||
editable: true,
|
editable: true,
|
||||||
render: (permission) => <PermissionView info={permission} />,
|
render: (permission) => <PermissionView info={permission} />,
|
||||||
@ -64,7 +64,7 @@ export const RoleController = memo(() => {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={roles}
|
dataSource={roles}
|
||||||
onRowAdd={makeActionHandler('insert', handlerProps)}
|
onRowAdd={makeActionHandler('insert', handlerProps)}
|
||||||
onRowEdit={makeActionHandler('update', handlerProps)}
|
onRowEdit={makeActionHandler('put', handlerProps)}
|
||||||
onRowDelete={makeActionHandler('delete', handlerProps)}
|
onRowDelete={makeActionHandler('delete', handlerProps)}
|
||||||
/>
|
/>
|
||||||
</LoaderPortal>
|
</LoaderPortal>
|
||||||
|
@ -29,8 +29,6 @@ const RoleTag = memo(({ roles, value, onChange }) => {
|
|||||||
})))
|
})))
|
||||||
}, [roles])
|
}, [roles])
|
||||||
|
|
||||||
console.log(value)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
|
@ -132,7 +132,7 @@ export default function WellController() {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={wells}
|
dataSource={wells}
|
||||||
onRowAdd={makeActionHandler('insert', handlerProps)}
|
onRowAdd={makeActionHandler('insert', handlerProps)}
|
||||||
onRowEdit={makeActionHandler('update', handlerProps)}
|
onRowEdit={makeActionHandler('put', handlerProps)}
|
||||||
onRowDelete={makeActionHandler('delete', handlerProps)}
|
onRowDelete={makeActionHandler('delete', handlerProps)}
|
||||||
//additionalButtons={addititonalButtons}
|
//additionalButtons={addititonalButtons}
|
||||||
buttonsWidth={95}
|
buttonsWidth={95}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import { Rule } from 'rc-field-form/lib/interface'
|
import { Rule } from 'rc-field-form/lib/interface'
|
||||||
|
|
||||||
export const min3: Rule[] = [{
|
const _min1: Rule = {
|
||||||
min: 3,
|
min: 1,
|
||||||
max: 255,
|
max: 255,
|
||||||
message: 'Допустимая длина 3-255 символов'
|
message: 'Допустимая длина 1-255 символов'
|
||||||
}]
|
}
|
||||||
|
|
||||||
export const createLoginRules: Rule[] = [...min3, {
|
export const min1: Rule[] = [_min1]
|
||||||
|
|
||||||
|
export const createLoginRules: Rule[] = [_min1, {
|
||||||
pattern: /^[A-Za-zА-Яа-я][А-Яа-я\w.-]+$/,
|
pattern: /^[A-Za-zА-Яа-я][А-Яа-я\w.-]+$/,
|
||||||
whitespace: true,
|
whitespace: true,
|
||||||
message: 'Логин должен начинаться с русской или латинской буквы, содержать только (А-яA-z0-9_-.)!'
|
message: 'Логин должен начинаться с русской или латинской буквы, содержать только (А-яA-z0-9_-.)!'
|
||||||
@ -17,11 +19,7 @@ export const loginRules: Rule[] = [{
|
|||||||
message: 'Пожалуйста, введите имя пользователя'
|
message: 'Пожалуйста, введите имя пользователя'
|
||||||
}]
|
}]
|
||||||
|
|
||||||
export const nameRules: Rule[] = [{
|
export const nameRules: Rule[] = [_min1, {
|
||||||
min: 1,
|
|
||||||
max: 255,
|
|
||||||
message: 'Допустимая длина 1-255 символов!'
|
|
||||||
}, {
|
|
||||||
pattern: /^[A-zА-я][A-zА-я-]*$/,
|
pattern: /^[A-zА-я][A-zА-я-]*$/,
|
||||||
message: 'Допустимые символы: А-яA-z-'
|
message: 'Допустимые символы: А-яA-z-'
|
||||||
}]
|
}]
|
||||||
|
Loading…
Reference in New Issue
Block a user