From 0db0984ba7e77507808f5c3058fee353f6d5c53a Mon Sep 17 00:00:00 2001 From: goodmice Date: Thu, 19 May 2022 11:43:32 +0500 Subject: [PATCH] =?UTF-8?q?*=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20Tel?= =?UTF-8?q?emetryMerger=20*=20=D0=BA=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D1=82=D0=B0=D0=BC=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20Readonly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminPanel/Telemetry/TelemetryMerger.jsx | 15 ++++++++------- src/utils/datetime.ts | 6 +++--- src/utils/functions.tsx | 6 +++--- src/utils/index.ts | 2 +- src/utils/mimeTypes.ts | 4 ++-- src/utils/permissions.ts | 4 ++-- src/utils/validationRules.ts | 18 +++++++++--------- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/pages/AdminPanel/Telemetry/TelemetryMerger.jsx b/src/pages/AdminPanel/Telemetry/TelemetryMerger.jsx index c97333e..f518c9e 100755 --- a/src/pages/AdminPanel/Telemetry/TelemetryMerger.jsx +++ b/src/pages/AdminPanel/Telemetry/TelemetryMerger.jsx @@ -35,7 +35,7 @@ export const TelemetryInfo = memo(({ info, danger, ...other }) => ( export const TelemetryMerger = memo(() => { const [primary, setPrimary] = useState(null) const [secondary, setSecondary] = useState(null) - const [telemetry, setTelemetry] = useState([]) + const [telemetry, setTelemetry] = useState(null) const [isLoading, setIsLoading] = useState(false) const [isMerging, setIsMerging] = useState(false) @@ -47,7 +47,7 @@ export const TelemetryMerger = memo(() => { primary?.info?.deposit !== secondary?.info?.deposit && 'deposit', ], [primary, secondary]) - const updateTelemetry = useCallback(async () => await invokeWebApiWrapperAsync( + const updateTelemetry = useCallback(() => invokeWebApiWrapperAsync( async () => { const telemetry = arrayOrDefault(await AdminTelemetryService.getAll()) setTelemetry(telemetry) @@ -59,22 +59,23 @@ export const TelemetryMerger = memo(() => { const mergeTelemetry = useCallback(() => invokeWebApiWrapperAsync( async () => { + if (!secondary?.id || !primary?.id) return await AdminTelemetryService.mergeTelemetries(secondary.id, primary.id) - await updateTelemetry() + updateTelemetry() }, setIsMerging, 'Не удалось объединить телеметрии', 'Объединение телеметрий', - ), [updateTelemetry, secondary.id, primary.id]) + ), [updateTelemetry, secondary, primary]) - useEffect(() => updateTelemetry(), [updateTelemetry]) + useEffect(updateTelemetry, [updateTelemetry]) useEffect(() => { const query = new URLSearchParams(location.search) const primaryId = parseInt(query.get('primary') ?? null) const secondaryId = parseInt(query.get('secondary') ?? null) - const primary = isNaN(primaryId) ? null : telemetry.find((t) => t.id === primaryId) - const secondary = isNaN(secondaryId) ? null : telemetry.find((t) => t.id === secondaryId) + const primary = isNaN(primaryId) ? null : telemetry.find((t) => t?.id === primaryId) + const secondary = isNaN(secondaryId) ? null : telemetry.find((t) => t?.id === secondaryId) setPrimary(primary) setSecondary(secondary) }, [location, telemetry]) diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts index 9977f60..e72f63c 100755 --- a/src/utils/datetime.ts +++ b/src/utils/datetime.ts @@ -4,7 +4,7 @@ import { SimpleTimezoneDto } from '@api' export type RawDate = number | string | Date -export const defaultFormat: string = 'DD.MM.YYYY HH:mm' +export const defaultFormat: Readonly = 'DD.MM.YYYY HH:mm' export enum timeInS { millisecond = 0.001, @@ -52,7 +52,7 @@ export const fractionalSum = (date: unknown, value: number, type: keyof typeof t return d } -export const rawTimezones = { +export const rawTimezones = Object.freeze({ 'Калининград': 2, 'Москва': 3, 'Самара': 4, @@ -68,7 +68,7 @@ export const rawTimezones = { 'Среднеколымск': 11, 'Анадырь': 12, 'Петропавловск-Камчатский': 12, -} +}) export type TimezoneId = keyof typeof rawTimezones diff --git a/src/utils/functions.tsx b/src/utils/functions.tsx index cc377e8..fce1223 100755 --- a/src/utils/functions.tsx +++ b/src/utils/functions.tsx @@ -1,13 +1,13 @@ import { OperationStatService, WellOperationDto, WellOperationDtoPlanFactPredictBase } from '@api' -const maxPrefix: string = 'isMax' -const minPrefix: string = 'isMin' +const maxPrefix: Readonly = 'isMax' +const minPrefix: Readonly = 'isMin' export const getPrecision = (number: number): string => Number.isFinite(number) ? number.toFixed(2) : '-' export type KeyType = number | string -export const nwtIdCategory: number = 1043 +export const nwtIdCategory: Readonly = 1043 export type SaubData = WellOperationDto & { /** Относится ли операция к НПВ */ diff --git a/src/utils/index.ts b/src/utils/index.ts index 2323451..51732bc 100755 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -3,7 +3,7 @@ export type { RawDate, timeInS } from './datetime' export { MimeTypes } from './mimeTypes' -export const headerHeight: number = 64 +export const headerHeight: Readonly = 64 export const mainFrameSize = () => ({ width: window.innerWidth, diff --git a/src/utils/mimeTypes.ts b/src/utils/mimeTypes.ts index cdbb3e9..c5a640a 100644 --- a/src/utils/mimeTypes.ts +++ b/src/utils/mimeTypes.ts @@ -1,4 +1,4 @@ -export const MimeTypes = { +export const MimeTypes = Object.freeze({ BMP: 'image/bmp', CSV: 'text/csv', CSV1: 'application/csv', @@ -29,6 +29,6 @@ export const MimeTypes = { XLSB: 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', XLSM: 'application/vnd.ms-excel.sheet.macroEnabled.12', XLSX: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', -} +}) export default MimeTypes diff --git a/src/utils/permissions.ts b/src/utils/permissions.ts index f6434b9..6108278 100755 --- a/src/utils/permissions.ts +++ b/src/utils/permissions.ts @@ -62,9 +62,9 @@ export const isURLAvailable = (path: string, userPermissions?: Permission[]) => return sectionAvailable(perms, userPerms) } -interface PermissionRecord extends Record {} +export interface PermissionRecord extends Record {} -export const requirements: PermissionRecord = { +export const requirements: Readonly = { '': [], login: [], // ['Auth.edit'] register: [], // ['Auth.edit'] diff --git a/src/utils/validationRules.ts b/src/utils/validationRules.ts index 9f300a4..a59de26 100755 --- a/src/utils/validationRules.ts +++ b/src/utils/validationRules.ts @@ -1,44 +1,44 @@ import { Rule } from 'rc-field-form/lib/interface' -const _min1: Rule = { +const _min1: Readonly = { min: 1, max: 255, message: 'Допустимая длина 1-255 символов', } -export const min1: Rule[] = [_min1] +export const min1: Readonly = [_min1] -export const createLoginRules: Rule[] = [_min1, { +export const createLoginRules: Readonly = [_min1, { pattern: /^\s*[A-zА-яЁё][A-zА-яЁё\w.-]+\s*$/, message: 'Логин должен начинаться с русской или латинской буквы и содержать только символы (А-яA-z0-9_-.)!' }] -export const loginRules: Rule[] = [...createLoginRules, { +export const loginRules: Readonly = [...createLoginRules, { required: true, message: 'Пожалуйста, введите логин', }] -export const nameRules: Rule[] = [_min1, { +export const nameRules: Readonly = [_min1, { pattern: /^[A-zА-яЁё][A-zА-яЁё-]*$/, message: 'Допустимые символы: А-яA-z-', }] -export const phoneRules: Rule[] = [{ +export const phoneRules: Readonly = [{ pattern: /^(?:\+7|8)\s?(?:\(\d{3}\)|\d{3})\s?\d{3}-?\d{2}-?\d{2}$/, message: 'Номер телефона должен иметь вид: +7 (xxx) xxx-xx-xx', }] -export const emailRules: Rule[] = [{ +export const emailRules: Readonly = [{ type: 'email', message: 'E-mail должен иметь вид: "user@site.domain"', }] -export const passwordRules: Rule[] = [{ +export const passwordRules: Readonly = [{ required: true, message: 'Пожалуйста, введите пароль!', }] -export const createPasswordRules: Rule[] = [{ +export const createPasswordRules: Readonly = [{ min: 8, max: 255, message: 'Допустимая длина пароля 8-255',