Files
chpark 690b85805c ECR 기능/스키마 wace_plm 일치 + 공통코드·테이블타입 화면 정리
- 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>
2026-05-11 15:58:54 +09:00

187 lines
6.5 KiB
TypeScript

"use client";
import React, { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { LoadingSpinner } from "@/components/common/LoadingSpinner";
import { CodeCategoryFormModal } from "./CodeCategoryFormModal";
import { CategoryItem } from "./CategoryItem";
import { AlertModal } from "@/components/common/AlertModal";
import { Search, Plus } from "lucide-react";
import { useDeleteCategory } from "@/hooks/queries/useCategories";
import { useCategoriesInfinite } from "@/hooks/queries/useCategoriesInfinite";
interface CodeCategoryPanelProps {
selectedCategoryCode: string;
onSelectCategory: (categoryCode: string) => void;
}
export function CodeCategoryPanel({ selectedCategoryCode, onSelectCategory }: CodeCategoryPanelProps) {
// 검색 및 필터 상태 (먼저 선언)
const [searchTerm, setSearchTerm] = useState("");
const [showActiveOnly, setShowActiveOnly] = useState(false);
// React Query로 카테고리 데이터 관리 (무한 스크롤)
const {
data: categories = [],
isLoading,
error,
handleScroll,
isFetchingNextPage,
hasNextPage,
} = useCategoriesInfinite({
search: searchTerm || undefined,
active: showActiveOnly || undefined, // isActive -> active로 수정
});
const deleteCategoryMutation = useDeleteCategory();
// 모달 상태
const [showFormModal, setShowFormModal] = useState(false);
const [editingCategory, setEditingCategory] = useState<string>("");
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [deletingCategory, setDeletingCategory] = useState<string>("");
// 새 카테고리 생성
const handleNewCategory = () => {
setEditingCategory("");
setShowFormModal(true);
};
// 카테고리 수정
const handleEditCategory = (categoryCode: string) => {
setEditingCategory(categoryCode);
setShowFormModal(true);
};
// 카테고리 삭제 확인
const handleDeleteCategory = (categoryCode: string) => {
setDeletingCategory(categoryCode);
setShowDeleteModal(true);
};
// 카테고리 삭제 실행
const handleConfirmDelete = async () => {
if (!deletingCategory) return;
try {
await deleteCategoryMutation.mutateAsync(deletingCategory);
// 삭제된 카테고리가 선택된 상태라면 선택 해제
if (selectedCategoryCode === deletingCategory) {
onSelectCategory("");
}
setShowDeleteModal(false);
setDeletingCategory("");
} catch (error) {
console.error("카테고리 삭제 실패:", error);
}
};
if (error) {
return (
<div className="flex h-full items-center justify-center">
<div className="text-center">
<p className="text-destructive"> .</p>
<Button variant="outline" onClick={() => window.location.reload()} className="mt-2">
</Button>
</div>
</div>
);
}
return (
<div className="flex h-full min-h-0 flex-col">
{/* 검색 + 등록 + 활성 토글 — 한 줄로 컴팩트 */}
<div className="flex flex-shrink-0 items-center gap-1.5 pb-2">
<div className="relative flex-1">
<Search className="pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="카테고리 검색"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="h-7 pl-7 text-xs"
/>
</div>
<Button onClick={handleNewCategory} size="sm" className="h-7 gap-1 px-2 text-xs">
<Plus className="h-3 w-3" />
</Button>
</div>
<label className="flex flex-shrink-0 items-center gap-1.5 pb-2 text-[11px] text-muted-foreground">
<input
type="checkbox"
checked={showActiveOnly}
onChange={(e) => setShowActiveOnly(e.target.checked)}
className="h-3 w-3 rounded border-input"
/>
</label>
{/* 카테고리 목록 (자체 스크롤 + 무한 스크롤) */}
<div className="min-h-0 flex-1 space-y-1 overflow-y-auto pr-1" onScroll={handleScroll}>
{isLoading ? (
<div className="flex h-24 items-center justify-center">
<LoadingSpinner />
</div>
) : categories.length === 0 ? (
<div className="flex h-24 items-center justify-center">
<p className="text-xs text-muted-foreground">
{searchTerm ? "검색 결과가 없습니다." : "카테고리가 없습니다."}
</p>
</div>
) : (
<>
{categories.map((category, index) => (
<CategoryItem
key={`${category.category_code}-${index}`}
category={category}
isSelected={selectedCategoryCode === category.category_code}
onSelect={() => onSelectCategory(category.category_code)}
onEdit={() => handleEditCategory(category.category_code)}
onDelete={() => handleDeleteCategory(category.category_code)}
/>
))}
{/* 추가 로딩 표시 */}
{isFetchingNextPage && (
<div className="flex items-center justify-center py-2">
<LoadingSpinner size="sm" />
<span className="ml-1.5 text-[11px] text-muted-foreground"> </span>
</div>
)}
{/* 더 이상 데이터가 없을 때 */}
{!hasNextPage && categories.length > 0 && (
<div className="py-2 text-center text-[11px] text-muted-foreground"> </div>
)}
</>
)}
</div>
{/* 카테고리 폼 모달 */}
{showFormModal && (
<CodeCategoryFormModal
isOpen={showFormModal}
onClose={() => setShowFormModal(false)}
editingCategoryCode={editingCategory}
categories={categories}
/>
)}
{/* 삭제 확인 모달 */}
{showDeleteModal && (
<AlertModal
isOpen={showDeleteModal}
onClose={() => setShowDeleteModal(false)}
type="error"
title="카테고리 삭제"
message="정말로 이 카테고리를 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다."
confirmText="삭제"
onConfirm={handleConfirmDelete}
/>
)}
</div>
);
}