251216_01_ENH : 프로젝트에 FW User 배정 구현 및 테스트 완료

This commit is contained in:
2025-12-16 16:57:03 +09:00
parent d9775c8a1d
commit bfbf4635b3
19 changed files with 813 additions and 107 deletions

View File

@@ -2,7 +2,7 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
import { MultiSelect } from '@/components/ui/multi-select'
import {MultiSelect, MultiSelectRef} from '@/components/ui/multi-select'
import type { MultiSelectOption } from '@/components/ui/multi-select'
type BaseProps<T> = {
@@ -14,6 +14,8 @@ type BaseProps<T> = {
placeholder?: string
widthClassName?: string
heightClassName?: string
spanClassName?: string
badgeClassName?: string
className?: string
getValue?: (item: T) => string
getLabel?: (item: T) => string
@@ -48,6 +50,8 @@ export function KriMultiSelect<T = unknown>({
placeholder = 'Select options',
widthClassName,
heightClassName,
spanClassName = "content-text-lg",
badgeClassName = "content-text-lg",
className,
getValue,
getLabel,
@@ -55,6 +59,8 @@ export function KriMultiSelect<T = unknown>({
onItemsChange,
onOptionsChange,
}: KriMultiSelectProps<T>) {
const msRef = React.useRef<MultiSelectRef>(null);
const extractValue = React.useCallback(
(item: T) => (getValue ? getValue(item) : String(item)),
[getValue]
@@ -75,6 +81,7 @@ export function KriMultiSelect<T = unknown>({
return (
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
<MultiSelect<T>
ref={msRef}
options={options}
defaultValue={value}
onValueChange={onChange}
@@ -83,6 +90,8 @@ export function KriMultiSelect<T = unknown>({
maxSelected={maxSelected}
placeholder={placeholder}
className={cn("bg-white content-text-lg", className)}
spanClassName={spanClassName}
badgeClassName={badgeClassName}
searchable={searchable}
searchMode={searchMode}
defaultSearchValue={defaultSearchValue}
@@ -105,6 +114,12 @@ type KriSingleSelectProps<T = unknown> = BaseProps<T> & {
onOptionChange?: (option: MultiSelectOption<T> | null) => void
preventDeselect?: boolean;
hideOptionCheck?: boolean;
useClear?: boolean
clearLabel?: string
clearValue?: string
showSelectedTooltip?: boolean
}
export function KriSingleSelect<T = unknown>({
@@ -118,6 +133,8 @@ export function KriSingleSelect<T = unknown>({
placeholder = 'Select an option',
heightClassName,
widthClassName,
spanClassName = "content-text-lg",
badgeClassName = "content-text-lg",
className,
getValue,
getLabel,
@@ -126,7 +143,13 @@ export function KriSingleSelect<T = unknown>({
onOptionChange,
preventDeselect = false,
hideOptionCheck = false,
showSelectedTooltip = false,
useClear = false,
clearLabel = "선택 해제",
clearValue = "__CLEAR__",
}: KriSingleSelectProps<T>) {
const msRef = React.useRef<MultiSelectRef>(null);
const extractValue = React.useCallback(
(item: T) => (getValue ? getValue(item) : String(item)),
[getValue]
@@ -137,31 +160,65 @@ export function KriSingleSelect<T = unknown>({
)
const options = React.useMemo<MultiSelectOption<T>[]>(() => {
return items.map((item) => ({
const special: MultiSelectOption<T>[] = [];
if (useClear) special.push({ value: clearValue, label: clearLabel });
const normal = items.map((item) => ({
value: extractValue(item),
label: extractLabel(item),
...(withInfo ? { info: item } : {}),
}))
}, [items, extractValue, extractLabel, withInfo])
}));
return [...special, ...normal]
}, [items, extractValue, extractLabel, withInfo, useClear, clearLabel, clearValue])
const defaultValue = React.useMemo(() => (value ? [value] : []), [value])
const tooltipText = React.useMemo(() => {
if (!showSelectedTooltip) return undefined;
if (!value || !value) return undefined;
if (useClear && value === clearValue) return undefined;
const label = options.find(o => o.value === value)?.label;
return label ?? value; // options에 없으면 value라도 표시
}, [showSelectedTooltip, value, options, useClear, clearValue]);
return (
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
<MultiSelect<T>
ref={msRef}
options={options}
defaultValue={defaultValue}
onValueChange={(next) => onChange(next[0] ?? '')}
onValueChange={(next) => {
const v = next[0] ?? ""
if (v === clearValue) {
msRef.current?.clear();
onChange("")
onOptionChange?.(null)
onItemChange?.(null)
return
}
onChange(v)
}}
onOptionChange={(opts) => {
const opt = opts[0] ?? null
const item = withInfo ? ((opt as any)?.info ?? null) : null
onOptionChange?.(opt)
onItemChange?.((withInfo ? (opt?.info ?? null) : null))
onItemChange?.(item)
}}
selectionMode="single"
maxCount={1}
maxSelected={1}
placeholder={placeholder}
className={cn("bg-white content-text-lg", className)}
spanClassName={spanClassName}
badgeClassName={badgeClassName}
searchable={searchable}
searchMode={searchMode}
defaultSearchValue={defaultSearchValue}