forked from ddrilling/asb_cloud_front
* Добавлена фильтрация полей в UserController
* Добавлен валидатор поля конструкции секции в WellOperationTable
This commit is contained in:
parent
e80f56ef57
commit
f90856f712
@ -15,7 +15,7 @@ export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
|
||||
export const makeNumericRender = (fixed?: number) => (value: any, row: object): ReactNode => {
|
||||
let val = '-'
|
||||
if ((value ?? null) !== null && Number.isFinite(+value)) {
|
||||
val = !!fixed
|
||||
val = (fixed ?? null) !== null
|
||||
? (+value).toFixed(fixed)
|
||||
: (+value).toPrecision(5)
|
||||
}
|
||||
|
@ -41,6 +41,34 @@ const RoleTag = memo(({ roles, value, onChange }) => {
|
||||
)
|
||||
})
|
||||
|
||||
const makeOnFilter = (key) => (value, record) => record?.[key]?.startsWith(value)
|
||||
const makeDataFilters = (array, keys) => {
|
||||
const filters = Array(keys.length)
|
||||
|
||||
for (let i = 0; i < keys.length; i++)
|
||||
filters[i] = []
|
||||
|
||||
array.forEach((row) => {
|
||||
if (!row) return
|
||||
keys.forEach((key, idx) => {
|
||||
if (row[key] && filters[idx].indexOf(row[key]) < 0)
|
||||
filters[idx].push(row[key])
|
||||
})
|
||||
})
|
||||
|
||||
const out = {}
|
||||
|
||||
keys.forEach((key, idx) => {
|
||||
filters[idx].sort()
|
||||
out[key] = filters[idx].map((filter) => ({
|
||||
value: filter,
|
||||
text: filter,
|
||||
}))
|
||||
})
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
export default function UserController() {
|
||||
const [users, setUsers] = useState([])
|
||||
const [showLoader, setShowLoader] = useState(false)
|
||||
@ -76,6 +104,8 @@ export default function UserController() {
|
||||
const users = arrayOrDefault(await AdminUserService.getAll())
|
||||
setUsers(users)
|
||||
|
||||
const filters = makeDataFilters(users, ['surname', 'name', 'patronymic', 'email'])
|
||||
|
||||
|
||||
setColumns([
|
||||
makeColumn('Логин', 'login', {
|
||||
@ -98,21 +128,33 @@ export default function UserController() {
|
||||
editable: true,
|
||||
formItemRules: [{ required: true }, ...nameRules],
|
||||
sorter: makeStringSorter('surname'),
|
||||
filters: filters.surname,
|
||||
filterSearch: true,
|
||||
onFilter: makeOnFilter('surname'),
|
||||
}),
|
||||
makeColumn('Имя', 'name', {
|
||||
editable: true,
|
||||
formItemRules: nameRules,
|
||||
sorter: makeStringSorter('name'),
|
||||
filters: filters.name,
|
||||
filterSearch: true,
|
||||
onFilter: makeOnFilter('name'),
|
||||
}),
|
||||
makeColumn('Отчество', 'patronymic', {
|
||||
editable: true,
|
||||
formItemRules: nameRules,
|
||||
sorter: makeStringSorter('patronymic'),
|
||||
filters: filters.patronymic,
|
||||
filterSearch: true,
|
||||
onFilter: makeOnFilter('patronymic'),
|
||||
}),
|
||||
makeColumn('E-mail', 'email', {
|
||||
editable: true,
|
||||
formItemRules: [{ required: true }, ...emailRules],
|
||||
sorter: makeStringSorter('email'),
|
||||
filters: filters.email,
|
||||
filterSearch: true,
|
||||
onFilter: makeOnFilter('email'),
|
||||
}),
|
||||
makeColumn('Номер телефона', 'phone', {
|
||||
editable: true,
|
||||
|
@ -21,7 +21,17 @@ const { TextArea } = Input
|
||||
const basePageSize = 160
|
||||
|
||||
const defaultColumns = [
|
||||
makeSelectColumn('Конструкция секции', 'idWellSectionType', [], undefined, { editable: true, width: 160 }),
|
||||
makeSelectColumn('Конструкция секции', 'idWellSectionType', [], undefined, {
|
||||
editable: true,
|
||||
width: 160,
|
||||
formItemRules: [({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (value?.length > 0)
|
||||
return Promise.resolve()
|
||||
return Promise.reject('Это обязательное поле!')
|
||||
}
|
||||
})],
|
||||
}),
|
||||
makeSelectColumn('Операция', 'idCategory', [], undefined, { editable: true, width: 200 }),
|
||||
makeColumn('Доп. инфо', 'categoryInfo', { editable: true, width: 300, input: <TextArea/> }),
|
||||
makeColumn('Глубина забоя на начало, м', 'depthStart', makeNumericColumnOptions(2, 'depthStart')),
|
||||
|
Loading…
Reference in New Issue
Block a user