From 741449fb999afe9a1442e4fc191dc236e4ded38a Mon Sep 17 00:00:00 2001 From: goodmice Date: Tue, 7 Dec 2021 19:42:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20code=20style=20makeActionHandler=20=D1=8D?= =?UTF-8?q?=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=20=D0=B8=D0=B7=20components/Table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/index.tsx | 2 +- src/components/Table/sorters.ts | 42 ++++++++++++++------------------- src/components/UserMenu.tsx | 20 ++++++++-------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 9fb2115..060a2ef 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -4,7 +4,7 @@ import { OptionsType } from 'rc-select/lib/interface' import { tryAddKeys } from './EditableTable' import { makeNumericSorter, makeStringSorter} from './sorters' export { makeDateSorter, makeNumericSorter, makeStringSorter} from './sorters' -export { EditableTable } from './EditableTable' +export { EditableTable, makeActionHandler } from './EditableTable' export { DatePickerWrapper } from './DatePickerWrapper' export { SelectFromDictionary } from './SelectFromDictionary' diff --git a/src/components/Table/sorters.ts b/src/components/Table/sorters.ts index 71732cb..8a377ae 100644 --- a/src/components/Table/sorters.ts +++ b/src/components/Table/sorters.ts @@ -1,33 +1,27 @@ -export const makeNumericSorter = (key: string) => (a: any, b: any) => a[key] - b[key]; +export const makeNumericSorter = (key: string) => (a: any, b: any) => Number(a[key]) - Number(b[key]) export const makeStringSorter = (key: string) => (a: any, b: any) => { - if (a == null && b == null) - return 1; + if (a == null) return 1 + if (b == null) return -1 - if (a == null) - return 1; + const aValue = a[key] + const bValue = b[key] - if (b == null) - return -1; + for (let i = 0; i < a.length; i++) { + if (isNaN(aValue.charCodeAt(i)) || (aValue.charCodeAt(i) > bValue.charCodeAt(i))) + return 1 - let aValue = a[key]; - let bValue = b[key]; - - for (let i = 0; i < a.length; i++) { - if (isNaN(aValue.charCodeAt(i)) || (aValue.charCodeAt(i) > bValue.charCodeAt(i))) - return 1; - - if (aValue.charCodeAt(i) > bValue.charCodeAt(i)) - return -1; - } - return 0; -}; + if (aValue.charCodeAt(i) > bValue.charCodeAt(i)) + return -1 + } + return 0 +} export const makeDateSorter = (key: string) => (a: any, b: any) => { - const date = new Date(a[key]); + const date = new Date(a[key]) - if (Number.isNaN(date.getTime())) - throw new Error('Date column contains not date formatted string(s)'); + if (Number.isNaN(date.getTime())) + throw new Error('Date column contains not date formatted string(s)') - return date.getTime() - new Date(b[key]).getTime(); -}; + return date.getTime() - new Date(b[key]).getTime() +} diff --git a/src/components/UserMenu.tsx b/src/components/UserMenu.tsx index 1e8ab67..0877eb2 100644 --- a/src/components/UserMenu.tsx +++ b/src/components/UserMenu.tsx @@ -79,16 +79,16 @@ export const UserMenu: React.FC = ({ isAdmin }) => { onOk={() => form.submit()} > -
- - setPassword(e.target.value)} value={password} /> - -
+
+ + setPassword(e.target.value)} value={password} /> + +