AI рефакторинг !
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
import { Textarea } from '@/component/ui/textarea'
|
||||
import { useTemplateContext } from '@/entitiy/template/model/TemplateContext'
|
||||
import { getElementDefinition } from '@/lib/element-registry'
|
||||
import { getLatestFileForTemplate } from '@/service/fileApiSevice'
|
||||
import { getLatestFileForTemplate } from '@/service/fileApiService'
|
||||
import { Template, TemplateElement } from '@/type/template'
|
||||
import {
|
||||
ArrowLeft,
|
||||
@@ -371,25 +371,6 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
||||
const [showSpreadsheet, setShowSpreadsheet] = useState(false)
|
||||
const engineRef = useRef<any>(null)
|
||||
|
||||
// 👉 Хелперы для конвертации адреса ячейки
|
||||
const labelToColumn = (label: string) => {
|
||||
let col = 0
|
||||
for (let i = 0; i < label.length; i++) {
|
||||
col = col * 26 + (label.charCodeAt(i) - 64)
|
||||
}
|
||||
return col - 1 // zero-based
|
||||
}
|
||||
|
||||
const parseCellAddress = (addr: string) => {
|
||||
const match = addr.match(/([A-Z]+)(\d+)/i)
|
||||
if (!match) return { row: 0, col: 0 }
|
||||
const [, colLabel, rowNum] = match
|
||||
return {
|
||||
row: parseInt(rowNum, 10) - 1,
|
||||
col: labelToColumn(colLabel),
|
||||
}
|
||||
}
|
||||
|
||||
const handleFieldChange = (elementId: string, value: any) => {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
@@ -401,7 +382,7 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
||||
const element = template.elements.find(el => el.id === elementId)
|
||||
if (element && element.targetCells) {
|
||||
element.targetCells.forEach(tc => {
|
||||
const { row, col } = parseCellAddress(tc.cell)
|
||||
const { row, col } = cellAddressToCoordinates(tc.cell)
|
||||
const sheetName =
|
||||
tc.sheet === 'R' || tc.sheet === 'Calculations' ? 'R' : 'L'
|
||||
engineRef.current.setCellValueWithoutRecalc(
|
||||
@@ -464,7 +445,7 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
||||
}
|
||||
|
||||
cells?.forEach(tc => {
|
||||
const { row, col } = parseCellAddress(tc.cell)
|
||||
const { row, col } = cellAddressToCoordinates(tc.cell)
|
||||
const sheetName =
|
||||
tc.sheet === 'R' || tc.sheet === 'Calculations' ? 'R' : 'L'
|
||||
console.log(
|
||||
@@ -493,7 +474,7 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
||||
const cellsToUpdate: Record<string, any> = {}
|
||||
const modifiedLeft = allModified['L'] || {}
|
||||
Object.keys(modifiedLeft).forEach(cellAddress => {
|
||||
const { row, col } = parseCellAddress(cellAddress)
|
||||
const { row, col } = cellAddressToCoordinates(cellAddress)
|
||||
cellsToUpdate[cellAddress] = engineRef.current.getCellValue(
|
||||
'L',
|
||||
row,
|
||||
|
||||
Reference in New Issue
Block a user