[feat] negodata: 협력사↔상품 매핑(취급상품·공급유형) + 견적 픽리스트 서버검색 콤보박스
- partner.supplier_items 매핑테이블 신설: supply_type(0없음/1유통/2제조/3총판), 부분 유니크 인덱스(soft-delete 인지). quotations.supplier_type와 의미단위 달라 컬럼명 supply_type. - 백엔드: supplier_item CRUD/service/router(/v1/supplier-item, by-supplier·by-item·create·bulk·update·delete). 소유권 company 스코프. ErrorType.SUPPLIER_ITEM_NOT_FOUND 추가. - DDL: 01-schema/04-alter(날짜접미 리네임) + dev DB 반영. - 프론트(feature): 협력사 엑셀 '취급상품' 컬럼(콤마 상품명→일괄매핑, 이름 미매칭 스킵+리포트, 유형 안받고 없음), 협력사 상세 취급상품 관리(추가/삭제/유형변경 즉시반영), 견적모달 협력사 리스트에 선택상품 공급유형 배지. - 재사용 서버검색 Combobox 신설 → 취급상품·견적상품·협력사초청·협상카드 픽리스트에 적용(size 100 캡 해소, 검색은 서버 ILIKE). 견적 선택상품 파생값은 useGetItem 단건조회로 안정화. - orval 재생성(supplier-item 클라이언트/모델). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ed175c5b65
commit
43dbcbcd96
37 files changed
+1871
-91
No files matched your search
@@ -0,0 +1,178 @@
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
||||
import { Search, Check, Loader2, ChevronsUpDown } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Input } from './input';
|
||||
import { Typography } from './typography';
|
||||
|
||||
// 서버검색 콤보박스 — 목록(options)은 부모가 쿼리에 맞춰 조회해 넘기고, 검색어 디바운스는 이 컴포넌트가 처리한다.
|
||||
// variant: 'field'(트리거+팝오버, 단일선택 폼용) / 'inline'(검색창+리스트 상시노출, 다중 체크리스트용).
|
||||
export type ComboOption = {
|
||||
id: string;
|
||||
label: string; // 검색결과에 없을 때 선택 표시용 텍스트
|
||||
node?: ReactNode; // 커스텀 행(미지정 시 label 렌더)
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
type ComboboxProps = {
|
||||
options: ComboOption[];
|
||||
onQueryChange: (q: string) => void; // 내부 디바운스 후 호출
|
||||
loading?: boolean;
|
||||
placeholder?: string;
|
||||
searchPlaceholder?: string;
|
||||
emptyText?: string;
|
||||
debounceMs?: number;
|
||||
id?: string;
|
||||
className?: string;
|
||||
maxListHeight?: string; // tailwind, default max-h-56
|
||||
variant?: 'field' | 'inline';
|
||||
multiple?: boolean;
|
||||
// single
|
||||
value?: string;
|
||||
selectedLabel?: ReactNode;
|
||||
onSelect?: (opt: ComboOption) => void;
|
||||
// multi
|
||||
values?: string[];
|
||||
onToggle?: (opt: ComboOption) => void;
|
||||
};
|
||||
|
||||
export function Combobox({
|
||||
options,
|
||||
onQueryChange,
|
||||
loading,
|
||||
placeholder = '선택...',
|
||||
searchPlaceholder = '검색...',
|
||||
emptyText = '결과가 없습니다',
|
||||
debounceMs = 300,
|
||||
id,
|
||||
className,
|
||||
maxListHeight = 'max-h-56',
|
||||
variant = 'field',
|
||||
multiple = false,
|
||||
value,
|
||||
selectedLabel,
|
||||
onSelect,
|
||||
values = [],
|
||||
onToggle,
|
||||
}: ComboboxProps) {
|
||||
const [text, setText] = useState('');
|
||||
const [open, setOpen] = useState(false);
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 검색어 디바운스 → onQueryChange. 콜백은 ref로 잡아 text 변화에만 반응.
|
||||
const qcRef = useRef(onQueryChange);
|
||||
qcRef.current = onQueryChange;
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => qcRef.current(text.trim()), debounceMs);
|
||||
return () => clearTimeout(t);
|
||||
}, [text, debounceMs]);
|
||||
|
||||
// field 팝오버 바깥 클릭 시 닫기.
|
||||
useEffect(() => {
|
||||
if (variant === 'inline') return;
|
||||
const onDoc = (e: MouseEvent) => {
|
||||
if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', onDoc);
|
||||
return () => document.removeEventListener('mousedown', onDoc);
|
||||
}, [variant]);
|
||||
|
||||
const isSelected = (oid: string) => (multiple ? values.includes(oid) : value === oid);
|
||||
|
||||
const handlePick = (opt: ComboOption) => {
|
||||
if (opt.disabled) return;
|
||||
if (multiple) onToggle?.(opt);
|
||||
else {
|
||||
onSelect?.(opt);
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
const searchInput = (
|
||||
<div className="relative">
|
||||
<Search size={13} className="absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
id={id}
|
||||
type="text"
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
placeholder={searchPlaceholder}
|
||||
className="pl-7 text-xs"
|
||||
autoComplete="off"
|
||||
/>
|
||||
{loading && <Loader2 size={13} className="absolute right-2 top-1/2 -translate-y-1/2 animate-spin text-muted-foreground" />}
|
||||
</div>
|
||||
);
|
||||
|
||||
const list = (
|
||||
<div className={cn('border border-border rounded bg-background overflow-y-auto', maxListHeight)}>
|
||||
{loading && options.length === 0 ? (
|
||||
<div className="flex items-center gap-2 p-3 text-muted-foreground text-[11px]">
|
||||
<Loader2 size={13} className="animate-spin" />
|
||||
<Typography as="span" variant="small" className="text-[11px]">불러오는 중…</Typography>
|
||||
</div>
|
||||
) : options.length === 0 ? (
|
||||
<Typography as="p" variant="small" className="p-3 text-muted-foreground text-[11px]">{emptyText}</Typography>
|
||||
) : (
|
||||
options.map((opt) => {
|
||||
const sel = isSelected(opt.id);
|
||||
return (
|
||||
<button
|
||||
key={opt.id}
|
||||
type="button"
|
||||
disabled={opt.disabled}
|
||||
onClick={() => handlePick(opt)}
|
||||
className={cn(
|
||||
'w-full flex items-center justify-between gap-2 p-2 text-left border-b border-border last:border-b-0 hover:bg-muted/40 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer transition-colors',
|
||||
sel && 'bg-primary/5',
|
||||
)}
|
||||
>
|
||||
<span className="min-w-0 flex-1">
|
||||
{opt.node ?? <Typography as="span" variant="small">{opt.label}</Typography>}
|
||||
</span>
|
||||
{multiple ? (
|
||||
<input type="checkbox" checked={sel} readOnly className="accent-primary h-3.5 w-3.5 shrink-0" />
|
||||
) : (
|
||||
sel && <Check size={14} className="text-primary shrink-0" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
if (variant === 'inline') {
|
||||
return (
|
||||
<div ref={rootRef} className={cn('space-y-1.5', className)}>
|
||||
{searchInput}
|
||||
{list}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// field: 트리거(선택 요약) + 팝오버(검색창 + 리스트)
|
||||
const hasSelection = multiple ? values.length > 0 : !!value;
|
||||
const summary = multiple
|
||||
? (values.length ? `${values.length}개 선택됨` : placeholder)
|
||||
: (value ? selectedLabel ?? '선택됨' : placeholder);
|
||||
|
||||
return (
|
||||
<div ref={rootRef} className={cn('relative', className)}>
|
||||
<button
|
||||
type="button"
|
||||
id={id}
|
||||
onClick={() => setOpen((o) => !o)}
|
||||
className="w-full flex items-center justify-between gap-2 p-2 bg-background border border-border rounded text-xs text-left hover:bg-muted/20 cursor-pointer"
|
||||
>
|
||||
<span className={cn('truncate', !hasSelection && 'text-muted-foreground')}>{summary}</span>
|
||||
<ChevronsUpDown size={14} className="text-muted-foreground shrink-0" />
|
||||
</button>
|
||||
{open && (
|
||||
<div className="absolute z-50 mt-1 w-full rounded border border-border bg-card shadow-lg p-1.5 space-y-1.5">
|
||||
{searchInput}
|
||||
{list}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user