From a5e0c8bf0f0fd970734edb03cbcabe8ab0ef976b Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 21 May 2026 07:25:28 +0300 Subject: [PATCH] Render 1C form items hierarchically --- .../src/components/editor/ide-workspace.tsx | 140 +++++++++++++++--- 1 file changed, 117 insertions(+), 23 deletions(-) diff --git a/frontend/sfera-web/src/components/editor/ide-workspace.tsx b/frontend/sfera-web/src/components/editor/ide-workspace.tsx index 00e8f57..7a5061d 100644 --- a/frontend/sfera-web/src/components/editor/ide-workspace.tsx +++ b/frontend/sfera-web/src/components/editor/ide-workspace.tsx @@ -3075,7 +3075,7 @@ function FormDesignerPanel({ const updateElement = (id: string, patch: Partial) => { setElementDrafts((current) => ({ ...current, - [formKey]: (current[formKey] ?? baseElements).map((element) => (element.id === id ? { ...element, ...patch } : element)) + [formKey]: updateIdeFormElementTree(current[formKey] ?? baseElements, id, patch) })); }; @@ -3090,7 +3090,8 @@ function FormDesignerPanel({ caption: name, controlKind: newElementKind, binding: name, - width: "stretch" + width: "stretch", + children: [] }; setElementDrafts((current) => ({ ...current, [formKey]: [...(current[formKey] ?? baseElements), next] })); setNewElementName(""); @@ -3130,10 +3131,10 @@ function FormDesignerPanel({
{t.formElements}
- {elements.length === 0 ? ( + {flattenIdeFormElements(elements).length === 0 ? (
{t.none}
) : ( - elements.map((element) => ( + flattenIdeFormElements(elements).map((element) => (
@@ -3239,7 +3240,7 @@ function FormDesignerPanel({
- +
@@ -3260,7 +3261,7 @@ function FormDesignerPanel({
- {elements.map((element) => ( + {flattenIdeFormElements(elements).map((element) => (
{element.name}
updateElement(element.id, { caption: event.target.value })} /> @@ -3296,10 +3297,41 @@ type IdeFormElementDraft = { controlKind: "input" | "date" | "checkbox" | "table" | "group" | "text"; binding: string; width: "stretch" | "half" | "third"; + qualifiedName?: string; + parentQualifiedName?: string | null; + children: IdeFormElementDraft[]; }; function IdeFormControl({ element, forceHalf }: Readonly<{ element: IdeFormElementDraft; forceHalf: boolean }>) { - const span = element.controlKind === "table" || element.controlKind === "group" ? "col-span-12" : forceHalf || element.width === "half" ? "col-span-6" : element.width === "third" ? "col-span-4" : "col-span-12"; + const span = element.controlKind === "table" || element.controlKind === "group" || element.controlKind === "text" ? "col-span-12" : forceHalf || element.width === "half" ? "col-span-6" : element.width === "third" ? "col-span-4" : "col-span-12"; + if (element.controlKind === "table") { + return ( +
+
+ {element.caption} + {element.binding} +
+ {ideFormControlInput(element)} +
+ ); + } + if (element.controlKind === "group") { + return ( +
+ {element.caption} +
+ {element.children.length ? element.children.map((child) => ) : null} +
+
+ ); + } + if (element.controlKind === "text") { + return ( +
+ {ideFormControlInput(element)} +
+ ); + } return (
@@ -3310,15 +3342,24 @@ function IdeFormControl({ element, forceHalf }: Readonly<{ element: IdeFormEleme function ideFormControlInput(element: IdeFormElementDraft) { if (element.controlKind === "table") { + const columns = element.children.filter((child) => child.controlKind !== "text" && child.controlKind !== "group"); + const visibleColumns = columns.length ? columns : [{ ...element, caption: element.caption, name: element.name, id: `${element.id}.column`, children: [] }]; return ( -
-
- {element.binding} - Количество - Сумма +
+
+ {visibleColumns.slice(0, 8).map((column) => ( + + {column.caption} + + ))}
-
-
+ {[0, 1, 2].map((row) => ( +
+ {visibleColumns.slice(0, 8).map((column) => ( + + ))} +
+ ))}
); } @@ -3329,7 +3370,7 @@ function ideFormControlInput(element: IdeFormElementDraft) { return
{element.binding}
; } if (element.controlKind === "text") { - return