From e5e7aed50432679831cee7ffd62e0a1574b96e9b Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Fri, 24 Jul 2026 14:03:03 +0900 Subject: [PATCH] =?UTF-8?q?260724=5F01=5FENH:=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=8A=A4=ED=83=80=EC=9D=BC=20=ED=86=B5=EC=9D=BC,?= =?UTF-8?q?=20=EC=9D=BC=EB=B6=80=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(pages)/(main)/assign/project/page.tsx | 15 +- .../(pages)/(main)/progress/message/page.tsx | 2 +- src/components/common/KriAutoComplete.tsx | 6 + src/components/data-table/DataTable.tsx | 138 ++++++++++++--- src/components/data-table/DataTable.type.ts | 3 + .../dialog/ListHeaderManageDialog.tsx | 2 +- .../progress/DateProgressSection.tsx | 81 +++++---- src/components/progress/UserProgressTable.tsx | 167 +++++------------- 8 files changed, 224 insertions(+), 190 deletions(-) diff --git a/src/app/(pages)/(main)/assign/project/page.tsx b/src/app/(pages)/(main)/assign/project/page.tsx index 2894851..1b5a1c3 100644 --- a/src/app/(pages)/(main)/assign/project/page.tsx +++ b/src/app/(pages)/(main)/assign/project/page.tsx @@ -179,11 +179,12 @@ const ProjectAssignPage = () => { ]); const assignInfoString = useMemo(() => { + const cmpnAssign = companyFilter ? originAssign.filter(u => u.userCmpn === companyFilter) : originAssign; return roleArray.map(role => { - const cnt = originAssign.filter(u => String(u.userRole) === role.value).length; + const cnt = cmpnAssign.filter(u => String(u.userRole) === role.value).length; return `${role.label} : ${cnt}`; }).join(' / '); - }, [roleArray, originAssign]); + }, [roleArray, originAssign, companyFilter]); const handleAssign = () => { const toAssign = ableView.filter(u => selectedAbleUser.includes(u.userId)); @@ -216,14 +217,14 @@ const ProjectAssignPage = () => { // 로그인 계정의 소속 회사를 기본 선택하되, 매치되는 게 없으면 자사(ownCmpn) 중 가장 상단 1개로 대체한다. useEffect(() => { - const cmpn = auth.user?.userCmpn ?? ""; - if (cmpn && companyArray.some((company) => company.cmpnId === cmpn)) { - setCompanyFilter(cmpn); + // 이미 유효한 값이 선택돼 있으면(사용자가 직접 고른 값 포함) 그대로 둔다. + if (companyFilter && companyArray.some((company) => company.cmpnId === companyFilter)) { return; } - // 이미 유효한 값이 선택돼 있으면(사용자가 직접 고른 값 포함) 그대로 둔다. - if (companyFilter && companyArray.some((company) => company.cmpnId === companyFilter)) { + const cmpn = auth.user?.userCmpn ?? ""; + if (cmpn && companyArray.some((company) => company.cmpnId === cmpn)) { + setCompanyFilter(cmpn); return; } diff --git a/src/app/(pages)/(main)/progress/message/page.tsx b/src/app/(pages)/(main)/progress/message/page.tsx index 3a7bd3e..fbb70b0 100644 --- a/src/app/(pages)/(main)/progress/message/page.tsx +++ b/src/app/(pages)/(main)/progress/message/page.tsx @@ -106,7 +106,7 @@ const MessageProgressPage = () => {
- + diff --git a/src/components/common/KriAutoComplete.tsx b/src/components/common/KriAutoComplete.tsx index 6aeb35a..1aa29e5 100644 --- a/src/components/common/KriAutoComplete.tsx +++ b/src/components/common/KriAutoComplete.tsx @@ -24,6 +24,8 @@ export interface KriAutoCompleteBaseProps { getLabel?: (item: T) => string withInfo?: boolean disabled?: boolean + /** Dialog 안에서 사용될 때 팝오버 스크롤이 막히지 않도록 기본 true (Radix Dialog + non-modal Popover 중첩 스크롤락 이슈 우회) */ + modalPopover?: boolean 'aria-invalid'?: boolean } @@ -74,6 +76,7 @@ export function KriMultiSelect({ onItemsChange, onOptionsChange, disabled, + modalPopover = true, 'aria-invalid': ariaInvalid, }: KriMultiSelectProps) { const options = React.useMemo( @@ -105,6 +108,7 @@ export function KriMultiSelect({ resetOnDefaultValueChange deduplicateOptions disabled={disabled} + modalPopover={modalPopover} aria-invalid={ariaInvalid} /> @@ -152,6 +156,7 @@ function KriSingleSelectInner( clearLabel = '선택 해제', clearValue = '__CLEAR__', disabled, + modalPopover = true, 'aria-invalid': ariaInvalid, }: KriSingleSelectProps, forwardedRef: React.ForwardedRef, @@ -221,6 +226,7 @@ function KriSingleSelectInner( resetOnDefaultValueChange deduplicateOptions disabled={disabled} + modalPopover={modalPopover} title={showSelectedTooltip ? selectedLabel ?? value : undefined} aria-invalid={ariaInvalid} /> diff --git a/src/components/data-table/DataTable.tsx b/src/components/data-table/DataTable.tsx index 5cf95a2..12190dd 100644 --- a/src/components/data-table/DataTable.tsx +++ b/src/components/data-table/DataTable.tsx @@ -1,7 +1,7 @@ 'use client' -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import type { OnChangeFn, PaginationState, Row, RowSelectionState, SortingState } from '@tanstack/react-table' +import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react' +import type { OnChangeFn, PaginationState, Row, RowPinningState, RowSelectionState, SortingState } from '@tanstack/react-table' import { flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table' import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react' import { Button } from '@/components/ui/button' @@ -12,6 +12,8 @@ import type { DataTableColumn, DataTableProps } from './DataTable.type' import { DataTablePagination } from './DataTablePagination' import { usePreventClickOnDrag } from './hooks/usePreventClickOnDrag' +const EMPTY_PINNED_ROWS: never[] = [] + export function DataTable({ columns, data, @@ -34,11 +36,14 @@ export function DataTable({ emptyText = '데이터가 없습니다.', className, maxBodyHeight, + disablePagination = false, + topPinnedRows = EMPTY_PINNED_ROWS, + bottomPinnedRows = EMPTY_PINNED_ROWS, }: Readonly>) { const [internalPagination, setInternalPagination] = useState({ pageIndex: 0, pageSize: defaultPageSize }) const [sorting, setSorting] = useState([]) const [rowSelection, setRowSelection] = useState({}) - const containerRef = useRef(null) + const scrollContainerRef = useRef(null) const drag = usePreventClickOnDrag() const selectionEnabled = selectMode === 'single' || selectMode === 'multi' @@ -54,7 +59,7 @@ export function DataTable({ aria-label="전체 선택" /> ) : null, - cell: ({ row }) => ( + cell: ({ row }) => row.getIsPinned() ? null : ( { @@ -95,22 +100,43 @@ export function DataTable({ [isClient, onServerPaginationChange], ) + const combinedData = useMemo( + () => [...topPinnedRows, ...data, ...bottomPinnedRows], + [topPinnedRows, data, bottomPinnedRows], + ) + + const internalGetRowId = useCallback((row: TData, index: number) => { + if (index < topPinnedRows.length) return `__top-pinned-${index}` + if (index >= topPinnedRows.length + data.length) { + return `__bottom-pinned-${index - topPinnedRows.length - data.length}` + } + const originalIndex = index - topPinnedRows.length + return getRowId ? getRowId(data[originalIndex], originalIndex) : String(originalIndex) + }, [topPinnedRows.length, data, getRowId]) + + const rowPinning = useMemo(() => ({ + top: topPinnedRows.map((_, i) => `__top-pinned-${i}`), + bottom: bottomPinnedRows.map((_, i) => `__bottom-pinned-${i}`), + }), [topPinnedRows, bottomPinnedRows]) + const table = useReactTable({ - data, + data: combinedData, columns: enhancedColumns, pageCount: isClient ? undefined : serverPageCount, - state: { sorting, pagination, rowSelection }, - enableRowSelection: selectionEnabled, + state: { sorting, pagination, rowSelection, rowPinning }, + enableRowSelection: (row) => selectionEnabled && !row.getIsPinned(), + enableRowPinning: true, + keepPinnedRows: true, onRowSelectionChange: setRowSelection, onSortingChange: setSorting, onPaginationChange: handlePaginationChange, getCoreRowModel: getCoreRowModel(), getSortedRowModel: isClient ? getSortedRowModel() : undefined, - getPaginationRowModel: isClient ? getPaginationRowModel() : undefined, + getPaginationRowModel: isClient && !disablePagination ? getPaginationRowModel() : undefined, manualPagination: !isClient, manualSorting: !isClient, enableSortingRemoval: false, - ...(getRowId ? { getRowId } : {}), + getRowId: internalGetRowId, }) useEffect(() => { @@ -124,7 +150,7 @@ export function DataTable({ useEffect(() => { if (!focusRowId) return - const target = containerRef.current?.querySelector(`[data-row-id="${CSS.escape(focusRowId)}"]`) + const target = scrollContainerRef.current?.querySelector(`[data-row-id="${CSS.escape(focusRowId)}"]`) target?.scrollIntoView({ behavior: 'smooth', block: 'center' }) }, [focusRowId, data]) @@ -150,15 +176,48 @@ export function DataTable({ const totalCount = isClient ? data.length : (serverTotalCount ?? 0) + const topRows = table.getTopRows() + const centerRows = table.getCenterRows() + const bottomRows = table.getBottomRows() + + const [topOffsets, setTopOffsets] = useState([]) + const [bottomOffsets, setBottomOffsets] = useState([]) + + useLayoutEffect(() => { + if (!maxBodyHeight) return + const container = scrollContainerRef.current + if (!container) return + + const headerHeight = container.querySelector('thead')?.getBoundingClientRect().height ?? 0 + const bodyRows = Array.from(container.querySelectorAll('tbody > tr')) + const topRowEls = bodyRows.slice(0, topRows.length) + const bottomRowEls = bottomRows.length ? bodyRows.slice(-bottomRows.length) : [] + + let topAcc = headerHeight + setTopOffsets(topRowEls.map((element) => { + const offset = topAcc + topAcc += element.getBoundingClientRect().height + return offset + })) + + let bottomAcc = 0 + const offsets: number[] = [] + for (let index = bottomRowEls.length - 1; index >= 0; index -= 1) { + offsets[index] = bottomAcc + bottomAcc += bottomRowEls[index].getBoundingClientRect().height + } + setBottomOffsets(offsets) + }, [maxBodyHeight, topRows.length, bottomRows.length, centerRows.length]) + return (
유형 단가
- + {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { @@ -171,7 +230,7 @@ export function DataTable({ ({ }} > {!header.isPlaceholder && column.getCanSort() ? ( - ) : content} @@ -193,7 +259,19 @@ export function DataTable({ ))} - {table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => ( + {topRows.map((row, index) => ( + td]:px-2 [&>td]:py-1.5', + maxBodyHeight && 'sticky z-10', + )} + style={maxBodyHeight ? { top: topOffsets[index] ?? 0 } : undefined} + > + {row.getVisibleCells().map((cell) => {flexRender(cell.column.columnDef.cell, cell.getContext())})} + + ))} + {centerRows.length ? centerRows.map((row) => ( ({ )) : ( {emptyText} )} + {bottomRows.map((row, index) => ( + td]:px-2 [&>td]:py-1.5', + maxBodyHeight && 'sticky z-10', + )} + style={maxBodyHeight ? { bottom: bottomOffsets[index] ?? 0 } : undefined} + > + {row.getVisibleCells().map((cell) => {flexRender(cell.column.columnDef.cell, cell.getContext())})} + + ))}
- + {!disablePagination && ( + + )} ) } diff --git a/src/components/data-table/DataTable.type.ts b/src/components/data-table/DataTable.type.ts index 6889475..c43caba 100644 --- a/src/components/data-table/DataTable.type.ts +++ b/src/components/data-table/DataTable.type.ts @@ -44,4 +44,7 @@ export interface DataTableProps { emptyText?: string className?: string maxBodyHeight?: string + disablePagination?: boolean + topPinnedRows?: TData[] + bottomPinnedRows?: TData[] } diff --git a/src/components/dialog/ListHeaderManageDialog.tsx b/src/components/dialog/ListHeaderManageDialog.tsx index ce06b2d..af60237 100644 --- a/src/components/dialog/ListHeaderManageDialog.tsx +++ b/src/components/dialog/ListHeaderManageDialog.tsx @@ -191,7 +191,7 @@ const ListHeaderManageDialog = ({ useEffect(() => { if (!resolvedOpen) return - setLocalRows(rows.map((row) => ({ ...row }))) + setLocalRows([...rows].sort((a, b) => a.listHderOrder - b.listHderOrder).map((row) => ({ ...row }))) }, [resolvedOpen, rows]) const handleOpenChange = (nextOpen: boolean) => { diff --git a/src/components/progress/DateProgressSection.tsx b/src/components/progress/DateProgressSection.tsx index f5c11f6..e31f555 100644 --- a/src/components/progress/DateProgressSection.tsx +++ b/src/components/progress/DateProgressSection.tsx @@ -2,6 +2,8 @@ import { useMemo } from 'react' import { KriLineChart } from '@/components/chart' +import { DataTable } from '@/components/data-table/DataTable' +import type { DataTableColumn } from '@/components/data-table/DataTable.type' import type { ProgressDateResponse } from '@/types/progress' import type { ResultCodeColumn } from './resultCodeColumns' @@ -35,6 +37,39 @@ export function DateProgressSection({ title, subtitle, rows, resultCodeColumns } return [totalSeries, ...resultSeries] }, [sortedRows, resultCodeColumns]) + const columns = useMemo[]>(() => [ + { + id: 'contactDate', + header: '일자', + accessorFn: (row) => row.contactDate ?? '-', + cell: ({ getValue }) =>
{getValue()}
, + }, + { + id: 'startTime', + header: '시작', + accessorFn: (row) => row.startTime ?? '-', + cell: ({ getValue }) =>
{getValue()}
, + }, + { + id: 'endTime', + header: '종료', + accessorFn: (row) => row.endTime ?? '-', + cell: ({ getValue }) =>
{getValue()}
, + }, + { + id: 'totalCount', + header: 'Total', + accessorFn: (row) => row.totalCount ?? 0, + cell: ({ getValue }) =>
{getValue().toLocaleString()}
, + }, + ...resultCodeColumns.map(({ resultCd, label }): DataTableColumn => ({ + id: `rc-${resultCd}`, + header: label, + accessorFn: (row) => row.resultCodeCountMap?.[resultCd] ?? 0, + cell: ({ getValue }) =>
{getValue().toLocaleString()}
, + })), + ], [resultCodeColumns]) + return (
@@ -46,45 +81,13 @@ export function DateProgressSection({ title, subtitle, rows, resultCodeColumns }
-
- - - - - - - - {resultCodeColumns.map(({ resultCd, label }) => ( - - ))} - - - - {sortedRows.length === 0 && ( - - - - )} - {sortedRows.map((row, index) => ( - - - - - - {resultCodeColumns.map(({ resultCd }) => ( - - ))} - - ))} - -
일자시작종료Total - {label} -
- 데이터가 없습니다. -
{row.contactDate ?? '-'}{row.startTime ?? '-'}{row.endTime ?? '-'}{(row.totalCount ?? 0).toLocaleString()} - {(row.resultCodeCountMap?.[resultCd] ?? 0).toLocaleString()} -
-
+ + columns={columns} + data={sortedRows} + getRowId={(row, index) => `${row.contactDate ?? ''}-${index}`} + disablePagination + maxBodyHeight="320px" + />
) } diff --git a/src/components/progress/UserProgressTable.tsx b/src/components/progress/UserProgressTable.tsx index 0d9d0fb..57e40a6 100644 --- a/src/components/progress/UserProgressTable.tsx +++ b/src/components/progress/UserProgressTable.tsx @@ -1,8 +1,8 @@ 'use client' -import { useMemo, useState } from 'react' -import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react' -import { cn } from '@/lib/utils' +import { useMemo } from 'react' +import { DataTable } from '@/components/data-table/DataTable' +import type { DataTableColumn } from '@/components/data-table/DataTable.type' import type { ProgressUserResponse } from '@/types/progress' import type { ResultCodeColumn } from './resultCodeColumns' @@ -14,23 +14,8 @@ export type UserProgressTableProps = { onSelectUser: (userId: string | null) => void } -type SortKey = 'userId' | 'totalCount' | `rc-${number}` -type SortState = { key: SortKey; dir: 'asc' | 'desc' } | null - -const getSortValue = (row: ProgressUserResponse, key: SortKey, userNameMap: Record) => { - if (key === 'userId') return userNameMap[row.userId ?? ''] ?? row.userId ?? '' - if (key === 'totalCount') return row.totalCount ?? 0 - const resultCd = Number(key.slice(3)) - return row.resultCodeCountMap?.[resultCd] ?? 0 -} - const pct = (count: number, total: number) => (total > 0 ? `(${((count / total) * 100).toFixed(1)})` : '(0.0)') -const SortIcon = ({ column, sort }: { column: SortKey; sort: SortState }) => { - if (!sort || sort.key !== column) return - return sort.dir === 'asc' ? : -} - export function UserProgressTable({ rows, resultCodeColumns, @@ -38,114 +23,58 @@ export function UserProgressTable({ selectedUserId, onSelectUser, }: UserProgressTableProps) { - const [sort, setSort] = useState(null) - - const total = useMemo(() => { - const totalCount = rows.reduce((acc, row) => acc + (row.totalCount ?? 0), 0) - const resultCodeCountMap: Record = {} + const totalRow = useMemo(() => { + const resultCodeCountMap: Record = {} resultCodeColumns.forEach(({ resultCd }) => { resultCodeCountMap[resultCd] = rows.reduce((acc, row) => acc + (row.resultCodeCountMap?.[resultCd] ?? 0), 0) }) - return { totalCount, resultCodeCountMap } + return { + totalCount: rows.reduce((acc, row) => acc + (row.totalCount ?? 0), 0), + resultCodeCountMap, + } }, [rows, resultCodeColumns]) - const sortedRows = useMemo(() => { - if (!sort) return rows - const list = [...rows] - list.sort((a, b) => { - const av = getSortValue(a, sort.key, userNameMap) - const bv = getSortValue(b, sort.key, userNameMap) - const compared = typeof av === 'string' && typeof bv === 'string' ? av.localeCompare(bv, 'ko') : Number(av) - Number(bv) - return sort.dir === 'asc' ? compared : -compared - }) - return list - }, [rows, sort, userNameMap]) - - const toggleSort = (key: SortKey) => { - setSort((prev) => { - if (!prev || prev.key !== key) return { key, dir: 'asc' } - if (prev.dir === 'asc') return { key, dir: 'desc' } - return null - }) - } - - const headerButtonClass = 'flex items-center gap-1 mx-auto cursor-pointer select-none' + const columns = useMemo[]>(() => [ + { + id: 'userId', + header: '담당자', + accessorFn: (row) => userNameMap[row.userId ?? ''] ?? row.userId ?? '', + cell: ({ row }) => ( +
+ {row.getIsPinned() ? 'Total' : (userNameMap[row.original.userId ?? ''] ?? row.original.userId ?? '')} +
+ ), + }, + { + id: 'totalCount', + header: 'Total', + accessorFn: (row) => row.totalCount ?? 0, + cell: ({ row }) =>
{(row.original.totalCount ?? 0).toLocaleString()}
, + }, + ...resultCodeColumns.map(({ resultCd, label }): DataTableColumn => ({ + id: `rc-${resultCd}`, + header: label, + accessorFn: (row) => row.resultCodeCountMap?.[resultCd] ?? 0, + cell: ({ row }) => { + const count = row.original.resultCodeCountMap?.[resultCd] ?? 0 + const rowTotal = row.original.totalCount ?? 0 + return
{count.toLocaleString()} {pct(count, rowTotal)}
+ }, + })), + ], [resultCodeColumns, userNameMap]) return ( -
- - - - - - {resultCodeColumns.map(({ resultCd, label }) => ( - - ))} - - - - - - - {resultCodeColumns.map(({ resultCd }) => { - const count = total.resultCodeCountMap[resultCd] ?? 0 - return ( - - ) - })} - - - {sortedRows.length === 0 && ( - - - - )} - - {sortedRows.map((row) => { - const userId = row.userId ?? '' - const rowTotal = row.totalCount ?? 0 - const selected = selectedUserId === userId - return ( - onSelectUser(selected ? null : userId)} - > - - - {resultCodeColumns.map(({ resultCd }) => { - const count = row.resultCodeCountMap?.[resultCd] ?? 0 - return ( - - ) - })} - - ) - })} - -
- - - - - -
Total{total.totalCount.toLocaleString()} - {count.toLocaleString()} {pct(count, total.totalCount)} -
- 데이터가 없습니다. -
{userNameMap[userId] ?? userId}{rowTotal.toLocaleString()} - {count.toLocaleString()} {pct(count, rowTotal)} -
-
+ + columns={columns} + data={rows} + getRowId={(row) => row.userId ?? ''} + topPinnedRows={[totalRow]} + disablePagination + maxBodyHeight="420px" + selectMode="click-event" + focusRowId={selectedUserId ?? undefined} + onRowClick={(row) => onSelectUser(selectedUserId === (row.userId ?? '') ? null : (row.userId ?? null))} + /> ) } -- 2.49.0.windows.1