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 { Funnel, PencilLine } from 'lucide-react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
|
import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover'
|
||||||
import { DataTable } from '@/components/data-table/DataTable'
|
import { DataTable } from '@/components/data-table/DataTable'
|
||||||
import type { DataTableColumn, SelectMode } from '@/components/data-table/DataTable.type'
|
import type { DataTableColumn, SelectMode } from '@/components/data-table/DataTable.type'
|
||||||
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
|
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
|
||||||
@@ -81,9 +82,13 @@ const toSidSet = (value: string) =>
|
|||||||
|
|
||||||
const deduplicateSidInput = (value: string) => [...new Set(toSidSet(value))].join(',')
|
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) => {
|
const sanitizeSidInput = (value: string) => {
|
||||||
let result = ''
|
let result = ''
|
||||||
let lastChar: 'digit' | 'comma' | 'tilde' | null = null
|
let lastChar: 'digit' | 'char' | 'comma' | 'tilde' | null = null
|
||||||
let segmentHasTilde = false
|
let segmentHasTilde = false
|
||||||
|
|
||||||
for (const ch of value) {
|
for (const ch of value) {
|
||||||
@@ -93,7 +98,15 @@ const sanitizeSidInput = (value: string) => {
|
|||||||
continue
|
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
|
result += ch
|
||||||
lastChar = 'comma'
|
lastChar = 'comma'
|
||||||
segmentHasTilde = false
|
segmentHasTilde = false
|
||||||
@@ -187,6 +200,7 @@ export function ListSearchTable({
|
|||||||
}: ListSearchTableProps) {
|
}: ListSearchTableProps) {
|
||||||
const { showDialog } = useDialog()
|
const { showDialog } = useDialog()
|
||||||
const [searchText, setSearchText] = useState(initialSearchState?.searchText ?? '')
|
const [searchText, setSearchText] = useState(initialSearchState?.searchText ?? '')
|
||||||
|
const [showSidHangulHint, setShowSidHangulHint] = useState(false)
|
||||||
const [searchContactResult, setSearchContactResult] = useState<string[]>(initialSearchState?.searchContactResult ?? [])
|
const [searchContactResult, setSearchContactResult] = useState<string[]>(initialSearchState?.searchContactResult ?? [])
|
||||||
const [searchContactDateRange, setSearchContactDateRange] = useState<KriDateRange>(
|
const [searchContactDateRange, setSearchContactDateRange] = useState<KriDateRange>(
|
||||||
initialSearchState?.searchContactDateRange ?? { from: '', to: '' },
|
initialSearchState?.searchContactDateRange ?? { from: '', to: '' },
|
||||||
@@ -202,6 +216,7 @@ export function ListSearchTable({
|
|||||||
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
||||||
const handledRefreshKeyRef = useRef(refreshKey)
|
const handledRefreshKeyRef = useRef(refreshKey)
|
||||||
const previousExternalAssignFilterRef = useRef(externalAssignFilter)
|
const previousExternalAssignFilterRef = useRef(externalAssignFilter)
|
||||||
|
const sidHangulHintTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||||
const selectedSids = useMemo(
|
const selectedSids = useMemo(
|
||||||
() => selectedRows.map((row) => String(row.sid ?? '')).filter((sid) => sid.length > 0),
|
() => selectedRows.map((row) => String(row.sid ?? '')).filter((sid) => sid.length > 0),
|
||||||
[selectedRows],
|
[selectedRows],
|
||||||
@@ -539,8 +554,22 @@ export function ListSearchTable({
|
|||||||
setPagination((prev) => (prev.pageIndex === 0 ? prev : { ...prev, pageIndex: 0 }))
|
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) => {
|
const handleSearchTextChange = (value: string) => {
|
||||||
setSearchText(sanitizeSidInput(value))
|
setSearchText(sanitizeSidInput(value))
|
||||||
|
triggerSidHangulHint(value)
|
||||||
resetToFirstPage()
|
resetToFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,6 +597,7 @@ export function ListSearchTable({
|
|||||||
const selectionEnd = e.currentTarget.selectionEnd ?? selectionStart
|
const selectionEnd = e.currentTarget.selectionEnd ?? selectionStart
|
||||||
const nextValue = `${searchText.slice(0, selectionStart)}${normalizedText}${searchText.slice(selectionEnd)}`
|
const nextValue = `${searchText.slice(0, selectionStart)}${normalizedText}${searchText.slice(selectionEnd)}`
|
||||||
setSearchText(deduplicateSidInput(sanitizeSidInput(nextValue)))
|
setSearchText(deduplicateSidInput(sanitizeSidInput(nextValue)))
|
||||||
|
triggerSidHangulHint(nextValue)
|
||||||
resetToFirstPage()
|
resetToFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,6 +627,12 @@ export function ListSearchTable({
|
|||||||
await listSearchQuery.refetch()
|
await listSearchQuery.refetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (sidHangulHintTimeoutRef.current) clearTimeout(sidHangulHintTimeoutRef.current)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onCurrentFilterChange?.(listSearchRequest.listFilter)
|
onCurrentFilterChange?.(listSearchRequest.listFilter)
|
||||||
}, [listSearchRequest.listFilter, onCurrentFilterChange])
|
}, [listSearchRequest.listFilter, onCurrentFilterChange])
|
||||||
@@ -662,13 +698,26 @@ export function ListSearchTable({
|
|||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<Input
|
<div className="flex-1 min-w-0 max-w-xs">
|
||||||
placeholder="SID 검색"
|
<Popover open={showSidHangulHint}>
|
||||||
className="h-9 bg-white flex-1 min-w-0 max-w-xs"
|
<PopoverAnchor asChild>
|
||||||
value={searchText}
|
<Input
|
||||||
onChange={(e) => handleSearchTextChange(e.target.value)}
|
placeholder="SID 검색"
|
||||||
onPaste={handleSidPaste}
|
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">
|
<div className="flex-1 min-w-0 max-w-xs">
|
||||||
<KriMultiSelect
|
<KriMultiSelect
|
||||||
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
|
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
|
||||||
|
|||||||
Reference in New Issue
Block a user