diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 3faac06..fddaf69 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -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) } diff --git a/src/pages/AdminPanel/UserController.jsx b/src/pages/AdminPanel/UserController.jsx index 4054501..4fce8ff 100644 --- a/src/pages/AdminPanel/UserController.jsx +++ b/src/pages/AdminPanel/UserController.jsx @@ -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, diff --git a/src/pages/WellOperations/WellOperationsEditor.jsx b/src/pages/WellOperations/WellOperationsEditor.jsx index 4098a4f..baabe0d 100644 --- a/src/pages/WellOperations/WellOperationsEditor.jsx +++ b/src/pages/WellOperations/WellOperationsEditor.jsx @@ -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: