"use client";
import React, { useState, useEffect, useMemo } from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { RackStructureComponentConfig, FieldMapping } from "./types";
import { applyLocationPattern, DEFAULT_CODE_PATTERN, DEFAULT_NAME_PATTERN, PATTERN_VARIABLES } from "./patternUtils";
// 패턴 미리보기 서브 컴포넌트
const PatternPreview: React.FC<{
codePattern?: string;
namePattern?: string;
}> = ({ codePattern, namePattern }) => {
const sampleVars = {
warehouse: "WH002",
warehouseName: "2창고",
floor: "2층",
zone: "A구역",
row: 1,
level: 3,
};
const previewCode = useMemo(
() => applyLocationPattern(codePattern || DEFAULT_CODE_PATTERN, sampleVars),
[codePattern],
);
const previewName = useMemo(
() => applyLocationPattern(namePattern || DEFAULT_NAME_PATTERN, sampleVars),
[namePattern],
);
return (
미리보기 (2창고 / 2층 / A구역 / 1열 / 3단)
위치코드:
{previewCode}
위치명:
{previewName}
);
};
interface RackStructureConfigPanelProps {
config: RackStructureComponentConfig;
onChange: (config: RackStructureComponentConfig) => void;
// 화면관리에서 전달하는 테이블 컬럼 정보
tables?: Array<{
tableName: string;
tableLabel?: string;
columns: Array<{
columnName: string;
columnLabel?: string;
dataType?: string;
}>;
}>;
}
export const RackStructureConfigPanel: React.FC = ({
config,
onChange,
tables = [],
}) => {
// 사용 가능한 컬럼 목록 추출
const [availableColumns, setAvailableColumns] = useState<
Array<{ value: string; label: string }>
>([]);
useEffect(() => {
// 모든 테이블의 컬럼을 플랫하게 추출
const columns: Array<{ value: string; label: string }> = [];
tables.forEach((table) => {
table.columns.forEach((col) => {
columns.push({
value: col.columnName,
label: col.columnLabel || col.columnName,
});
});
});
setAvailableColumns(columns);
}, [tables]);
const handleChange = (key: keyof RackStructureComponentConfig, value: any) => {
onChange({ ...config, [key]: value });
};
const handleFieldMappingChange = (field: keyof FieldMapping, value: string) => {
const currentMapping = config.fieldMapping || {};
onChange({
...config,
fieldMapping: {
...currentMapping,
[field]: value === "__none__" ? undefined : value,
},
});
};
const fieldMapping = config.fieldMapping || {};
return (
{/* 필드 매핑 섹션 */}
필드 매핑
상위 폼에 배치된 필드 중 어떤 필드를 사용할지 선택하세요
{/* 창고 코드 필드 */}
{/* 창고명 필드 */}
{/* 층 필드 */}
{/* 구역 필드 */}
{/* 위치 유형 필드 */}
{/* 사용 여부 필드 */}
{/* 위치코드 패턴 설정 */}
위치코드/위치명 패턴
변수를 조합하여 위치코드와 위치명 생성 규칙을 설정하세요
{/* 위치코드 패턴 */}
{/* 위치명 패턴 */}
{/* 실시간 미리보기 */}
{/* 사용 가능한 변수 목록 */}
사용 가능한 변수
{PATTERN_VARIABLES.map((v) => (
{v.token}
{v.description}
))}
{/* 제한 설정 */}
{/* UI 설정 */}
UI 설정
handleChange("showTemplates", checked)}
/>
handleChange("showPreview", checked)}
/>
handleChange("showStatistics", checked)}
/>
handleChange("readonly", checked)}
/>
);
};