690b85805c
- ECR 관리: wace 의 ecrList/Form/Detail JSP 와 동일하게 5개 필터(연도/기종/요청/작성자/상태), 변경전/후 2분할 모달, 작성중(0000100)만 삭제·수정 허용, 컬럼 순서/라벨 wace 일치 - ECR 스키마 wace 풀세트 동기화: ecr_mng 컬럼폭 확장, product_mgmt 16컬럼, part_mng 52컬럼, user_info 22컬럼, comm_code 보강(id/code_cd/ext_val), code_name(varchar) 함수, seq_ecr_no setval(33) 정렬 - wace_plm public.comm_code 733행 시드: src/seed/wace_comm_code.sql 추출 + 부팅 시 자동 적재 (writer='system-seed' placeholder 자동 정리, 무중단 재적재 엔드포인트 /comm-code-seed) - wace_plm 데이터 import 풀스키마: PRODUCT(7→16), PART(6→52), USER_INFO·COMM_CODE 신규 - 공통코드 관리 화면: 제목/설명 축소, 카테고리·코드 카드 → 컴팩트 리스트, 활성 토글 점, 계층 배지 톤다운, hover 시 액션 노출 - 테이블 타입 관리 — 좌측: 한 줄 리스트 + 알파벳 인덱스 sticky 헤더 - 테이블 타입 관리 — 우측: 타입 카드 그리드 → 그룹 셀렉트(기본/참조/자동/첨부/표시변형), 표시이름 제거 + 코멘트(description) Textarea 신설(화면관리에서 기본 라벨로 활용), 시스템 자동 생성 컬럼(id/company_code/writer/created_date/updated_date) 잠금, 표시옵션/고급설정(필수·읽기·기본값·최대길이) 제거 — 화면관리로 이관 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
258 lines
8.9 KiB
TypeScript
258 lines
8.9 KiB
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import { useSortable } from "@dnd-kit/sortable";
|
|
import { CSS } from "@dnd-kit/utilities";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Edit, Trash2, CornerDownRight, Plus, ChevronRight, ChevronDown } from "lucide-react";
|
|
import { cn } from "@/lib/utils";
|
|
import { useUpdateCode } from "@/hooks/queries/useCodes";
|
|
import type { CodeInfo } from "@/types/commonCode";
|
|
|
|
interface SortableCodeItemProps {
|
|
code: CodeInfo;
|
|
categoryCode: string;
|
|
onEdit: () => void;
|
|
onDelete: () => void;
|
|
onAddChild: () => void; // 하위 코드 추가
|
|
isDragOverlay?: boolean;
|
|
maxDepth?: number; // 최대 깊이 (기본값 3)
|
|
hasChildren?: boolean; // 자식이 있는지 여부
|
|
childCount?: number; // 자식 개수
|
|
isExpanded?: boolean; // 펼쳐진 상태
|
|
onToggleExpand?: () => void; // 접기/펼치기 토글
|
|
}
|
|
|
|
export function SortableCodeItem({
|
|
code,
|
|
categoryCode,
|
|
onEdit,
|
|
onDelete,
|
|
onAddChild,
|
|
isDragOverlay = false,
|
|
maxDepth = 3,
|
|
hasChildren = false,
|
|
childCount = 0,
|
|
isExpanded = true,
|
|
onToggleExpand,
|
|
}: SortableCodeItemProps) {
|
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
id: code.codeValue || code.code_value || "",
|
|
disabled: isDragOverlay,
|
|
});
|
|
const updateCodeMutation = useUpdateCode();
|
|
|
|
const style = {
|
|
transform: CSS.Transform.toString(transform),
|
|
transition,
|
|
};
|
|
|
|
// 활성/비활성 토글 핸들러
|
|
const handleToggleActive = async (checked: boolean) => {
|
|
try {
|
|
const codeValue = code.codeValue || code.code_value;
|
|
if (!codeValue) {
|
|
return;
|
|
}
|
|
|
|
await updateCodeMutation.mutateAsync({
|
|
categoryCode,
|
|
codeValue: codeValue,
|
|
data: {
|
|
codeName: code.codeName || code.code_name,
|
|
codeNameEng: code.codeNameEng || code.code_name_eng || "",
|
|
description: code.description || "",
|
|
sortOrder: code.sortOrder || code.sort_order,
|
|
isActive: checked ? "Y" : "N",
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error("코드 활성 상태 변경 실패:", error);
|
|
}
|
|
};
|
|
|
|
// 계층구조 깊이에 따른 들여쓰기
|
|
const depth = code.depth || 1;
|
|
const indentLevel = (depth - 1) * 16; // 16px per level (was 28)
|
|
const hasParent = !!(code.parentCodeValue || code.parent_code_value);
|
|
const isActive = code.isActive === "Y" || code.is_active === "Y";
|
|
|
|
return (
|
|
<div className="flex items-stretch">
|
|
{/* 계층구조 들여쓰기 영역 */}
|
|
{depth > 1 && (
|
|
<div
|
|
className="flex items-center justify-end pr-1"
|
|
style={{ width: `${indentLevel}px`, minWidth: `${indentLevel}px` }}
|
|
>
|
|
<CornerDownRight className="h-3 w-3 text-muted-foreground/50" />
|
|
</div>
|
|
)}
|
|
|
|
<div
|
|
ref={setNodeRef}
|
|
style={style}
|
|
{...attributes}
|
|
{...listeners}
|
|
className={cn(
|
|
"group flex-1 cursor-grab rounded-md border bg-card px-2.5 py-1.5 transition-colors hover:bg-muted/40",
|
|
isDragging && "cursor-grabbing opacity-50 shadow-md",
|
|
depth === 1 && "border-l-2 border-l-primary",
|
|
depth === 2 && "border-l-2 border-l-blue-400",
|
|
depth === 3 && "border-l-2 border-l-emerald-400",
|
|
)}
|
|
>
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex min-w-0 flex-1 items-center gap-1.5">
|
|
{/* 접기/펼치기 버튼 */}
|
|
{hasChildren && onToggleExpand ? (
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
onToggleExpand();
|
|
}}
|
|
onPointerDown={(e) => e.stopPropagation()}
|
|
onMouseDown={(e) => e.stopPropagation()}
|
|
className="flex h-4 w-4 flex-shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
|
|
title={isExpanded ? "접기" : "펼치기"}
|
|
>
|
|
{isExpanded ? <ChevronDown className="h-3 w-3" /> : <ChevronRight className="h-3 w-3" />}
|
|
</button>
|
|
) : (
|
|
<div className="h-4 w-4 flex-shrink-0" />
|
|
)}
|
|
|
|
{/* 활성 토글 (점) */}
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
if (!updateCodeMutation.isPending) handleToggleActive(!isActive);
|
|
}}
|
|
onPointerDown={(e) => e.stopPropagation()}
|
|
onMouseDown={(e) => e.stopPropagation()}
|
|
className={cn(
|
|
"h-1.5 w-1.5 flex-shrink-0 rounded-full transition-colors",
|
|
isActive ? "bg-emerald-500" : "bg-muted-foreground/40",
|
|
updateCodeMutation.isPending && "opacity-50",
|
|
)}
|
|
title={isActive ? "활성 (클릭하여 비활성)" : "비활성 (클릭하여 활성)"}
|
|
/>
|
|
|
|
{/* 코드명 */}
|
|
<span className="truncate text-[13px] font-medium" title={code.codeName || code.code_name}>
|
|
{code.codeName || code.code_name}
|
|
</span>
|
|
|
|
{/* 코드값 (mono) */}
|
|
<span className="hidden flex-shrink-0 font-mono text-[10px] text-muted-foreground sm:inline">
|
|
{code.codeValue || code.code_value}
|
|
</span>
|
|
|
|
{/* 자식 개수(접힌 경우) */}
|
|
{hasChildren && !isExpanded && (
|
|
<span className="flex-shrink-0 text-[10px] text-muted-foreground">({childCount})</span>
|
|
)}
|
|
|
|
{/* 깊이 배지 — 1단계만 표시 (덜 어수선) */}
|
|
{depth === 1 && (
|
|
<Badge
|
|
variant="outline"
|
|
className="ml-1 flex-shrink-0 border-primary/30 bg-primary/5 px-1 py-0 text-[9px] font-medium text-primary"
|
|
>
|
|
대분류
|
|
</Badge>
|
|
)}
|
|
{depth === 2 && (
|
|
<Badge
|
|
variant="outline"
|
|
className="ml-1 flex-shrink-0 border-blue-300 bg-blue-50 px-1 py-0 text-[9px] font-medium text-blue-700 dark:bg-blue-950/20"
|
|
>
|
|
중분류
|
|
</Badge>
|
|
)}
|
|
{depth === 3 && (
|
|
<Badge
|
|
variant="outline"
|
|
className="ml-1 flex-shrink-0 border-emerald-300 bg-emerald-50 px-1 py-0 text-[9px] font-medium text-emerald-700 dark:bg-emerald-950/20"
|
|
>
|
|
소분류
|
|
</Badge>
|
|
)}
|
|
{depth > 3 && (
|
|
<Badge variant="outline" className="ml-1 flex-shrink-0 px-1 py-0 text-[9px]">
|
|
L{depth}
|
|
</Badge>
|
|
)}
|
|
</div>
|
|
|
|
{/* 액션 — hover 시 노출 */}
|
|
<div
|
|
className="flex flex-shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100"
|
|
onPointerDown={(e) => e.stopPropagation()}
|
|
onMouseDown={(e) => e.stopPropagation()}
|
|
>
|
|
{depth < maxDepth && (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-6 w-6 text-primary hover:bg-primary/10"
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
onAddChild();
|
|
}}
|
|
title="하위 코드 추가"
|
|
>
|
|
<Plus className="h-3 w-3" />
|
|
</Button>
|
|
)}
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-6 w-6"
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
onEdit();
|
|
}}
|
|
title="수정"
|
|
>
|
|
<Edit className="h-3 w-3" />
|
|
</Button>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-6 w-6 text-destructive hover:bg-destructive/10"
|
|
onClick={(e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
onDelete();
|
|
}}
|
|
title="삭제"
|
|
>
|
|
<Trash2 className="h-3 w-3" />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 부모 표시(있을 때만, 한 줄) */}
|
|
{hasParent && (
|
|
<p className="ml-7 mt-0.5 truncate font-mono text-[10px] text-muted-foreground">
|
|
↳ {code.parentCodeValue || code.parent_code_value}
|
|
</p>
|
|
)}
|
|
{code.description && (
|
|
<p className="ml-7 mt-0.5 truncate text-[11px] text-muted-foreground" title={code.description}>
|
|
{code.description}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|