Merge pull request '260910_02_ENH: 검색 시 1페이지로' (#34) from develop into master
Reviewed-on: #34
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useState, type ClipboardEvent, type ReactNode } from 'react'
|
import { useCallback, useEffect, useMemo, useRef, useState, type ClipboardEvent, type ReactNode } from 'react'
|
||||||
import type { PaginationState, SortingState } from '@tanstack/react-table'
|
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'
|
||||||
@@ -200,6 +200,8 @@ export function ListSearchTable({
|
|||||||
const [batchResultCodes, setBatchResultCodes] = useState<BatchEditResultCodes>({})
|
const [batchResultCodes, setBatchResultCodes] = useState<BatchEditResultCodes>({})
|
||||||
const [batchSurveyResultCodes, setBatchSurveyResultCodes] = useState<BatchEditSurveyResultCodes>({})
|
const [batchSurveyResultCodes, setBatchSurveyResultCodes] = useState<BatchEditSurveyResultCodes>({})
|
||||||
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
||||||
|
const handledRefreshKeyRef = useRef(refreshKey)
|
||||||
|
const previousExternalAssignFilterRef = useRef(externalAssignFilter)
|
||||||
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],
|
||||||
@@ -533,8 +535,28 @@ export function ListSearchTable({
|
|||||||
[accessibleFilterHeaders, getValueOptionsForHeader, lockedListFilterHeaderTypes],
|
[accessibleFilterHeaders, getValueOptionsForHeader, lockedListFilterHeaderTypes],
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleSearchClick = () => {
|
const resetToFirstPage = () => {
|
||||||
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
|
setPagination((prev) => (prev.pageIndex === 0 ? prev : { ...prev, pageIndex: 0 }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearchTextChange = (value: string) => {
|
||||||
|
setSearchText(sanitizeSidInput(value))
|
||||||
|
resetToFirstPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleContactResultChange = (value: string[]) => {
|
||||||
|
setSearchContactResult(value)
|
||||||
|
resetToFirstPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleInterviewResultChange = (value: string[]) => {
|
||||||
|
setSearchInterviewResult(value)
|
||||||
|
resetToFirstPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSortingChange = (value: SortingState) => {
|
||||||
|
setSorting(value)
|
||||||
|
resetToFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSidPaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
const handleSidPaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
||||||
@@ -546,6 +568,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)))
|
||||||
|
resetToFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleFilterConfirm = async (rows: FilterRow[]) => {
|
const handleFilterConfirm = async (rows: FilterRow[]) => {
|
||||||
@@ -555,6 +578,7 @@ export function ListSearchTable({
|
|||||||
|
|
||||||
const handleChangeSurveyResult = (prjctSurveyIdx: number, codes: string[]) => {
|
const handleChangeSurveyResult = (prjctSurveyIdx: number, codes: string[]) => {
|
||||||
setSurveyResultSelections((prev) => ({ ...prev, [prjctSurveyIdx]: codes }))
|
setSurveyResultSelections((prev) => ({ ...prev, [prjctSurveyIdx]: codes }))
|
||||||
|
resetToFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
const surveyResultCodeOptions = resultCodes.filter((item) => item.resultCdTy === ResultCodeType.SURVEY)
|
const surveyResultCodeOptions = resultCodes.filter((item) => item.resultCdTy === ResultCodeType.SURVEY)
|
||||||
@@ -617,9 +641,22 @@ export function ListSearchTable({
|
|||||||
}, [accessibleFilterHeaderById, lockedListFilterHeaderTypes])
|
}, [accessibleFilterHeaderById, lockedListFilterHeaderTypes])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!refreshKey) return
|
if (!refreshKey || handledRefreshKeyRef.current === refreshKey) return
|
||||||
refetch()
|
handledRefreshKeyRef.current = refreshKey
|
||||||
}, [refetch, refreshKey])
|
|
||||||
|
if (pagination.pageIndex === 0) {
|
||||||
|
refetch()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resetToFirstPage()
|
||||||
|
}, [pagination.pageIndex, refetch, refreshKey])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (previousExternalAssignFilterRef.current === externalAssignFilter) return
|
||||||
|
previousExternalAssignFilterRef.current = externalAssignFilter
|
||||||
|
resetToFirstPage()
|
||||||
|
}, [externalAssignFilter])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -629,14 +666,14 @@ export function ListSearchTable({
|
|||||||
placeholder="SID 검색"
|
placeholder="SID 검색"
|
||||||
className="h-9 bg-white flex-1 min-w-0 max-w-xs"
|
className="h-9 bg-white flex-1 min-w-0 max-w-xs"
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(sanitizeSidInput(e.target.value))}
|
onChange={(e) => handleSearchTextChange(e.target.value)}
|
||||||
onPaste={handleSidPaste}
|
onPaste={handleSidPaste}
|
||||||
/>
|
/>
|
||||||
<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)}
|
||||||
value={searchContactResult}
|
value={searchContactResult}
|
||||||
onChange={setSearchContactResult}
|
onChange={handleContactResultChange}
|
||||||
getValue={(item) => String(item.resultCd)}
|
getValue={(item) => String(item.resultCd)}
|
||||||
getLabel={(item) => item.resultCdLbl}
|
getLabel={(item) => item.resultCdLbl}
|
||||||
placeholder="컨택 결과"
|
placeholder="컨택 결과"
|
||||||
@@ -658,7 +695,7 @@ export function ListSearchTable({
|
|||||||
<KriMultiSelect
|
<KriMultiSelect
|
||||||
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.INTERVIEW)}
|
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.INTERVIEW)}
|
||||||
value={searchInterviewResult}
|
value={searchInterviewResult}
|
||||||
onChange={setSearchInterviewResult}
|
onChange={handleInterviewResultChange}
|
||||||
getValue={(item) => String(item.resultCd)}
|
getValue={(item) => String(item.resultCd)}
|
||||||
getLabel={(item) => item.resultCdLbl}
|
getLabel={(item) => item.resultCdLbl}
|
||||||
placeholder="면접 결과"
|
placeholder="면접 결과"
|
||||||
@@ -719,7 +756,7 @@ export function ListSearchTable({
|
|||||||
totalCount={totalCount}
|
totalCount={totalCount}
|
||||||
pagination={pagination}
|
pagination={pagination}
|
||||||
onPaginationChange={setPagination}
|
onPaginationChange={setPagination}
|
||||||
onSortingChange={setSorting}
|
onSortingChange={handleSortingChange}
|
||||||
selectMode={selectMode}
|
selectMode={selectMode}
|
||||||
onRowSelectionChange={handleRowSelectionChange}
|
onRowSelectionChange={handleRowSelectionChange}
|
||||||
onRowClick={onRowClick}
|
onRowClick={onRowClick}
|
||||||
|
|||||||
Reference in New Issue
Block a user