260716_01_ENH: 본 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
@@ -8,8 +8,8 @@ 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 BatchEditRow } from '@/components/dialog/ListBatchEditDialog'
|
||||
import ListFilterDialog from '@/components/dialog/ListFilterDialog'
|
||||
import ListBatchEditDialog, { type BatchEditPayload, type BatchEditResultCodes, type BatchEditRow } 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'
|
||||
@@ -25,9 +25,11 @@ import {
|
||||
type ListFilter,
|
||||
ListFilterMatchType,
|
||||
ListFilterOperator,
|
||||
type ListFilterTarget,
|
||||
type ListHeaderAssignType,
|
||||
type ListOtherItemFilterCondition,
|
||||
type ListSearchRequest,
|
||||
type ListSearchUiState,
|
||||
} from '@/types/list'
|
||||
import { type ResultCode, ResultCodeType } from '@/types/project'
|
||||
import {
|
||||
@@ -53,12 +55,16 @@ export type ListSearchTableProps = {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -157,23 +163,28 @@ export function ListSearchTable({
|
||||
excludeFilterHeaderTypes,
|
||||
externalAssignFilter,
|
||||
onCurrentFilterChange,
|
||||
onFilterSummaryChange,
|
||||
onSelectedRowsChange,
|
||||
onRowClick,
|
||||
onRowDoubleClick,
|
||||
maxTableHeight = '66vh',
|
||||
initialPagination,
|
||||
onPaginationChange,
|
||||
initialSearchState,
|
||||
onSearchStateChange,
|
||||
focusRowId,
|
||||
}: ListSearchTableProps) {
|
||||
const { showDialog } = useDialog()
|
||||
const [searchText, setSearchText] = useState('')
|
||||
const [searchContactResult, setSearchContactResult] = useState<string[]>([])
|
||||
const [searchInterviewResult, setSearchInterviewResult] = useState<string[]>([])
|
||||
const [searchSurveyResult, setSearchSurveyResult] = useState<string[]>([])
|
||||
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 [pagination, setPagination] = useState<PaginationState>(initialPagination ?? { pageIndex: 0, pageSize: 25 })
|
||||
const [sorting, setSorting] = useState<SortingState>([])
|
||||
const [filterRows, setFilterRows] = useState<FilterRow[]>([])
|
||||
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 [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
|
||||
|
||||
const updateListMutation = useUpdateListMutation(prjctIdx)
|
||||
|
||||
@@ -317,9 +328,98 @@ export function ListSearchTable({
|
||||
userRole,
|
||||
])
|
||||
|
||||
const resultCodeLabel = useCallback(
|
||||
(type: ResultCodeType, code: string) =>
|
||||
resultCodes.find((item) => item.resultCdTy === type && 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 },
|
||||
{ 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(', ')}`)
|
||||
})
|
||||
|
||||
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,
|
||||
searchSurveyResult,
|
||||
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)
|
||||
@@ -335,11 +435,15 @@ export function ListSearchTable({
|
||||
|
||||
const headerOptions = useMemo(
|
||||
() =>
|
||||
accessibleListHeaders.map((header) => ({
|
||||
id: header.listHderId,
|
||||
label: header.listHderNm,
|
||||
})),
|
||||
[accessibleListHeaders],
|
||||
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[]>(
|
||||
@@ -363,12 +467,14 @@ export function ListSearchTable({
|
||||
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
|
||||
}
|
||||
|
||||
const handleBatchConfirm = async (rows: BatchEditRow[]) => {
|
||||
const handleBatchConfirm = async ({ rows, resultCodes: resultCodeSelections, target }: BatchEditPayload) => {
|
||||
setBatchRows(rows)
|
||||
setBatchResultCodes(resultCodeSelections)
|
||||
const updateContents = Object.fromEntries(rows.map((row) => [String(row.headerId), row.value]))
|
||||
await updateListMutation.mutateAsync({
|
||||
updateContents,
|
||||
listFilter: listSearchRequest.listFilter,
|
||||
updateResultCodes: resultCodeSelections,
|
||||
listFilter: buildTargetFilter(target),
|
||||
})
|
||||
await listSearchQuery.refetch()
|
||||
}
|
||||
@@ -377,6 +483,29 @@ export function ListSearchTable({
|
||||
onCurrentFilterChange?.(listSearchRequest.listFilter)
|
||||
}, [listSearchRequest.listFilter, onCurrentFilterChange])
|
||||
|
||||
useEffect(() => {
|
||||
onFilterSummaryChange?.(filterSummaryLines)
|
||||
}, [filterSummaryLines, onFilterSummaryChange])
|
||||
|
||||
useEffect(() => {
|
||||
onSearchStateChange?.({
|
||||
searchText,
|
||||
searchContactResult,
|
||||
searchInterviewResult,
|
||||
searchSurveyResult,
|
||||
filterRows,
|
||||
sorting,
|
||||
})
|
||||
}, [
|
||||
searchText,
|
||||
searchContactResult,
|
||||
searchInterviewResult,
|
||||
searchSurveyResult,
|
||||
filterRows,
|
||||
sorting,
|
||||
onSearchStateChange,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
onPaginationChange?.(pagination)
|
||||
}, [pagination, onPaginationChange])
|
||||
@@ -478,7 +607,7 @@ export function ListSearchTable({
|
||||
onPaginationChange={setPagination}
|
||||
onSortingChange={setSorting}
|
||||
selectMode={selectMode}
|
||||
onRowSelectionChange={onSelectedRowsChange}
|
||||
onRowSelectionChange={handleRowSelectionChange}
|
||||
onRowClick={onRowClick}
|
||||
onRowDoubleClick={onRowDoubleClick}
|
||||
pageSizeOptions={[25, 50, 100]}
|
||||
@@ -490,8 +619,10 @@ export function ListSearchTable({
|
||||
{enableBatchEdit ? (
|
||||
<ListBatchEditDialog
|
||||
headerOptions={headerOptions}
|
||||
appliedFilters={Object.fromEntries(filterRows.map((row) => [row.headerId, row.multiValues]))}
|
||||
resultCodes={resultCodes}
|
||||
filterSummary={filterSummaryLines}
|
||||
initialRows={batchRows}
|
||||
initialResultCodes={batchResultCodes}
|
||||
onConfirm={handleBatchConfirm}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user