From 43e85364b0e202630f0c73023097c14b1559be33 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Mon, 28 Feb 2022 12:51:45 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=81=D1=82=D0=BE=D0=BB=D0=B1=D0=B5=D1=86=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=B7=D0=BE?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D1=8B=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=9C=D0=B5=D1=81=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8/=D0=9A=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BC=D0=B8/=D0=A1=D0=BA=D0=B2=D0=B0=D0=B6?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/index.tsx | 73 ++++++++++++++++++- src/pages/AdminPanel/ClusterController.jsx | 4 +- src/pages/AdminPanel/DepositController.jsx | 5 +- src/pages/AdminPanel/WellController/index.jsx | 2 + src/pages/DrillingProgram/CategoryRender.jsx | 2 +- 5 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index d9c737e..88a3936 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -1,6 +1,7 @@ import { memo, useEffect, useState, ReactNode } from 'react' import { InputNumber, Select, Table as RawTable, Tag, SelectProps, TableProps } from 'antd' import { DefaultOptionType, SelectValue } from 'antd/lib/select' +import { ColumnProps } from 'antd/lib/table' import { Rule } from 'rc-field-form/lib/interface' import { tryAddKeys } from './EditableTable' @@ -32,11 +33,11 @@ export const makeNumericRender = (fixed?: number) => (value: any, _: object): Re ) } -export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string) => ({ +export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, width: 100, - sorter: sorterKey ? makeNumericSorter(sorterKey) : null, + sorter: sorterKey ? makeNumericSorter(sorterKey) : undefined, formItemRules: [ { required: true, @@ -51,7 +52,7 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string) => other - объект с дополнительными свойствами колонки поддерживаются все базовые свойства из описания https://ant.design/components/table/#Column плю дополнительные для колонок EditableTable: */ -interface columnPropsOther { +type columnPropsOther = ColumnProps & { // редактируемая колонка editable?: boolean // react компонента редактора @@ -309,3 +310,69 @@ export type TableContainer = TableProps & { export const Table = memo(({dataSource, children, ...other}) => ( {children} )) + +const rawTimezones = { + 'Калининград': 2, + 'Москва': 3, + 'Самара': 4, + 'Екатеринбург': 5, + 'Омск': 6, + 'Красноярск': 7, + 'Новосибирск': 7, + 'Иркутск': 8, + 'Чита': 9, + 'Владивосток': 10, + 'Магадан': 11, + 'Южно-Сахалинск': 11, + 'Среднеколымск': 11, + 'Анадырь': 12, + 'Петропавловск-Камчатский': 12, +} + +const timezoneOptions = Object + .entries(rawTimezones) + .sort((a, b) => a[1] - b[1]) + .map(([id, hours]) => ({ + label: `UTC${hours > 0 ? '+':''}${('0' + hours).slice(-2)} :: ${id}`, + value: id, + })) + +export type TimezoneSelectProps = SelectProps & { + // +} + +export const TimezoneSelect = memo(({ onChange, ...other }) => { + const [id, setId] = useState(null) + + useEffect(() => onChange?.({ + timezoneId: id, + hours: id ? rawTimezones[id] : 0, + isOverride: false, + }, []), [id, onChange]) + + return (