667 lines
24 KiB
TypeScript
667 lines
24 KiB
TypeScript
'use client'
|
|
|
|
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'
|
|
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 { 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, type BatchEditSurveyResultCodes } from '@/components/dialog/ListBatchEditDialog'
|
|
import ListFilterDialog, { operatorLabel } from '@/components/dialog/ListFilterDialog'
|
|
import { useDialog } from '@/hooks/useDialog'
|
|
import { useListSearchQuery, useUpdateListMutation } from '@/query/list'
|
|
import { getListColumns, LIST_IS_USE_LABEL, type ListTableRow } from '@/components/table-column/ListTableColumn'
|
|
import { useAssignTargetRows } from '@/components/assign/AssignTargetList'
|
|
import { ListHeaderAssignConst, ListHeaderConst } from '@/const/listConst'
|
|
import {
|
|
createEmptyListFilter,
|
|
type FilterHeaderOption,
|
|
type FilterOperator,
|
|
type FilterRow,
|
|
type FilterValueOption,
|
|
type listHeader,
|
|
type ListFilter,
|
|
ListFilterMatchType,
|
|
ListFilterOperator,
|
|
type ListFilterTarget,
|
|
type ListHeaderAssignType,
|
|
type ListOtherItemFilterCondition,
|
|
type ListSearchRequest,
|
|
type ListSearchUiState,
|
|
type SurveyResultSelections,
|
|
} from '@/types/list'
|
|
import { type ProjectSurvey, type ResultCode, ResultCodeType } from '@/types/project'
|
|
import {
|
|
applyListAccessFilter,
|
|
getLockedListFilterHeaderTypes,
|
|
isAssignHeaderType,
|
|
isListFilterVisibleByAccess,
|
|
isListHeaderVisibleByAccess,
|
|
} from '@/utils/listAccess'
|
|
|
|
export type ListSearchTableProps = {
|
|
prjctIdx: number
|
|
enabled: boolean
|
|
userRole: number
|
|
userId: string
|
|
userCmpn: string
|
|
resultCodes: ResultCode[]
|
|
surveys: ProjectSurvey[]
|
|
listHeaders: listHeader[]
|
|
enableBatchEdit?: boolean
|
|
refreshKey?: number
|
|
selectMode?: SelectMode
|
|
filterActions?: ReactNode
|
|
rightActions?: ReactNode
|
|
excludeFilterHeaderTypes?: number[]
|
|
externalAssignFilter?: { type: ListHeaderAssignType; values: string[]; condition?: 'assigned' | 'unassigned' }
|
|
onCurrentFilterChange?: (filter: ListFilter) => void
|
|
onFilterSummaryChange?: (summary: string[]) => void
|
|
onSelectedRowsChange?: (rows: ListTableRow[]) => void
|
|
onRowClick?: (row: ListTableRow) => void
|
|
onRowDoubleClick?: (row: ListTableRow) => void
|
|
maxTableHeight?: string
|
|
initialPagination?: PaginationState
|
|
onPaginationChange?: (pagination: PaginationState) => void
|
|
/** 뒤로 돌아왔을 때 검색창/필터/정렬을 그대로 복원하기 위한 초기값. 최초 마운트 시 한 번만 사용된다. */
|
|
initialSearchState?: ListSearchUiState
|
|
onSearchStateChange?: (state: ListSearchUiState) => void
|
|
focusRowId?: string
|
|
}
|
|
|
|
const toSidSet = (value: string) =>
|
|
value
|
|
.split(',')
|
|
.map((item) => item.trim())
|
|
.filter((item) => item.length > 0)
|
|
|
|
const sanitizeSidInput = (value: string) => {
|
|
let result = ''
|
|
let lastChar: 'digit' | 'comma' | 'tilde' | null = null
|
|
let segmentHasTilde = false
|
|
|
|
for (const ch of value) {
|
|
if (/[0-9]/.test(ch)) {
|
|
result += ch
|
|
lastChar = 'digit'
|
|
continue
|
|
}
|
|
|
|
if (ch === ',' && lastChar === 'digit') {
|
|
result += ch
|
|
lastChar = 'comma'
|
|
segmentHasTilde = false
|
|
continue
|
|
}
|
|
|
|
if (ch === '~' && lastChar === 'digit' && !segmentHasTilde) {
|
|
result += ch
|
|
lastChar = 'tilde'
|
|
segmentHasTilde = true
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
const toFilterCondition = (row: FilterRow, usesListValue: boolean): Omit<ListOtherItemFilterCondition, 'listHderId'> => {
|
|
if (row.operator === 'empty') {
|
|
return { operator: ListFilterOperator.POSITIVE, matchType: ListFilterMatchType.EMPTY, values: [] }
|
|
}
|
|
if (row.operator === 'notEmpty') {
|
|
return { operator: ListFilterOperator.NEGATIVE, matchType: ListFilterMatchType.EMPTY, values: [] }
|
|
}
|
|
|
|
const values = usesListValue ? row.multiValues : [row.textValue.trim()]
|
|
|
|
if (row.operator === 'eq') {
|
|
return { operator: ListFilterOperator.POSITIVE, matchType: ListFilterMatchType.EXACT, values }
|
|
}
|
|
if (row.operator === 'neq') {
|
|
return { operator: ListFilterOperator.NEGATIVE, matchType: ListFilterMatchType.EXACT, values }
|
|
}
|
|
if (row.operator === 'contains') {
|
|
return { operator: ListFilterOperator.POSITIVE, matchType: ListFilterMatchType.CONTAINS, values }
|
|
}
|
|
return { operator: ListFilterOperator.NEGATIVE, matchType: ListFilterMatchType.CONTAINS, values }
|
|
}
|
|
|
|
const TEXT_LIKE_OPERATORS: FilterOperator[] = ['eq', 'neq', 'contains', 'notContains', 'empty', 'notEmpty']
|
|
const ASSIGN_LIKE_OPERATORS: FilterOperator[] = ['eq', 'neq', 'empty', 'notEmpty']
|
|
const IS_USE_OPERATORS: FilterOperator[] = ['eq', 'neq']
|
|
const FILE_OPERATORS: FilterOperator[] = ['empty', 'notEmpty']
|
|
|
|
const getAllowedOperators = (listHderTy: number): FilterOperator[] => {
|
|
if (listHderTy === ListHeaderConst.IS_USE) return IS_USE_OPERATORS
|
|
if (isAssignHeaderType(listHderTy) || listHderTy === ListHeaderConst.CONTENT_ITEM) return ASSIGN_LIKE_OPERATORS
|
|
if (listHderTy === ListHeaderConst.FILE) return FILE_OPERATORS
|
|
return TEXT_LIKE_OPERATORS
|
|
}
|
|
|
|
const IS_USE_VALUE_OPTIONS: FilterValueOption[] = Object.entries(LIST_IS_USE_LABEL).map(([value, label]) => ({
|
|
value,
|
|
label,
|
|
}))
|
|
|
|
export function ListSearchTable({
|
|
prjctIdx,
|
|
enabled,
|
|
userRole,
|
|
userId,
|
|
userCmpn,
|
|
resultCodes,
|
|
surveys,
|
|
listHeaders,
|
|
enableBatchEdit = false,
|
|
refreshKey = 0,
|
|
selectMode = 'multi',
|
|
filterActions,
|
|
rightActions,
|
|
excludeFilterHeaderTypes,
|
|
externalAssignFilter,
|
|
onCurrentFilterChange,
|
|
onFilterSummaryChange,
|
|
onSelectedRowsChange,
|
|
onRowClick,
|
|
onRowDoubleClick,
|
|
maxTableHeight = '66vh',
|
|
initialPagination,
|
|
onPaginationChange,
|
|
initialSearchState,
|
|
onSearchStateChange,
|
|
focusRowId,
|
|
}: ListSearchTableProps) {
|
|
const { showDialog } = useDialog()
|
|
const [searchText, setSearchText] = useState(initialSearchState?.searchText ?? '')
|
|
const [searchContactResult, setSearchContactResult] = useState<string[]>(initialSearchState?.searchContactResult ?? [])
|
|
const [searchInterviewResult, setSearchInterviewResult] = useState<string[]>(initialSearchState?.searchInterviewResult ?? [])
|
|
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)
|
|
|
|
const outsourceTargetRows = useAssignTargetRows({ prjctIdx, enabled, assignType: ListHeaderAssignConst.OUTSOURCE })
|
|
const contactTargetRows = useAssignTargetRows({
|
|
prjctIdx,
|
|
enabled,
|
|
assignType: ListHeaderAssignConst.CONTACT_INTERVIEWER,
|
|
})
|
|
const fieldTargetRows = useAssignTargetRows({ prjctIdx, enabled, assignType: ListHeaderAssignConst.FIELD_INTERVIEWER })
|
|
|
|
const getValueOptionsForHeader = useCallback(
|
|
(header: listHeader): FilterValueOption[] | undefined => {
|
|
if (header.listHderTy === ListHeaderConst.IS_USE) return IS_USE_VALUE_OPTIONS
|
|
if (header.listHderTy === ListHeaderAssignConst.OUTSOURCE) {
|
|
return outsourceTargetRows.map((row) => ({ value: row.id, label: row.name }))
|
|
}
|
|
if (header.listHderTy === ListHeaderAssignConst.CONTACT_INTERVIEWER) {
|
|
return contactTargetRows.map((row) => ({ value: row.id, label: row.name }))
|
|
}
|
|
if (header.listHderTy === ListHeaderAssignConst.FIELD_INTERVIEWER) {
|
|
return fieldTargetRows.map((row) => ({ value: row.id, label: row.name }))
|
|
}
|
|
if (header.listHderTy === ListHeaderConst.CONTENT_ITEM) {
|
|
return header.filterContents?.map((content) => ({ value: content, label: content }))
|
|
}
|
|
return undefined
|
|
},
|
|
[contactTargetRows, fieldTargetRows, outsourceTargetRows],
|
|
)
|
|
|
|
const accessibleListHeaders = useMemo(
|
|
() => listHeaders.filter((header) => isListHeaderVisibleByAccess(header, userRole)),
|
|
[listHeaders, userRole],
|
|
)
|
|
|
|
const accessibleFilterHeaders = useMemo(
|
|
() =>
|
|
listHeaders.filter(
|
|
(header) =>
|
|
header.listHderTy !== ListHeaderConst.SID &&
|
|
isListFilterVisibleByAccess(header, userRole) &&
|
|
!excludeFilterHeaderTypes?.includes(header.listHderTy),
|
|
),
|
|
[listHeaders, userRole, excludeFilterHeaderTypes],
|
|
)
|
|
|
|
const accessibleFilterHeaderById = useMemo(
|
|
() => new Map(accessibleFilterHeaders.map((header) => [header.listHderId, header])),
|
|
[accessibleFilterHeaders],
|
|
)
|
|
|
|
const lockedListFilterHeaderTypes = useMemo(() => getLockedListFilterHeaderTypes(userRole), [userRole])
|
|
|
|
const listSearchRequest = useMemo<ListSearchRequest>(() => {
|
|
const sort = sorting?.[0] ?? { id: 'sid', desc: false as const }
|
|
const listFilter = createEmptyListFilter()
|
|
listFilter.sidSet = toSidSet(searchText)
|
|
listFilter.memoConditions = []
|
|
listFilter.resultCodeMap = {
|
|
[ResultCodeType.CONTACT]: searchContactResult.map(Number),
|
|
[ResultCodeType.INTERVIEW]: searchInterviewResult.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)
|
|
if (!header || lockedListFilterHeaderTypes.has(header.listHderTy)) return
|
|
|
|
const isEmptyOperator = row.operator === 'empty' || row.operator === 'notEmpty'
|
|
const usesListValue = getValueOptionsForHeader(header) !== undefined
|
|
const condition = toFilterCondition(row, usesListValue)
|
|
const hasValue = isEmptyOperator || condition.values.some((value) => value.trim().length > 0)
|
|
if (!hasValue) return
|
|
|
|
if (header.listHderTy === ListHeaderConst.IS_USE) {
|
|
listFilter.listUseConditions.push(condition)
|
|
return
|
|
}
|
|
|
|
if (isAssignHeaderType(header.listHderTy)) {
|
|
listFilter.assignConditions.push({ assignType: header.listHderTy, ...condition })
|
|
return
|
|
}
|
|
|
|
if (header.listHderTy === ListHeaderConst.MEMO) {
|
|
listFilter.memoConditions.push(condition)
|
|
return
|
|
}
|
|
|
|
listFilter.otherItemConditions.push({
|
|
listHderId: row.headerId,
|
|
...condition,
|
|
})
|
|
})
|
|
|
|
if (externalAssignFilter) {
|
|
if (externalAssignFilter.condition === 'assigned') {
|
|
listFilter.assignConditions.push({
|
|
assignType: externalAssignFilter.type,
|
|
operator: ListFilterOperator.NEGATIVE,
|
|
matchType: ListFilterMatchType.EMPTY,
|
|
})
|
|
} else if (externalAssignFilter.condition === 'unassigned') {
|
|
listFilter.assignConditions.push({
|
|
assignType: externalAssignFilter.type,
|
|
operator: ListFilterOperator.POSITIVE,
|
|
matchType: ListFilterMatchType.EMPTY,
|
|
})
|
|
} else {
|
|
listFilter.assignUserMap[externalAssignFilter.type] = externalAssignFilter.values
|
|
}
|
|
}
|
|
|
|
const restrictedListFilter = applyListAccessFilter(listFilter, { userRole, userId, userCmpn })
|
|
|
|
return {
|
|
listFilter: restrictedListFilter,
|
|
pageRequest: {
|
|
pageIndex: pagination.pageIndex,
|
|
pageSize: pagination.pageSize,
|
|
sortBy: sort.id,
|
|
sortDir: sort.desc ? 'desc' : 'asc',
|
|
},
|
|
}
|
|
}, [
|
|
accessibleFilterHeaderById,
|
|
externalAssignFilter,
|
|
filterRows,
|
|
getValueOptionsForHeader,
|
|
lockedListFilterHeaderTypes,
|
|
pagination.pageIndex,
|
|
pagination.pageSize,
|
|
searchContactResult,
|
|
searchInterviewResult,
|
|
surveyResultSelections,
|
|
searchText,
|
|
sorting,
|
|
userCmpn,
|
|
userId,
|
|
userRole,
|
|
])
|
|
|
|
const resultCodeLabel = useCallback(
|
|
(type: ResultCodeType, code: string) =>
|
|
resultCodes.find((item) => item.resultCdTy === type && String(item.resultCd) === code)?.resultCdLbl ?? code,
|
|
[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[]>(() => {
|
|
const lines: string[] = []
|
|
|
|
const sidValues = toSidSet(searchText)
|
|
if (sidValues.length > 0) {
|
|
lines.push(`SID: ${sidValues.join(', ')}`)
|
|
}
|
|
|
|
const resultSummaryGroups: { label: string; type: ResultCodeType; values: string[] }[] = [
|
|
{ label: '컨택 결과', type: ResultCodeType.CONTACT, values: searchContactResult },
|
|
{ label: '면접 결과', type: ResultCodeType.INTERVIEW, values: searchInterviewResult },
|
|
]
|
|
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
|
|
|
|
if (row.operator === 'empty' || row.operator === 'notEmpty') {
|
|
lines.push(`${header.listHderNm} ${operatorLabel[row.operator]}`)
|
|
return
|
|
}
|
|
|
|
const valueOptions = getValueOptionsForHeader(header)
|
|
if (valueOptions !== undefined) {
|
|
if (row.multiValues.length === 0) return
|
|
const labels = row.multiValues.map(
|
|
(value) => valueOptions.find((option) => option.value === value)?.label ?? value,
|
|
)
|
|
lines.push(`${header.listHderNm} ${operatorLabel[row.operator]} ${labels.join(', ')}`)
|
|
return
|
|
}
|
|
|
|
if (row.textValue.trim().length === 0) return
|
|
lines.push(`${header.listHderNm} ${operatorLabel[row.operator]} ${row.textValue.trim()}`)
|
|
})
|
|
|
|
return lines
|
|
}, [
|
|
accessibleFilterHeaderById,
|
|
filterRows,
|
|
getValueOptionsForHeader,
|
|
lockedListFilterHeaderTypes,
|
|
resultCodeLabel,
|
|
searchContactResult,
|
|
searchInterviewResult,
|
|
surveys,
|
|
surveyResultSelections,
|
|
surveyResultCodeLabel,
|
|
searchText,
|
|
])
|
|
|
|
const listSearchQuery = useListSearchQuery(prjctIdx, listSearchRequest, enabled)
|
|
const { refetch } = listSearchQuery
|
|
|
|
const buildTargetFilter = useCallback(
|
|
(target: ListFilterTarget): ListFilter => {
|
|
if (target === 'all') {
|
|
return applyListAccessFilter(createEmptyListFilter(), { userRole, userId, userCmpn })
|
|
}
|
|
if (target === 'selected') {
|
|
return applyListAccessFilter(
|
|
{
|
|
...createEmptyListFilter(),
|
|
sidSet: selectedRows.map((row) => String(row.sid ?? '')).filter((sid) => sid.length > 0),
|
|
},
|
|
{ userRole, userId, userCmpn },
|
|
)
|
|
}
|
|
return listSearchRequest.listFilter
|
|
},
|
|
[listSearchRequest.listFilter, selectedRows, userCmpn, userId, userRole],
|
|
)
|
|
|
|
const handleRowSelectionChange = useCallback(
|
|
(rows: ListTableRow[]) => {
|
|
setSelectedRows(rows)
|
|
onSelectedRowsChange?.(rows)
|
|
},
|
|
[onSelectedRowsChange],
|
|
)
|
|
|
|
const columns = useMemo<DataTableColumn<ListTableRow, unknown>[]>(() => {
|
|
if (!listHeaders.length) return []
|
|
return getListColumns(listHeaders, resultCodes, userRole, surveys)
|
|
}, [listHeaders, resultCodes, userRole, surveys])
|
|
|
|
const viewList = useMemo<ListTableRow[]>(
|
|
() => (listSearchQuery.data?.content ?? []).map((row) => ({ ...row, ...row.itemList })),
|
|
[listSearchQuery.data],
|
|
)
|
|
|
|
const totalCount = listSearchQuery.data?.totalElements ?? 0
|
|
const pageCount = listSearchQuery.data?.totalPages ?? 0
|
|
|
|
const headerOptions = useMemo(
|
|
() =>
|
|
accessibleListHeaders
|
|
.filter((header) => header.listHderTy !== ListHeaderConst.SID && !isAssignHeaderType(header.listHderTy))
|
|
.map((header) => ({
|
|
id: header.listHderId,
|
|
label: header.listHderNm,
|
|
listHderTy: header.listHderTy,
|
|
valueOptions: getValueOptionsForHeader(header),
|
|
})),
|
|
[accessibleListHeaders, getValueOptionsForHeader],
|
|
)
|
|
|
|
const filterHeaderOptions = useMemo<FilterHeaderOption[]>(
|
|
() =>
|
|
accessibleFilterHeaders.map((header) => ({
|
|
id: header.listHderId,
|
|
label: header.listHderNm,
|
|
allowedOperators: getAllowedOperators(header.listHderTy),
|
|
valueOptions: getValueOptionsForHeader(header),
|
|
disabled: lockedListFilterHeaderTypes.has(header.listHderTy),
|
|
})),
|
|
[accessibleFilterHeaders, getValueOptionsForHeader, lockedListFilterHeaderTypes],
|
|
)
|
|
|
|
const handleSearchClick = () => {
|
|
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
|
|
}
|
|
|
|
const handleFilterConfirm = async (rows: FilterRow[]) => {
|
|
setFilterRows(rows)
|
|
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
useEffect(() => {
|
|
onCurrentFilterChange?.(listSearchRequest.listFilter)
|
|
}, [listSearchRequest.listFilter, onCurrentFilterChange])
|
|
|
|
useEffect(() => {
|
|
onFilterSummaryChange?.(filterSummaryLines)
|
|
}, [filterSummaryLines, onFilterSummaryChange])
|
|
|
|
useEffect(() => {
|
|
onSearchStateChange?.({
|
|
searchText,
|
|
searchContactResult,
|
|
searchInterviewResult,
|
|
surveyResultSelections,
|
|
filterRows,
|
|
sorting,
|
|
})
|
|
}, [
|
|
searchText,
|
|
searchContactResult,
|
|
searchInterviewResult,
|
|
surveyResultSelections,
|
|
filterRows,
|
|
sorting,
|
|
onSearchStateChange,
|
|
])
|
|
|
|
useEffect(() => {
|
|
onPaginationChange?.(pagination)
|
|
}, [pagination, onPaginationChange])
|
|
|
|
useEffect(() => {
|
|
setFilterRows((prev) => {
|
|
const next = prev.filter((row) => {
|
|
const header = accessibleFilterHeaderById.get(row.headerId)
|
|
return !!header && !lockedListFilterHeaderTypes.has(header.listHderTy)
|
|
})
|
|
return next.length === prev.length ? prev : next
|
|
})
|
|
}, [accessibleFilterHeaderById, lockedListFilterHeaderTypes])
|
|
|
|
useEffect(() => {
|
|
if (!refreshKey) return
|
|
refetch()
|
|
}, [refetch, refreshKey])
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<div className="space-y-2">
|
|
<div className="flex items-center gap-2">
|
|
<Input
|
|
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 max-w-xs">
|
|
<KriMultiSelect
|
|
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
|
|
value={searchContactResult}
|
|
onChange={setSearchContactResult}
|
|
getValue={(item) => String(item.resultCd)}
|
|
getLabel={(item) => item.resultCdLbl}
|
|
placeholder="컨택 결과"
|
|
widthClassName="w-full"
|
|
heightClassName="h-9"
|
|
/>
|
|
</div>
|
|
<div className="flex-1 min-w-0 max-w-xs">
|
|
<KriMultiSelect
|
|
items={resultCodes.filter((item) => item.resultCdTy === ResultCodeType.INTERVIEW)}
|
|
value={searchInterviewResult}
|
|
onChange={setSearchInterviewResult}
|
|
getValue={(item) => String(item.resultCd)}
|
|
getLabel={(item) => item.resultCdLbl}
|
|
placeholder="면접 결과"
|
|
widthClassName="w-full"
|
|
heightClassName="h-9"
|
|
/>
|
|
</div>
|
|
</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')}>
|
|
<Funnel className="w-4 h-4" />
|
|
필터
|
|
</Button>
|
|
{filterActions}
|
|
{enableBatchEdit ? (
|
|
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('listBatchEditDialog')}>
|
|
<PencilLine className="w-4 h-4" />
|
|
일괄 수정
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
{rightActions ? <div className="flex items-center gap-2 flex-wrap">{rightActions}</div> : null}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
|
|
<DataTable<ListTableRow>
|
|
columns={columns}
|
|
data={viewList}
|
|
getRowId={(row) => String(row.sid)}
|
|
focusRowId={focusRowId}
|
|
isClient={false}
|
|
pageCount={pageCount}
|
|
totalCount={totalCount}
|
|
pagination={pagination}
|
|
onPaginationChange={setPagination}
|
|
onSortingChange={setSorting}
|
|
selectMode={selectMode}
|
|
onRowSelectionChange={handleRowSelectionChange}
|
|
onRowClick={onRowClick}
|
|
onRowDoubleClick={onRowDoubleClick}
|
|
pageSizeOptions={[25, 50, 100]}
|
|
maxBodyHeight={maxTableHeight}
|
|
/>
|
|
</div>
|
|
|
|
<ListFilterDialog headerOptions={filterHeaderOptions} initialRows={filterRows} onConfirm={handleFilterConfirm} />
|
|
{enableBatchEdit ? (
|
|
<ListBatchEditDialog
|
|
headerOptions={headerOptions}
|
|
resultCodes={resultCodes}
|
|
surveys={surveys}
|
|
filterSummary={filterSummaryLines}
|
|
initialRows={batchRows}
|
|
initialResultCodes={batchResultCodes}
|
|
initialSurveyResultCodes={batchSurveyResultCodes}
|
|
onConfirm={handleBatchConfirm}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|