баг изчезающие элементы
This commit is contained in:
@@ -698,7 +698,11 @@ const CanvasSettings: React.FC<CanvasSettingsProps> = ({
|
||||
interface ElementConstructorProps {
|
||||
template: Template
|
||||
onElementAdd: (element: TemplateElement) => void
|
||||
onElementUpdate: (elementId: string, element: TemplateElement) => void
|
||||
// Принимаем частичное обновление элемента, чтобы корректно обновлять только изменённые поля
|
||||
onElementUpdate: (
|
||||
elementId: string,
|
||||
updates: Partial<TemplateElement>
|
||||
) => void
|
||||
onElementDelete: (elementId: string) => void
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export const ElementsCreation: FC = () => {
|
||||
|
||||
const handleElementUpdate = async (
|
||||
elementId: string,
|
||||
updatedElement: TemplateElement
|
||||
updates: Partial<TemplateElement>
|
||||
) => {
|
||||
if (!selectedTemplate) return
|
||||
|
||||
@@ -68,7 +68,15 @@ export const ElementsCreation: FC = () => {
|
||||
const updatedTemplate = {
|
||||
...selectedTemplate,
|
||||
elements: selectedTemplate.elements.map(el =>
|
||||
el.id === elementId ? updatedElement : el
|
||||
el.id === elementId
|
||||
? {
|
||||
...el,
|
||||
// Обновляем только определённые ключи, чтобы не затирать существующие значения `undefined`
|
||||
...Object.fromEntries(
|
||||
Object.entries(updates).filter(([, v]) => v !== undefined)
|
||||
),
|
||||
}
|
||||
: el
|
||||
),
|
||||
updatedAt: new Date(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user