* Исправлена работа TelemetryMerger

* к константам добавлен Readonly
This commit is contained in:
goodmice 2022-05-19 11:43:32 +05:00
parent 43e97750e4
commit 0db0984ba7
7 changed files with 28 additions and 27 deletions

View File

@ -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])

View File

@ -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<string> = '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

View File

@ -1,13 +1,13 @@
import { OperationStatService, WellOperationDto, WellOperationDtoPlanFactPredictBase } from '@api'
const maxPrefix: string = 'isMax'
const minPrefix: string = 'isMin'
const maxPrefix: Readonly<string> = 'isMax'
const minPrefix: Readonly<string> = '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<number> = 1043
export type SaubData = WellOperationDto & {
/** Относится ли операция к НПВ */

View File

@ -3,7 +3,7 @@ export type { RawDate, timeInS } from './datetime'
export { MimeTypes } from './mimeTypes'
export const headerHeight: number = 64
export const headerHeight: Readonly<number> = 64
export const mainFrameSize = () => ({
width: window.innerWidth,

View File

@ -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

View File

@ -62,9 +62,9 @@ export const isURLAvailable = (path: string, userPermissions?: Permission[]) =>
return sectionAvailable(perms, userPerms)
}
interface PermissionRecord extends Record<string, string[] | PermissionRecord | null> {}
export interface PermissionRecord extends Record<string, string[] | PermissionRecord | null> {}
export const requirements: PermissionRecord = {
export const requirements: Readonly<PermissionRecord> = {
'': [],
login: [], // ['Auth.edit']
register: [], // ['Auth.edit']

View File

@ -1,44 +1,44 @@
import { Rule } from 'rc-field-form/lib/interface'
const _min1: Rule = {
const _min1: Readonly<Rule> = {
min: 1,
max: 255,
message: 'Допустимая длина 1-255 символов',
}
export const min1: Rule[] = [_min1]
export const min1: Readonly<Rule[]> = [_min1]
export const createLoginRules: Rule[] = [_min1, {
export const createLoginRules: Readonly<Rule[]> = [_min1, {
pattern: /^\s*[A-zА-яЁё][A-zА-яЁё\w.-]+\s*$/,
message: 'Логин должен начинаться с русской или латинской буквы и содержать только символы (А-яA-z0-9_-.)!'
}]
export const loginRules: Rule[] = [...createLoginRules, {
export const loginRules: Readonly<Rule[]> = [...createLoginRules, {
required: true,
message: 'Пожалуйста, введите логин',
}]
export const nameRules: Rule[] = [_min1, {
export const nameRules: Readonly<Rule[]> = [_min1, {
pattern: /^[A-zА-яЁё][A-zА-яЁё-]*$/,
message: 'Допустимые символы: А-яA-z-',
}]
export const phoneRules: Rule[] = [{
export const phoneRules: Readonly<Rule[]> = [{
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<Rule[]> = [{
type: 'email',
message: 'E-mail должен иметь вид: "user@site.domain"',
}]
export const passwordRules: Rule[] = [{
export const passwordRules: Readonly<Rule[]> = [{
required: true,
message: 'Пожалуйста, введите пароль!',
}]
export const createPasswordRules: Rule[] = [{
export const createPasswordRules: Readonly<Rule[]> = [{
min: 8,
max: 255,
message: 'Допустимая длина пароля 8-255',