Merge pull request 'develop' (#36) from develop into master
Reviewed-on: #36
This commit is contained in:
@@ -5,6 +5,7 @@ import type { PaginationState, SortingState } from '@tanstack/react-table'
|
||||
import { Funnel, PencilLine } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover'
|
||||
import { DataTable } from '@/components/data-table/DataTable'
|
||||
import type { DataTableColumn, SelectMode } from '@/components/data-table/DataTable.type'
|
||||
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
|
||||
@@ -81,9 +82,13 @@ const toSidSet = (value: string) =>
|
||||
|
||||
const deduplicateSidInput = (value: string) => [...new Set(toSidSet(value))].join(',')
|
||||
|
||||
const HANGUL_PATTERN = /[ㄱ-ㆎ가-힣]/
|
||||
const hasHangul = (value: string) => HANGUL_PATTERN.test(value)
|
||||
const SID_HANGUL_HINT_DURATION_MS = 2000
|
||||
|
||||
const sanitizeSidInput = (value: string) => {
|
||||
let result = ''
|
||||
let lastChar: 'digit' | 'comma' | 'tilde' | null = null
|
||||
let lastChar: 'digit' | 'char' | 'comma' | 'tilde' | null = null
|
||||
let segmentHasTilde = false
|
||||
|
||||
for (const ch of value) {
|
||||
@@ -93,7 +98,15 @@ const sanitizeSidInput = (value: string) => {
|
||||
continue
|
||||
}
|
||||
|
||||
if (ch === ',' && lastChar === 'digit') {
|
||||
if (/[a-zA-Z_-]/.test(ch)) {
|
||||
// 틸드 범위 검색은 숫자끼리만 허용되므로, 틸드 바로 뒤에는 문자를 붙이지 않는다.
|
||||
if (lastChar === 'tilde') continue
|
||||
result += ch
|
||||
lastChar = 'char'
|
||||
continue
|
||||
}
|
||||
|
||||
if (ch === ',' && (lastChar === 'digit' || lastChar === 'char')) {
|
||||
result += ch
|
||||
lastChar = 'comma'
|
||||
segmentHasTilde = false
|
||||
@@ -187,6 +200,7 @@ export function ListSearchTable({
|
||||
}: ListSearchTableProps) {
|
||||
const { showDialog } = useDialog()
|
||||
const [searchText, setSearchText] = useState(initialSearchState?.searchText ?? '')
|
||||
const [showSidHangulHint, setShowSidHangulHint] = useState(false)
|
||||
const [searchContactResult, setSearchContactResult] = useState<string[]>(initialSearchState?.searchContactResult ?? [])
|
||||
const [searchContactDateRange, setSearchContactDateRange] = useState<KriDateRange>(
|
||||
initialSearchState?.searchContactDateRange ?? { from: '', to: '' },
|
||||
@@ -202,6 +216,7 @@ export function ListSearchTable({
|
||||
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
||||
const handledRefreshKeyRef = useRef(refreshKey)
|
||||
const previousExternalAssignFilterRef = useRef(externalAssignFilter)
|
||||
const sidHangulHintTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
const selectedSids = useMemo(
|
||||
() => selectedRows.map((row) => String(row.sid ?? '')).filter((sid) => sid.length > 0),
|
||||
[selectedRows],
|
||||
@@ -539,8 +554,22 @@ export function ListSearchTable({
|
||||
setPagination((prev) => (prev.pageIndex === 0 ? prev : { ...prev, pageIndex: 0 }))
|
||||
}
|
||||
|
||||
const triggerSidHangulHint = (value: string) => {
|
||||
if (!hasHangul(value)) {
|
||||
setShowSidHangulHint(false)
|
||||
return
|
||||
}
|
||||
setShowSidHangulHint(true)
|
||||
if (sidHangulHintTimeoutRef.current) clearTimeout(sidHangulHintTimeoutRef.current)
|
||||
sidHangulHintTimeoutRef.current = setTimeout(() => {
|
||||
setShowSidHangulHint(false)
|
||||
sidHangulHintTimeoutRef.current = null
|
||||
}, SID_HANGUL_HINT_DURATION_MS)
|
||||
}
|
||||
|
||||
const handleSearchTextChange = (value: string) => {
|
||||
setSearchText(sanitizeSidInput(value))
|
||||
triggerSidHangulHint(value)
|
||||
resetToFirstPage()
|
||||
}
|
||||
|
||||
@@ -568,6 +597,7 @@ export function ListSearchTable({
|
||||
const selectionEnd = e.currentTarget.selectionEnd ?? selectionStart
|
||||
const nextValue = `${searchText.slice(0, selectionStart)}${normalizedText}${searchText.slice(selectionEnd)}`
|
||||
setSearchText(deduplicateSidInput(sanitizeSidInput(nextValue)))
|
||||
triggerSidHangulHint(nextValue)
|
||||
resetToFirstPage()
|
||||
}
|
||||
|
||||
@@ -597,6 +627,12 @@ export function ListSearchTable({
|
||||
await listSearchQuery.refetch()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (sidHangulHintTimeoutRef.current) clearTimeout(sidHangulHintTimeoutRef.current)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
onCurrentFilterChange?.(listSearchRequest.listFilter)
|
||||
}, [listSearchRequest.listFilter, onCurrentFilterChange])
|
||||
@@ -662,13 +698,26 @@ export function ListSearchTable({
|
||||
<div className="space-y-2">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<Input
|
||||
placeholder="SID 검색"
|
||||
className="h-9 bg-white flex-1 min-w-0 max-w-xs"
|
||||
value={searchText}
|
||||
onChange={(e) => handleSearchTextChange(e.target.value)}
|
||||
onPaste={handleSidPaste}
|
||||
/>
|
||||
<div className="flex-1 min-w-0 max-w-xs">
|
||||
<Popover open={showSidHangulHint}>
|
||||
<PopoverAnchor asChild>
|
||||
<Input
|
||||
placeholder="SID 검색"
|
||||
className="h-9 bg-white w-full"
|
||||
value={searchText}
|
||||
onChange={(e) => handleSearchTextChange(e.target.value)}
|
||||
onPaste={handleSidPaste}
|
||||
/>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent
|
||||
align="start"
|
||||
className="w-auto p-2 text-xs text-destructive"
|
||||
onOpenAutoFocus={(e) => e.preventDefault()}
|
||||
>
|
||||
한글은 입력할 수 없습니다. 한/영 전환 후 영문·숫자로 입력해 주세요.
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0 max-w-xs">
|
||||
<KriMultiSelect
|
||||
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
|
||||
|
||||
Reference in New Issue
Block a user