260722_01_ENH: 버그 수정 및 개선 사항 수정
This commit is contained in:
@@ -8,7 +8,7 @@ import { Input } from '@/components/ui/input'
|
||||
import { DataTable } from '@/components/data-table/DataTable'
|
||||
import type { DataTableColumn, SelectMode } from '@/components/data-table/DataTable.type'
|
||||
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
|
||||
import ListBatchEditDialog, { type BatchEditPayload, type BatchEditResultCodes, type BatchEditRow } from '@/components/dialog/ListBatchEditDialog'
|
||||
import ListBatchEditDialog, { type BatchEditPayload, type BatchEditResultCodes, type BatchEditRow, type BatchEditSurveyResultCodes } from '@/components/dialog/ListBatchEditDialog'
|
||||
import ListFilterDialog, { operatorLabel } from '@/components/dialog/ListFilterDialog'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import { useListSearchQuery, useUpdateListMutation } from '@/query/list'
|
||||
@@ -30,8 +30,9 @@ import {
|
||||
type ListOtherItemFilterCondition,
|
||||
type ListSearchRequest,
|
||||
type ListSearchUiState,
|
||||
type SurveyResultSelections,
|
||||
} from '@/types/list'
|
||||
import { type ResultCode, ResultCodeType } from '@/types/project'
|
||||
import { type ProjectSurvey, type ResultCode, ResultCodeType } from '@/types/project'
|
||||
import {
|
||||
applyListAccessFilter,
|
||||
getLockedListFilterHeaderTypes,
|
||||
@@ -46,6 +47,7 @@ export type ListSearchTableProps = {
|
||||
userId: string
|
||||
userCmpn: string
|
||||
resultCodes: ResultCode[]
|
||||
surveys: ProjectSurvey[]
|
||||
listHeaders: listHeader[]
|
||||
enableBatchEdit?: boolean
|
||||
refreshKey?: number
|
||||
@@ -154,6 +156,7 @@ export function ListSearchTable({
|
||||
userId,
|
||||
userCmpn,
|
||||
resultCodes,
|
||||
surveys,
|
||||
listHeaders,
|
||||
enableBatchEdit = false,
|
||||
refreshKey = 0,
|
||||
@@ -178,12 +181,13 @@ export function ListSearchTable({
|
||||
const [searchText, setSearchText] = useState(initialSearchState?.searchText ?? '')
|
||||
const [searchContactResult, setSearchContactResult] = useState<string[]>(initialSearchState?.searchContactResult ?? [])
|
||||
const [searchInterviewResult, setSearchInterviewResult] = useState<string[]>(initialSearchState?.searchInterviewResult ?? [])
|
||||
const [searchSurveyResult, setSearchSurveyResult] = useState<string[]>(initialSearchState?.searchSurveyResult ?? [])
|
||||
const [surveyResultSelections, setSurveyResultSelections] = useState<SurveyResultSelections>(initialSearchState?.surveyResultSelections ?? {})
|
||||
const [pagination, setPagination] = useState<PaginationState>(initialPagination ?? { pageIndex: 0, pageSize: 25 })
|
||||
const [sorting, setSorting] = useState<SortingState>(initialSearchState?.sorting ?? [])
|
||||
const [filterRows, setFilterRows] = useState<FilterRow[]>(initialSearchState?.filterRows ?? [])
|
||||
const [batchRows, setBatchRows] = useState<BatchEditRow[]>([])
|
||||
const [batchResultCodes, setBatchResultCodes] = useState<BatchEditResultCodes>({})
|
||||
const [batchSurveyResultCodes, setBatchSurveyResultCodes] = useState<BatchEditSurveyResultCodes>({})
|
||||
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
||||
|
||||
const updateListMutation = useUpdateListMutation(prjctIdx)
|
||||
@@ -247,8 +251,13 @@ export function ListSearchTable({
|
||||
listFilter.resultCodeMap = {
|
||||
[ResultCodeType.CONTACT]: searchContactResult.map(Number),
|
||||
[ResultCodeType.INTERVIEW]: searchInterviewResult.map(Number),
|
||||
[ResultCodeType.SURVEY]: searchSurveyResult.map(Number),
|
||||
}
|
||||
listFilter.surveyResultConditions = Object.entries(surveyResultSelections)
|
||||
.filter(([, codes]) => codes.length > 0)
|
||||
.map(([prjctSurveyIdx, codes]) => ({
|
||||
prjctSurveyIdx: Number(prjctSurveyIdx),
|
||||
resultCodes: codes.map(Number),
|
||||
}))
|
||||
|
||||
filterRows.forEach((row) => {
|
||||
const header = accessibleFilterHeaderById.get(row.headerId)
|
||||
@@ -320,7 +329,7 @@ export function ListSearchTable({
|
||||
pagination.pageSize,
|
||||
searchContactResult,
|
||||
searchInterviewResult,
|
||||
searchSurveyResult,
|
||||
surveyResultSelections,
|
||||
searchText,
|
||||
sorting,
|
||||
userCmpn,
|
||||
@@ -334,6 +343,12 @@ export function ListSearchTable({
|
||||
[resultCodes],
|
||||
)
|
||||
|
||||
const surveyResultCodeLabel = useCallback(
|
||||
(code: string) =>
|
||||
resultCodes.find((item) => item.resultCdTy === ResultCodeType.SURVEY && String(item.resultCd) === code)?.resultCdLbl ?? code,
|
||||
[resultCodes],
|
||||
)
|
||||
|
||||
// ApplyFilterOption의 "필터 적용 대상만"을 고를 때 보여줄, 사람이 읽을 수 있는 현재 필터 조건 요약.
|
||||
// 실제 서버로 보내는 listSearchRequest와 같은 유효성 조건(잠긴 헤더 제외, 빈 값 제외 등)을 따라간다.
|
||||
const filterSummaryLines = useMemo<string[]>(() => {
|
||||
@@ -347,13 +362,19 @@ export function ListSearchTable({
|
||||
const resultSummaryGroups: { label: string; type: ResultCodeType; values: string[] }[] = [
|
||||
{ label: '컨택 결과', type: ResultCodeType.CONTACT, values: searchContactResult },
|
||||
{ label: '면접 결과', type: ResultCodeType.INTERVIEW, values: searchInterviewResult },
|
||||
{ label: '설문 결과', type: ResultCodeType.SURVEY, values: searchSurveyResult },
|
||||
]
|
||||
resultSummaryGroups.forEach(({ label, type, values }) => {
|
||||
if (values.length === 0) return
|
||||
lines.push(`${label}: ${values.map((value) => resultCodeLabel(type, value)).join(', ')}`)
|
||||
})
|
||||
|
||||
surveys.forEach((survey) => {
|
||||
if (survey.prjctSurveyIdx == null) return
|
||||
const codes = surveyResultSelections[survey.prjctSurveyIdx] ?? []
|
||||
if (codes.length === 0) return
|
||||
lines.push(`${survey.surveyName} 결과: ${codes.map(surveyResultCodeLabel).join(', ')}`)
|
||||
})
|
||||
|
||||
filterRows.forEach((row) => {
|
||||
const header = accessibleFilterHeaderById.get(row.headerId)
|
||||
if (!header || lockedListFilterHeaderTypes.has(header.listHderTy)) return
|
||||
@@ -386,7 +407,9 @@ export function ListSearchTable({
|
||||
resultCodeLabel,
|
||||
searchContactResult,
|
||||
searchInterviewResult,
|
||||
searchSurveyResult,
|
||||
surveys,
|
||||
surveyResultSelections,
|
||||
surveyResultCodeLabel,
|
||||
searchText,
|
||||
])
|
||||
|
||||
@@ -422,8 +445,8 @@ export function ListSearchTable({
|
||||
|
||||
const columns = useMemo<DataTableColumn<ListTableRow, unknown>[]>(() => {
|
||||
if (!listHeaders.length) return []
|
||||
return getListColumns(listHeaders, resultCodes, userRole)
|
||||
}, [listHeaders, resultCodes, userRole])
|
||||
return getListColumns(listHeaders, resultCodes, userRole, surveys)
|
||||
}, [listHeaders, resultCodes, userRole, surveys])
|
||||
|
||||
const viewList = useMemo<ListTableRow[]>(
|
||||
() => (listSearchQuery.data?.content ?? []).map((row) => ({ ...row, ...row.itemList })),
|
||||
@@ -467,13 +490,21 @@ export function ListSearchTable({
|
||||
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
|
||||
}
|
||||
|
||||
const handleBatchConfirm = async ({ rows, resultCodes: resultCodeSelections, target }: BatchEditPayload) => {
|
||||
const handleChangeSurveyResult = (prjctSurveyIdx: number, codes: string[]) => {
|
||||
setSurveyResultSelections((prev) => ({ ...prev, [prjctSurveyIdx]: codes }))
|
||||
}
|
||||
|
||||
const surveyResultCodeOptions = resultCodes.filter((item) => item.resultCdTy === ResultCodeType.SURVEY)
|
||||
|
||||
const handleBatchConfirm = async ({ rows, resultCodes: resultCodeSelections, surveyResultCodes, target }: BatchEditPayload) => {
|
||||
setBatchRows(rows)
|
||||
setBatchResultCodes(resultCodeSelections)
|
||||
setBatchSurveyResultCodes(Object.fromEntries(surveyResultCodes.map((item) => [item.prjctSurveyIdx, item.resultCd])))
|
||||
const updateContents = Object.fromEntries(rows.map((row) => [String(row.headerId), row.value]))
|
||||
await updateListMutation.mutateAsync({
|
||||
updateContents,
|
||||
updateResultCodes: resultCodeSelections,
|
||||
updateSurveyResultCodes: surveyResultCodes,
|
||||
listFilter: buildTargetFilter(target),
|
||||
})
|
||||
await listSearchQuery.refetch()
|
||||
@@ -492,7 +523,7 @@ export function ListSearchTable({
|
||||
searchText,
|
||||
searchContactResult,
|
||||
searchInterviewResult,
|
||||
searchSurveyResult,
|
||||
surveyResultSelections,
|
||||
filterRows,
|
||||
sorting,
|
||||
})
|
||||
@@ -500,7 +531,7 @@ export function ListSearchTable({
|
||||
searchText,
|
||||
searchContactResult,
|
||||
searchInterviewResult,
|
||||
searchSurveyResult,
|
||||
surveyResultSelections,
|
||||
filterRows,
|
||||
sorting,
|
||||
onSearchStateChange,
|
||||
@@ -530,12 +561,12 @@ export function ListSearchTable({
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder="Search SID"
|
||||
className="h-9 bg-white flex-1 min-w-0"
|
||||
placeholder="SID 검색"
|
||||
className="h-9 bg-white flex-1 min-w-0 max-w-xs"
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(sanitizeSidInput(e.target.value))}
|
||||
/>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex-1 min-w-0 max-w-xs">
|
||||
<KriMultiSelect
|
||||
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
|
||||
value={searchContactResult}
|
||||
@@ -547,7 +578,7 @@ export function ListSearchTable({
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex-1 min-w-0 max-w-xs">
|
||||
<KriMultiSelect
|
||||
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.INTERVIEW)}
|
||||
value={searchInterviewResult}
|
||||
@@ -559,23 +590,29 @@ export function ListSearchTable({
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<KriMultiSelect
|
||||
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.SURVEY)}
|
||||
value={searchSurveyResult}
|
||||
onChange={setSearchSurveyResult}
|
||||
getValue={(item) => String(item.resultCd)}
|
||||
getLabel={(item) => item.resultCdLbl}
|
||||
placeholder="설문 결과"
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
</div>
|
||||
<Button className="text-lg shrink-0" onClick={handleSearchClick}>
|
||||
검색
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{surveys.length > 0 ? (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{surveys
|
||||
.filter((survey) => survey.prjctSurveyIdx != null)
|
||||
.map((survey) => (
|
||||
<div key={survey.prjctSurveyIdx} className="flex-1 min-w-[180px] max-w-xs">
|
||||
<KriMultiSelect
|
||||
items={surveyResultCodeOptions}
|
||||
value={surveyResultSelections[survey.prjctSurveyIdx as number] ?? []}
|
||||
onChange={(value) => handleChangeSurveyResult(survey.prjctSurveyIdx as number, value)}
|
||||
getValue={(item) => String(item.resultCd)}
|
||||
getLabel={(item) => item.resultCdLbl}
|
||||
placeholder={`${survey.surveyName} 결과`}
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex items-center gap-2 flex-wrap justify-between">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('listFilterDialog')}>
|
||||
@@ -620,9 +657,11 @@ export function ListSearchTable({
|
||||
<ListBatchEditDialog
|
||||
headerOptions={headerOptions}
|
||||
resultCodes={resultCodes}
|
||||
surveys={surveys}
|
||||
filterSummary={filterSummaryLines}
|
||||
initialRows={batchRows}
|
||||
initialResultCodes={batchResultCodes}
|
||||
initialSurveyResultCodes={batchSurveyResultCodes}
|
||||
onConfirm={handleBatchConfirm}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user