From f90856f712f79f0de718739580e4e843236ae197 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Thu, 13 Jan 2022 15:52:57 +0500 Subject: [PATCH] =?UTF-8?q?*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=B2=20UserCo?= =?UTF-8?q?ntroller=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=82=D0=BE=D1=80=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=86=D0=B8=D0=B8=20=D1=81=D0=B5=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B2=20WellOperationTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/index.tsx | 2 +- src/pages/AdminPanel/UserController.jsx | 42 +++++++++++++++++++ .../WellOperations/WellOperationsEditor.jsx | 12 +++++- 3 files changed, 54 insertions(+), 2 deletions(-) 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: