From dee9ae7ad670e08219f9207b19e1bfe221fc5207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=D1=81=20=D0=A1=D1=83=D0=BB=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 21 Jul 2026 14:24:35 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BE=D1=87=D0=BD=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA=D0=B5=20=D0=BA=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SubdirectoryFieldConfig.tsx | 51 +++---------------- .../components/TableFieldWithSubdirectory.tsx | 26 ++++------ 2 files changed, 17 insertions(+), 60 deletions(-) diff --git a/client/src/components/SubdirectoryFieldConfig.tsx b/client/src/components/SubdirectoryFieldConfig.tsx index f797dd3..3a414e1 100644 --- a/client/src/components/SubdirectoryFieldConfig.tsx +++ b/client/src/components/SubdirectoryFieldConfig.tsx @@ -47,11 +47,6 @@ export default function SubdirectoryFieldConfig({ const subdirectories = subdirectoriesData?.subdirectories || []; const showSubdirectory = !!field.options?.showSubdirectory; - const selectedSubdirectoryId = field.options?.subdirectoryId as number | undefined; - - const selectedSubdirectory = useMemo(() => { - return subdirectories.find((s) => s.id === selectedSubdirectoryId || s.childTableId === selectedSubdirectoryId); - }, [subdirectories, selectedSubdirectoryId]); const selectedTable = useMemo(() => { return tablesData?.tables?.find((t) => t.id === tableId); @@ -65,7 +60,6 @@ export default function SubdirectoryFieldConfig({ tableId: undefined, displayColumn: undefined, showSubdirectory: undefined, - subdirectoryId: undefined, }, }); return; @@ -78,7 +72,6 @@ export default function SubdirectoryFieldConfig({ tableId: newTableId, displayColumn: newSelectedTable?.columns?.[0]?.name || undefined, showSubdirectory: undefined, - subdirectoryId: undefined, }, }); }; @@ -88,18 +81,6 @@ export default function SubdirectoryFieldConfig({ options: { ...field.options, showSubdirectory: checked, - subdirectoryId: checked ? field.options?.subdirectoryId : undefined, - }, - }); - }; - - const handleSubdirectoryChange = (value: string) => { - const newSubdirectory = value === 'none' ? undefined : subdirectories.find((s) => s.id?.toString() === value || s.childTableId?.toString() === value); - updateField(index, { - options: { - ...field.options, - subdirectoryId: newSubdirectory?.id, - childTableId: newSubdirectory?.childTableId, }, }); }; @@ -178,32 +159,12 @@ export default function SubdirectoryFieldConfig({ {showSubdirectory && ( -
- - - {selectedSubdirectory && ( -

- Подсправочник показывается при выборе привязанных строк родителя. -

- )} -
+

+ При выборе строки родительского справочника будет показан подсправочник, привязанный к этой строке. + {subdirectories.length > 0 + ? ` Найдено подсправочников: ${subdirectories.length}.` + : ' Нет привязанных подсправочников.'} +

)} )} diff --git a/client/src/components/TableFieldWithSubdirectory.tsx b/client/src/components/TableFieldWithSubdirectory.tsx index 8b8f189..a07a8fe 100644 --- a/client/src/components/TableFieldWithSubdirectory.tsx +++ b/client/src/components/TableFieldWithSubdirectory.tsx @@ -65,7 +65,6 @@ export default function TableFieldWithSubdirectory({ const opts = options && !Array.isArray(options) ? (options as Record) : {}; const tableId = opts.tableId as number | undefined; const showSubdirectory = !!opts.showSubdirectory; - const subdirectoryId = opts.subdirectoryId as number | undefined; const { data: subdirectoriesData } = useQuery<{ subdirectories: DataTableSubdirectory[] }>({ queryKey: ['/api/directories', tableId, 'subdirectories'], @@ -77,16 +76,14 @@ export default function TableFieldWithSubdirectory({ staleTime: 60 * 1000, }); - const subdirectory = useMemo(() => { - return subdirectoriesData?.subdirectories?.find((s) => s.id === subdirectoryId); - }, [subdirectoriesData, subdirectoryId]); - const { parentId, childId } = parseTableValue(value); - const isParentLinked = useMemo(() => { - if (!subdirectory || !parentId) return false; - return subdirectory.parentRowIds?.includes(Number(parentId)) ?? false; - }, [subdirectory, parentId]); + const subdirectory = useMemo(() => { + if (!parentId) return undefined; + return subdirectoriesData?.subdirectories?.find((s) => + s.parentRowIds?.includes(Number(parentId)) + ); + }, [subdirectoriesData, parentId]); const handleParentChange = (newParentId: string) => { onChange(serializeTableValue(newParentId || null, null)); @@ -96,7 +93,7 @@ export default function TableFieldWithSubdirectory({ onChange(serializeTableValue(parentId, newChildId || null)); }; - if (!showSubdirectory || !subdirectory || allowMultiple) { + if (!showSubdirectory || allowMultiple) { const SelectComponent = allowMultiple ? TableFieldMultiSelect : TableFieldSelect; return ( @@ -126,7 +122,7 @@ export default function TableFieldWithSubdirectory({ value={parentId || ''} onChange={handleParentChange} /> - {isParentLinked && ( + {subdirectory && (