268 lines
6.1 KiB
Markdown
268 lines
6.1 KiB
Markdown
|
|
# DataContext.tsx 리팩토링 계획
|
||
|
|
|
||
|
|
## 현황 분석
|
||
|
|
|
||
|
|
### 기존 파일 구조
|
||
|
|
- **총 라인**: 6,707줄
|
||
|
|
- **파일 크기**: 222KB
|
||
|
|
- **상태 변수**: 33개
|
||
|
|
- **타입 정의**: 50개 이상
|
||
|
|
|
||
|
|
### 문제점
|
||
|
|
1. 단일 파일에 모든 도메인 집중 → 유지보수 불가능
|
||
|
|
2. 6700줄 분석 시 토큰 과다 소비 → 세션 종료 빈번
|
||
|
|
3. 관련 없는 데이터도 항상 로드 → 성능 저하
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 도메인 분류 (10개 도메인, 33개 상태)
|
||
|
|
|
||
|
|
### 1. ItemMaster (품목 마스터) - 13개 상태
|
||
|
|
**파일**: `contexts/ItemMasterContext.tsx`
|
||
|
|
**관련 페이지**: 품목관리, 품목기준관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- itemMasters (품목 마스터 데이터)
|
||
|
|
- specificationMasters (규격 마스터)
|
||
|
|
- materialItemNames (자재 품목명)
|
||
|
|
- itemCategories (품목 분류)
|
||
|
|
- itemUnits (단위)
|
||
|
|
- itemMaterials (재질)
|
||
|
|
- surfaceTreatments (표면처리)
|
||
|
|
- partTypeOptions (부품 유형 옵션)
|
||
|
|
- partUsageOptions (부품 용도 옵션)
|
||
|
|
- guideRailOptions (가이드레일 옵션)
|
||
|
|
- sectionTemplates (섹션 템플릿)
|
||
|
|
- itemMasterFields (품목 필드 정의)
|
||
|
|
- itemPages (품목 입력 페이지)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- ItemMaster, ItemRevisio1n, ItemCategory, ItemUnit, ItemMaterial
|
||
|
|
- SurfaceTreatment, PartTypeOption, PartUsageOption, GuideRailOption
|
||
|
|
- ItemMasterField, ItemFieldProperty, FieldDisplayCondition
|
||
|
|
- ItemField, ItemSection, ItemPage, SectionTemplate
|
||
|
|
- SpecificationMaster, MaterialItemName
|
||
|
|
- BOMLine, BOMItem, BendingDetail
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 2. Sales (판매) - 3개 상태
|
||
|
|
**파일**: `contexts/SalesContext.tsx`
|
||
|
|
**관련 페이지**: 견적관리, 수주관리, 거래처관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- salesOrders (수주 데이터)
|
||
|
|
- quotes (견적 데이터)
|
||
|
|
- clients (거래처 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- SalesOrder, SalesOrderItem, OrderRevision, DocumentSendHistory
|
||
|
|
- Quote, QuoteRevision, QuoteCalculationRow, BOMCalculationRow
|
||
|
|
- Client
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 3. Production (생산) - 2개 상태
|
||
|
|
**파일**: `contexts/ProductionContext.tsx`
|
||
|
|
**관련 페이지**: 생산관리, 품질관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- productionOrders (생산지시 데이터)
|
||
|
|
- qualityInspections (품질검사 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- ProductionOrder
|
||
|
|
- QualityInspection
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 4. Inventory (재고) - 2개 상태
|
||
|
|
**파일**: `contexts/InventoryContext.tsx`
|
||
|
|
**관련 페이지**: 재고관리, 구매관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- inventoryItems (재고 데이터)
|
||
|
|
- purchaseOrders (구매 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- InventoryItem
|
||
|
|
- PurchaseOrder
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 5. Shipping (출고) - 1개 상태
|
||
|
|
**파일**: `contexts/ShippingContext.tsx`
|
||
|
|
**관련 페이지**: 출고관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- shippingOrders (출고지시서 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- ShippingOrder, ShippingOrderItem
|
||
|
|
- ShippingSchedule, ShippingLot, ShippingLotItem
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 6. HR (인사) - 3개 상태
|
||
|
|
**파일**: `contexts/HRContext.tsx`
|
||
|
|
**관련 페이지**: 직원관리, 근태관리, 결재관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- employees (직원 데이터)
|
||
|
|
- attendances (근태 데이터)
|
||
|
|
- approvals (결재 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- Employee
|
||
|
|
- Attendance
|
||
|
|
- Approval
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 7. Accounting (회계) - 2개 상태
|
||
|
|
**파일**: `contexts/AccountingContext.tsx`
|
||
|
|
**관련 페이지**: 회계관리, 매출채권관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- accountingTransactions (회계 거래 데이터)
|
||
|
|
- receivables (매출채권 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- AccountingTransaction
|
||
|
|
- Receivable
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 8. Facilities (시설) - 2개 상태
|
||
|
|
**파일**: `contexts/FacilitiesContext.tsx`
|
||
|
|
**관련 페이지**: 차량관리, 현장관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- vehicles (차량 데이터)
|
||
|
|
- sites (현장 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- Vehicle
|
||
|
|
- Site, SiteAttachment
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 9. Pricing (가격/계산식) - 3개 상태
|
||
|
|
**파일**: `contexts/PricingContext.tsx`
|
||
|
|
**관련 페이지**: 가격관리, 계산식관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- formulas (계산식 데이터)
|
||
|
|
- formulaRules (계산식 규칙 데이터)
|
||
|
|
- pricing (가격 데이터)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- CalculationFormula, FormulaRevision
|
||
|
|
- FormulaRule, FormulaRuleRevision, RangeRule
|
||
|
|
- PricingData, PriceRevision
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### 10. Auth (인증) - 2개 상태
|
||
|
|
**파일**: `contexts/AuthContext.tsx`
|
||
|
|
**관련 페이지**: 로그인, 사용자관리
|
||
|
|
|
||
|
|
상태:
|
||
|
|
- users (사용자 데이터)
|
||
|
|
- currentUser (현재 사용자)
|
||
|
|
|
||
|
|
타입:
|
||
|
|
- User, UserRole
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 공통 타입 파일
|
||
|
|
|
||
|
|
### types/index.ts
|
||
|
|
재사용되는 공통 타입 정의:
|
||
|
|
- 없음 (각 도메인이 독립적)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 통합 Provider
|
||
|
|
|
||
|
|
### contexts/RootProvider.tsx
|
||
|
|
모든 Context를 통합하는 최상위 Provider
|
||
|
|
|
||
|
|
```tsx
|
||
|
|
export function RootProvider({ children }: { children: ReactNode }) {
|
||
|
|
return (
|
||
|
|
<AuthProvider>
|
||
|
|
<ItemMasterProvider>
|
||
|
|
<SalesProvider>
|
||
|
|
<ProductionProvider>
|
||
|
|
<InventoryProvider>
|
||
|
|
<ShippingProvider>
|
||
|
|
<HRProvider>
|
||
|
|
<AccountingProvider>
|
||
|
|
<FacilitiesProvider>
|
||
|
|
<PricingProvider>
|
||
|
|
{children}
|
||
|
|
</PricingProvider>
|
||
|
|
</FacilitiesProvider>
|
||
|
|
</AccountingProvider>
|
||
|
|
</HRProvider>
|
||
|
|
</ShippingProvider>
|
||
|
|
</InventoryProvider>
|
||
|
|
</ProductionProvider>
|
||
|
|
</SalesProvider>
|
||
|
|
</ItemMasterProvider>
|
||
|
|
</AuthProvider>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 마이그레이션 체크리스트
|
||
|
|
|
||
|
|
### Phase 1: 준비
|
||
|
|
- [x] 전체 구조 분석
|
||
|
|
- [x] 도메인 분류 설계
|
||
|
|
- [ ] 기존 파일 백업
|
||
|
|
|
||
|
|
### Phase 2: Context 생성 (10개)
|
||
|
|
- [ ] AuthContext.tsx
|
||
|
|
- [ ] ItemMasterContext.tsx
|
||
|
|
- [ ] SalesContext.tsx
|
||
|
|
- [ ] ProductionContext.tsx
|
||
|
|
- [ ] InventoryContext.tsx
|
||
|
|
- [ ] ShippingContext.tsx
|
||
|
|
- [ ] HRContext.tsx
|
||
|
|
- [ ] AccountingContext.tsx
|
||
|
|
- [ ] FacilitiesContext.tsx
|
||
|
|
- [ ] PricingContext.tsx
|
||
|
|
|
||
|
|
### Phase 3: 통합
|
||
|
|
- [ ] RootProvider.tsx 생성
|
||
|
|
- [ ] app/layout.tsx에서 RootProvider 적용
|
||
|
|
- [ ] 기존 DataContext.tsx 삭제
|
||
|
|
|
||
|
|
### Phase 4: 검증
|
||
|
|
- [ ] 빌드 테스트 (npm run build)
|
||
|
|
- [ ] 타입 체크 (npm run type-check)
|
||
|
|
- [ ] 품목관리 페이지 동작 확인
|
||
|
|
- [ ] 기타 페이지 동작 확인
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 예상 효과
|
||
|
|
|
||
|
|
### 파일 크기 감소
|
||
|
|
- 기존: 6,707줄 → 각 도메인: 평균 500-1,500줄
|
||
|
|
- ItemMaster: ~2,000줄 (가장 큼)
|
||
|
|
- Auth: ~300줄 (가장 작음)
|
||
|
|
|
||
|
|
### 토큰 사용량 감소
|
||
|
|
- 품목관리 작업 시: 70% 감소
|
||
|
|
- 기타 페이지 작업 시: 60-80% 감소
|
||
|
|
|
||
|
|
### 유지보수성 향상
|
||
|
|
- 도메인별 독립적 관리
|
||
|
|
- 수정 시 영향 범위 명확
|
||
|
|
- 협업 시 충돌 최소화
|