테이블 컬럼 중복 삽입 안되게 수정
This commit is contained in:
parent
0c3ce4d3eb
commit
e934cc945b
|
|
@ -356,6 +356,33 @@ export default function ScreenDesigner({ selectedScreen, onBackToList }: ScreenD
|
|||
);
|
||||
}, [tables, searchTerm]);
|
||||
|
||||
// 이미 배치된 컬럼 목록 계산
|
||||
const placedColumns = useMemo(() => {
|
||||
const placed = new Set<string>();
|
||||
|
||||
const collectColumns = (components: ComponentData[]) => {
|
||||
components.forEach((comp) => {
|
||||
const anyComp = comp as any;
|
||||
|
||||
// widget 타입 또는 component 타입 (새로운 시스템)에서 tableName과 columnName 확인
|
||||
if ((comp.type === "widget" || comp.type === "component") && anyComp.tableName && anyComp.columnName) {
|
||||
const key = `${anyComp.tableName}.${anyComp.columnName}`;
|
||||
placed.add(key);
|
||||
console.log("🔍 배치된 컬럼 발견:", key, "타입:", comp.type);
|
||||
}
|
||||
|
||||
// 자식 컴포넌트도 확인 (재귀)
|
||||
if (comp.children && comp.children.length > 0) {
|
||||
collectColumns(comp.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
collectColumns(layout.components);
|
||||
console.log("📋 배치된 컬럼 목록:", Array.from(placed));
|
||||
return placed;
|
||||
}, [layout.components]);
|
||||
|
||||
// 히스토리에 저장
|
||||
const saveToHistory = useCallback(
|
||||
(newLayout: LayoutData) => {
|
||||
|
|
@ -3926,6 +3953,7 @@ export default function ScreenDesigner({ selectedScreen, onBackToList }: ScreenD
|
|||
e.dataTransfer.setData("application/json", JSON.stringify(dragData));
|
||||
}}
|
||||
selectedTableName={selectedScreen.tableName}
|
||||
placedColumns={placedColumns}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ interface ComponentsPanelProps {
|
|||
onSearchChange?: (value: string) => void;
|
||||
onTableDragStart?: (e: React.DragEvent, table: TableInfo, column?: ColumnInfo) => void;
|
||||
selectedTableName?: string;
|
||||
placedColumns?: Set<string>; // 이미 배치된 컬럼명 집합
|
||||
}
|
||||
|
||||
export function ComponentsPanel({
|
||||
|
|
@ -26,7 +27,8 @@ export function ComponentsPanel({
|
|||
searchTerm = "",
|
||||
onSearchChange,
|
||||
onTableDragStart,
|
||||
selectedTableName
|
||||
selectedTableName,
|
||||
placedColumns
|
||||
}: ComponentsPanelProps) {
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
||||
|
|
@ -207,6 +209,7 @@ export function ComponentsPanel({
|
|||
onSearchChange={onSearchChange || (() => {})}
|
||||
onDragStart={onTableDragStart}
|
||||
selectedTableName={selectedTableName}
|
||||
placedColumns={placedColumns}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-32 items-center justify-center text-center">
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ interface TablesPanelProps {
|
|||
onSearchChange: (term: string) => void;
|
||||
onDragStart: (e: React.DragEvent, table: TableInfo, column?: any) => void;
|
||||
selectedTableName?: string;
|
||||
placedColumns?: Set<string>; // 이미 배치된 컬럼명 집합 (tableName.columnName 형식)
|
||||
}
|
||||
|
||||
// 위젯 타입별 아이콘
|
||||
|
|
@ -67,6 +68,7 @@ export const TablesPanel: React.FC<TablesPanelProps> = ({
|
|||
onSearchChange,
|
||||
onDragStart,
|
||||
selectedTableName,
|
||||
placedColumns = new Set(),
|
||||
}) => {
|
||||
const [expandedTables, setExpandedTables] = useState<Set<string>>(new Set());
|
||||
|
||||
|
|
@ -80,11 +82,26 @@ export const TablesPanel: React.FC<TablesPanelProps> = ({
|
|||
setExpandedTables(newExpanded);
|
||||
};
|
||||
|
||||
const filteredTables = tables.filter(
|
||||
(table) =>
|
||||
table.tableName.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
table.columns.some((col) => col.columnName.toLowerCase().includes(searchTerm.toLowerCase())),
|
||||
);
|
||||
// 이미 배치된 컬럼을 제외한 테이블 정보 생성
|
||||
const tablesWithAvailableColumns = tables.map((table) => ({
|
||||
...table,
|
||||
columns: table.columns.filter((col) => {
|
||||
const columnKey = `${table.tableName}.${col.columnName}`;
|
||||
const isPlaced = placedColumns.has(columnKey);
|
||||
if (isPlaced) {
|
||||
console.log("🚫 필터링된 컬럼:", columnKey);
|
||||
}
|
||||
return !isPlaced;
|
||||
}),
|
||||
}));
|
||||
|
||||
const filteredTables = tablesWithAvailableColumns
|
||||
.filter((table) => table.columns.length > 0) // 사용 가능한 컬럼이 있는 테이블만 표시
|
||||
.filter(
|
||||
(table) =>
|
||||
table.tableName.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
table.columns.some((col) => col.columnName.toLowerCase().includes(searchTerm.toLowerCase())),
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
|
|
|
|||
Loading…
Reference in New Issue