260724_01_ENH: 테이블 스타일 통일, 일부 버그 수정
This commit is contained in:
@@ -179,11 +179,12 @@ const ProjectAssignPage = () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const assignInfoString = useMemo(() => {
|
const assignInfoString = useMemo(() => {
|
||||||
|
const cmpnAssign = companyFilter ? originAssign.filter(u => u.userCmpn === companyFilter) : originAssign;
|
||||||
return roleArray.map(role => {
|
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}`;
|
return `${role.label} : ${cnt}`;
|
||||||
}).join(' / ');
|
}).join(' / ');
|
||||||
}, [roleArray, originAssign]);
|
}, [roleArray, originAssign, companyFilter]);
|
||||||
|
|
||||||
const handleAssign = () => {
|
const handleAssign = () => {
|
||||||
const toAssign = ableView.filter(u => selectedAbleUser.includes(u.userId));
|
const toAssign = ableView.filter(u => selectedAbleUser.includes(u.userId));
|
||||||
@@ -216,14 +217,14 @@ const ProjectAssignPage = () => {
|
|||||||
|
|
||||||
// 로그인 계정의 소속 회사를 기본 선택하되, 매치되는 게 없으면 자사(ownCmpn) 중 가장 상단 1개로 대체한다.
|
// 로그인 계정의 소속 회사를 기본 선택하되, 매치되는 게 없으면 자사(ownCmpn) 중 가장 상단 1개로 대체한다.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const cmpn = auth.user?.userCmpn ?? "";
|
// 이미 유효한 값이 선택돼 있으면(사용자가 직접 고른 값 포함) 그대로 둔다.
|
||||||
if (cmpn && companyArray.some((company) => company.cmpnId === cmpn)) {
|
if (companyFilter && companyArray.some((company) => company.cmpnId === companyFilter)) {
|
||||||
setCompanyFilter(cmpn);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 이미 유효한 값이 선택돼 있으면(사용자가 직접 고른 값 포함) 그대로 둔다.
|
const cmpn = auth.user?.userCmpn ?? "";
|
||||||
if (companyFilter && companyArray.some((company) => company.cmpnId === companyFilter)) {
|
if (cmpn && companyArray.some((company) => company.cmpnId === cmpn)) {
|
||||||
|
setCompanyFilter(cmpn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const MessageProgressPage = () => {
|
|||||||
|
|
||||||
<div className="rounded-md border overflow-hidden">
|
<div className="rounded-md border overflow-hidden">
|
||||||
<table className="w-full text-sm">
|
<table className="w-full text-sm">
|
||||||
<thead className="bg-blue-50">
|
<thead className="bg-primary text-primary-foreground">
|
||||||
<tr>
|
<tr>
|
||||||
<th className="h-10 px-3 text-center font-semibold border-b">유형</th>
|
<th className="h-10 px-3 text-center font-semibold border-b">유형</th>
|
||||||
<th className="h-10 px-3 text-center font-semibold border-b">단가</th>
|
<th className="h-10 px-3 text-center font-semibold border-b">단가</th>
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export interface KriAutoCompleteBaseProps<T> {
|
|||||||
getLabel?: (item: T) => string
|
getLabel?: (item: T) => string
|
||||||
withInfo?: boolean
|
withInfo?: boolean
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
/** Dialog 안에서 사용될 때 팝오버 스크롤이 막히지 않도록 기본 true (Radix Dialog + non-modal Popover 중첩 스크롤락 이슈 우회) */
|
||||||
|
modalPopover?: boolean
|
||||||
'aria-invalid'?: boolean
|
'aria-invalid'?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +76,7 @@ export function KriMultiSelect<T = unknown>({
|
|||||||
onItemsChange,
|
onItemsChange,
|
||||||
onOptionsChange,
|
onOptionsChange,
|
||||||
disabled,
|
disabled,
|
||||||
|
modalPopover = true,
|
||||||
'aria-invalid': ariaInvalid,
|
'aria-invalid': ariaInvalid,
|
||||||
}: KriMultiSelectProps<T>) {
|
}: KriMultiSelectProps<T>) {
|
||||||
const options = React.useMemo(
|
const options = React.useMemo(
|
||||||
@@ -105,6 +108,7 @@ export function KriMultiSelect<T = unknown>({
|
|||||||
resetOnDefaultValueChange
|
resetOnDefaultValueChange
|
||||||
deduplicateOptions
|
deduplicateOptions
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
modalPopover={modalPopover}
|
||||||
aria-invalid={ariaInvalid}
|
aria-invalid={ariaInvalid}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -152,6 +156,7 @@ function KriSingleSelectInner<T>(
|
|||||||
clearLabel = '선택 해제',
|
clearLabel = '선택 해제',
|
||||||
clearValue = '__CLEAR__',
|
clearValue = '__CLEAR__',
|
||||||
disabled,
|
disabled,
|
||||||
|
modalPopover = true,
|
||||||
'aria-invalid': ariaInvalid,
|
'aria-invalid': ariaInvalid,
|
||||||
}: KriSingleSelectProps<T>,
|
}: KriSingleSelectProps<T>,
|
||||||
forwardedRef: React.ForwardedRef<MultiSelectRef>,
|
forwardedRef: React.ForwardedRef<MultiSelectRef>,
|
||||||
@@ -221,6 +226,7 @@ function KriSingleSelectInner<T>(
|
|||||||
resetOnDefaultValueChange
|
resetOnDefaultValueChange
|
||||||
deduplicateOptions
|
deduplicateOptions
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
modalPopover={modalPopover}
|
||||||
title={showSelectedTooltip ? selectedLabel ?? value : undefined}
|
title={showSelectedTooltip ? selectedLabel ?? value : undefined}
|
||||||
aria-invalid={ariaInvalid}
|
aria-invalid={ariaInvalid}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||||
import type { OnChangeFn, PaginationState, Row, RowSelectionState, SortingState } from '@tanstack/react-table'
|
import type { OnChangeFn, PaginationState, Row, RowPinningState, RowSelectionState, SortingState } from '@tanstack/react-table'
|
||||||
import { flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table'
|
import { flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table'
|
||||||
import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react'
|
import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
@@ -12,6 +12,8 @@ import type { DataTableColumn, DataTableProps } from './DataTable.type'
|
|||||||
import { DataTablePagination } from './DataTablePagination'
|
import { DataTablePagination } from './DataTablePagination'
|
||||||
import { usePreventClickOnDrag } from './hooks/usePreventClickOnDrag'
|
import { usePreventClickOnDrag } from './hooks/usePreventClickOnDrag'
|
||||||
|
|
||||||
|
const EMPTY_PINNED_ROWS: never[] = []
|
||||||
|
|
||||||
export function DataTable<TData, TValue = unknown>({
|
export function DataTable<TData, TValue = unknown>({
|
||||||
columns,
|
columns,
|
||||||
data,
|
data,
|
||||||
@@ -34,11 +36,14 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
emptyText = '데이터가 없습니다.',
|
emptyText = '데이터가 없습니다.',
|
||||||
className,
|
className,
|
||||||
maxBodyHeight,
|
maxBodyHeight,
|
||||||
|
disablePagination = false,
|
||||||
|
topPinnedRows = EMPTY_PINNED_ROWS,
|
||||||
|
bottomPinnedRows = EMPTY_PINNED_ROWS,
|
||||||
}: Readonly<DataTableProps<TData, TValue>>) {
|
}: Readonly<DataTableProps<TData, TValue>>) {
|
||||||
const [internalPagination, setInternalPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: defaultPageSize })
|
const [internalPagination, setInternalPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: defaultPageSize })
|
||||||
const [sorting, setSorting] = useState<SortingState>([])
|
const [sorting, setSorting] = useState<SortingState>([])
|
||||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const scrollContainerRef = useRef<HTMLDivElement>(null)
|
||||||
const drag = usePreventClickOnDrag()
|
const drag = usePreventClickOnDrag()
|
||||||
const selectionEnabled = selectMode === 'single' || selectMode === 'multi'
|
const selectionEnabled = selectMode === 'single' || selectMode === 'multi'
|
||||||
|
|
||||||
@@ -54,7 +59,7 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
aria-label="전체 선택"
|
aria-label="전체 선택"
|
||||||
/>
|
/>
|
||||||
) : null,
|
) : null,
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => row.getIsPinned() ? null : (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={row.getIsSelected()}
|
checked={row.getIsSelected()}
|
||||||
onCheckedChange={(value) => {
|
onCheckedChange={(value) => {
|
||||||
@@ -95,22 +100,43 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
[isClient, onServerPaginationChange],
|
[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<RowPinningState>(() => ({
|
||||||
|
top: topPinnedRows.map((_, i) => `__top-pinned-${i}`),
|
||||||
|
bottom: bottomPinnedRows.map((_, i) => `__bottom-pinned-${i}`),
|
||||||
|
}), [topPinnedRows, bottomPinnedRows])
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data,
|
data: combinedData,
|
||||||
columns: enhancedColumns,
|
columns: enhancedColumns,
|
||||||
pageCount: isClient ? undefined : serverPageCount,
|
pageCount: isClient ? undefined : serverPageCount,
|
||||||
state: { sorting, pagination, rowSelection },
|
state: { sorting, pagination, rowSelection, rowPinning },
|
||||||
enableRowSelection: selectionEnabled,
|
enableRowSelection: (row) => selectionEnabled && !row.getIsPinned(),
|
||||||
|
enableRowPinning: true,
|
||||||
|
keepPinnedRows: true,
|
||||||
onRowSelectionChange: setRowSelection,
|
onRowSelectionChange: setRowSelection,
|
||||||
onSortingChange: setSorting,
|
onSortingChange: setSorting,
|
||||||
onPaginationChange: handlePaginationChange,
|
onPaginationChange: handlePaginationChange,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getSortedRowModel: isClient ? getSortedRowModel() : undefined,
|
getSortedRowModel: isClient ? getSortedRowModel() : undefined,
|
||||||
getPaginationRowModel: isClient ? getPaginationRowModel() : undefined,
|
getPaginationRowModel: isClient && !disablePagination ? getPaginationRowModel() : undefined,
|
||||||
manualPagination: !isClient,
|
manualPagination: !isClient,
|
||||||
manualSorting: !isClient,
|
manualSorting: !isClient,
|
||||||
enableSortingRemoval: false,
|
enableSortingRemoval: false,
|
||||||
...(getRowId ? { getRowId } : {}),
|
getRowId: internalGetRowId,
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -124,7 +150,7 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focusRowId) return
|
if (!focusRowId) return
|
||||||
const target = containerRef.current?.querySelector<HTMLElement>(`[data-row-id="${CSS.escape(focusRowId)}"]`)
|
const target = scrollContainerRef.current?.querySelector<HTMLElement>(`[data-row-id="${CSS.escape(focusRowId)}"]`)
|
||||||
target?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
target?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||||
}, [focusRowId, data])
|
}, [focusRowId, data])
|
||||||
|
|
||||||
@@ -150,15 +176,48 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
|
|
||||||
const totalCount = isClient ? data.length : (serverTotalCount ?? 0)
|
const totalCount = isClient ? data.length : (serverTotalCount ?? 0)
|
||||||
|
|
||||||
|
const topRows = table.getTopRows()
|
||||||
|
const centerRows = table.getCenterRows()
|
||||||
|
const bottomRows = table.getBottomRows()
|
||||||
|
|
||||||
|
const [topOffsets, setTopOffsets] = useState<number[]>([])
|
||||||
|
const [bottomOffsets, setBottomOffsets] = useState<number[]>([])
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
<div className={cn('w-full space-y-4', className)}>
|
<div className={cn('w-full space-y-4', className)}>
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
ref={scrollContainerRef}
|
||||||
className={cn('relative w-full overflow-x-auto rounded-md border', maxBodyHeight && 'overflow-y-auto')}
|
className={cn('relative w-full overflow-x-auto rounded-md border', maxBodyHeight && 'overflow-y-auto')}
|
||||||
style={maxBodyHeight ? { maxHeight: maxBodyHeight } : undefined}
|
style={maxBodyHeight ? { maxHeight: maxBodyHeight } : undefined}
|
||||||
>
|
>
|
||||||
<table className="w-full caption-bottom text-sm">
|
<table className="w-full caption-bottom text-sm">
|
||||||
<TableHeader className={cn(maxBodyHeight && 'sticky top-0 z-10 bg-background')}>
|
<TableHeader className={cn(maxBodyHeight && 'sticky top-0 z-20 bg-background')}>
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id} className="hover:bg-transparent">
|
<TableRow key={headerGroup.id} className="hover:bg-transparent">
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
@@ -171,7 +230,7 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
<TableHead
|
<TableHead
|
||||||
key={header.id}
|
key={header.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
'text-base font-semibold text-foreground',
|
'text-base font-semibold bg-primary text-primary-foreground',
|
||||||
column.id === 'actions' && 'w-[140px] text-center',
|
column.id === 'actions' && 'w-[140px] text-center',
|
||||||
maxWidth && 'overflow-hidden text-ellipsis',
|
maxWidth && 'overflow-hidden text-ellipsis',
|
||||||
)}
|
)}
|
||||||
@@ -181,9 +240,16 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{!header.isPlaceholder && column.getCanSort() ? (
|
{!header.isPlaceholder && column.getCanSort() ? (
|
||||||
<Button type="button" variant="ghost" className="flex gap-1 px-0 text-base font-semibold" onClick={column.getToggleSortingHandler()}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
className={cn(
|
||||||
|
"flex gap-1 px-0 text-base font-semibold",
|
||||||
|
)}
|
||||||
|
onClick={column.getToggleSortingHandler()}
|
||||||
|
>
|
||||||
<span>{content}</span>
|
<span>{content}</span>
|
||||||
{sorted === 'asc' ? <ArrowUp className="size-3" /> : sorted === 'desc' ? <ArrowDown className="size-3" /> : <ArrowUpDown className="text-muted-foreground size-3" />}
|
{sorted === 'asc' ? <ArrowUp className="size-3" /> : sorted === 'desc' ? <ArrowDown className="size-3" /> : <ArrowUpDown className="size-3" />}
|
||||||
</Button>
|
</Button>
|
||||||
) : content}
|
) : content}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
@@ -193,7 +259,19 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => (
|
{topRows.map((row, index) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
className={cn(
|
||||||
|
'bg-muted text-base font-semibold [&>td]:px-2 [&>td]:py-1.5',
|
||||||
|
maxBodyHeight && 'sticky z-10',
|
||||||
|
)}
|
||||||
|
style={maxBodyHeight ? { top: topOffsets[index] ?? 0 } : undefined}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => <TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>)}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
{centerRows.length ? centerRows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.id}
|
key={row.id}
|
||||||
data-row-id={row.id}
|
data-row-id={row.id}
|
||||||
@@ -228,17 +306,31 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
)) : (
|
)) : (
|
||||||
<TableRow><TableCell colSpan={enhancedColumns.length} className="h-24 text-center">{emptyText}</TableCell></TableRow>
|
<TableRow><TableCell colSpan={enhancedColumns.length} className="h-24 text-center">{emptyText}</TableCell></TableRow>
|
||||||
)}
|
)}
|
||||||
|
{bottomRows.map((row, index) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
className={cn(
|
||||||
|
'bg-muted text-base font-semibold [&>td]:px-2 [&>td]:py-1.5',
|
||||||
|
maxBodyHeight && 'sticky z-10',
|
||||||
|
)}
|
||||||
|
style={maxBodyHeight ? { bottom: bottomOffsets[index] ?? 0 } : undefined}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => <TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>)}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DataTablePagination
|
{!disablePagination && (
|
||||||
table={table}
|
<DataTablePagination
|
||||||
isClient={isClient}
|
table={table}
|
||||||
totalCount={totalCount}
|
isClient={isClient}
|
||||||
pageSizeOptions={pageSizeOptions}
|
totalCount={totalCount}
|
||||||
paginationItemsToDisplay={paginationItemsToDisplay}
|
pageSizeOptions={pageSizeOptions}
|
||||||
/>
|
paginationItemsToDisplay={paginationItemsToDisplay}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,7 @@ export interface DataTableProps<TData, TValue = unknown> {
|
|||||||
emptyText?: string
|
emptyText?: string
|
||||||
className?: string
|
className?: string
|
||||||
maxBodyHeight?: string
|
maxBodyHeight?: string
|
||||||
|
disablePagination?: boolean
|
||||||
|
topPinnedRows?: TData[]
|
||||||
|
bottomPinnedRows?: TData[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ const ListHeaderManageDialog = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!resolvedOpen) return
|
if (!resolvedOpen) return
|
||||||
setLocalRows(rows.map((row) => ({ ...row })))
|
setLocalRows([...rows].sort((a, b) => a.listHderOrder - b.listHderOrder).map((row) => ({ ...row })))
|
||||||
}, [resolvedOpen, rows])
|
}, [resolvedOpen, rows])
|
||||||
|
|
||||||
const handleOpenChange = (nextOpen: boolean) => {
|
const handleOpenChange = (nextOpen: boolean) => {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { KriLineChart } from '@/components/chart'
|
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 { ProgressDateResponse } from '@/types/progress'
|
||||||
import type { ResultCodeColumn } from './resultCodeColumns'
|
import type { ResultCodeColumn } from './resultCodeColumns'
|
||||||
|
|
||||||
@@ -35,6 +37,39 @@ export function DateProgressSection({ title, subtitle, rows, resultCodeColumns }
|
|||||||
return [totalSeries, ...resultSeries]
|
return [totalSeries, ...resultSeries]
|
||||||
}, [sortedRows, resultCodeColumns])
|
}, [sortedRows, resultCodeColumns])
|
||||||
|
|
||||||
|
const columns = useMemo<DataTableColumn<ProgressDateResponse>[]>(() => [
|
||||||
|
{
|
||||||
|
id: 'contactDate',
|
||||||
|
header: '일자',
|
||||||
|
accessorFn: (row) => row.contactDate ?? '-',
|
||||||
|
cell: ({ getValue }) => <div className="text-center">{getValue<string>()}</div>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'startTime',
|
||||||
|
header: '시작',
|
||||||
|
accessorFn: (row) => row.startTime ?? '-',
|
||||||
|
cell: ({ getValue }) => <div className="text-center">{getValue<string>()}</div>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'endTime',
|
||||||
|
header: '종료',
|
||||||
|
accessorFn: (row) => row.endTime ?? '-',
|
||||||
|
cell: ({ getValue }) => <div className="text-center">{getValue<string>()}</div>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'totalCount',
|
||||||
|
header: 'Total',
|
||||||
|
accessorFn: (row) => row.totalCount ?? 0,
|
||||||
|
cell: ({ getValue }) => <div className="text-center">{getValue<number>().toLocaleString()}</div>,
|
||||||
|
},
|
||||||
|
...resultCodeColumns.map(({ resultCd, label }): DataTableColumn<ProgressDateResponse> => ({
|
||||||
|
id: `rc-${resultCd}`,
|
||||||
|
header: label,
|
||||||
|
accessorFn: (row) => row.resultCodeCountMap?.[resultCd] ?? 0,
|
||||||
|
cell: ({ getValue }) => <div className="text-center">{getValue<number>().toLocaleString()}</div>,
|
||||||
|
})),
|
||||||
|
], [resultCodeColumns])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
@@ -46,45 +81,13 @@ export function DateProgressSection({ title, subtitle, rows, resultCodeColumns }
|
|||||||
<KriLineChart categories={categories} series={series} height={320} />
|
<KriLineChart categories={categories} series={series} height={320} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="rounded-md border overflow-auto max-h-[320px]">
|
<DataTable<ProgressDateResponse>
|
||||||
<table className="w-full text-sm whitespace-nowrap">
|
columns={columns}
|
||||||
<thead className="sticky top-0 z-10 bg-blue-50">
|
data={sortedRows}
|
||||||
<tr>
|
getRowId={(row, index) => `${row.contactDate ?? ''}-${index}`}
|
||||||
<th className="h-9 px-3 text-center font-semibold border-b">일자</th>
|
disablePagination
|
||||||
<th className="h-9 px-3 text-center font-semibold border-b">시작</th>
|
maxBodyHeight="320px"
|
||||||
<th className="h-9 px-3 text-center font-semibold border-b">종료</th>
|
/>
|
||||||
<th className="h-9 px-3 text-center font-semibold border-b">Total</th>
|
|
||||||
{resultCodeColumns.map(({ resultCd, label }) => (
|
|
||||||
<th key={resultCd} className="h-9 px-3 text-center font-semibold border-b">
|
|
||||||
{label}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{sortedRows.length === 0 && (
|
|
||||||
<tr>
|
|
||||||
<td colSpan={4 + resultCodeColumns.length} className="h-16 text-center text-muted-foreground">
|
|
||||||
데이터가 없습니다.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
{sortedRows.map((row, index) => (
|
|
||||||
<tr key={`${row.contactDate}-${index}`} className="border-b last:border-b-0">
|
|
||||||
<td className="h-9 px-3 text-center">{row.contactDate ?? '-'}</td>
|
|
||||||
<td className="h-9 px-3 text-center">{row.startTime ?? '-'}</td>
|
|
||||||
<td className="h-9 px-3 text-center">{row.endTime ?? '-'}</td>
|
|
||||||
<td className="h-9 px-3 text-center">{(row.totalCount ?? 0).toLocaleString()}</td>
|
|
||||||
{resultCodeColumns.map(({ resultCd }) => (
|
|
||||||
<td key={resultCd} className="h-9 px-3 text-center">
|
|
||||||
{(row.resultCodeCountMap?.[resultCd] ?? 0).toLocaleString()}
|
|
||||||
</td>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useMemo, useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react'
|
import { DataTable } from '@/components/data-table/DataTable'
|
||||||
import { cn } from '@/lib/utils'
|
import type { DataTableColumn } from '@/components/data-table/DataTable.type'
|
||||||
import type { ProgressUserResponse } from '@/types/progress'
|
import type { ProgressUserResponse } from '@/types/progress'
|
||||||
import type { ResultCodeColumn } from './resultCodeColumns'
|
import type { ResultCodeColumn } from './resultCodeColumns'
|
||||||
|
|
||||||
@@ -14,23 +14,8 @@ export type UserProgressTableProps = {
|
|||||||
onSelectUser: (userId: string | null) => void
|
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<string, string>) => {
|
|
||||||
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 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 <ArrowUpDown className="size-3 text-muted-foreground" />
|
|
||||||
return sort.dir === 'asc' ? <ArrowUp className="size-3" /> : <ArrowDown className="size-3" />
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UserProgressTable({
|
export function UserProgressTable({
|
||||||
rows,
|
rows,
|
||||||
resultCodeColumns,
|
resultCodeColumns,
|
||||||
@@ -38,114 +23,58 @@ export function UserProgressTable({
|
|||||||
selectedUserId,
|
selectedUserId,
|
||||||
onSelectUser,
|
onSelectUser,
|
||||||
}: UserProgressTableProps) {
|
}: UserProgressTableProps) {
|
||||||
const [sort, setSort] = useState<SortState>(null)
|
const totalRow = useMemo<ProgressUserResponse>(() => {
|
||||||
|
const resultCodeCountMap: Record<string, number> = {}
|
||||||
const total = useMemo(() => {
|
|
||||||
const totalCount = rows.reduce((acc, row) => acc + (row.totalCount ?? 0), 0)
|
|
||||||
const resultCodeCountMap: Record<number, number> = {}
|
|
||||||
resultCodeColumns.forEach(({ resultCd }) => {
|
resultCodeColumns.forEach(({ resultCd }) => {
|
||||||
resultCodeCountMap[resultCd] = rows.reduce((acc, row) => acc + (row.resultCodeCountMap?.[resultCd] ?? 0), 0)
|
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])
|
}, [rows, resultCodeColumns])
|
||||||
|
|
||||||
const sortedRows = useMemo(() => {
|
const columns = useMemo<DataTableColumn<ProgressUserResponse>[]>(() => [
|
||||||
if (!sort) return rows
|
{
|
||||||
const list = [...rows]
|
id: 'userId',
|
||||||
list.sort((a, b) => {
|
header: '담당자',
|
||||||
const av = getSortValue(a, sort.key, userNameMap)
|
accessorFn: (row) => userNameMap[row.userId ?? ''] ?? row.userId ?? '',
|
||||||
const bv = getSortValue(b, sort.key, userNameMap)
|
cell: ({ row }) => (
|
||||||
const compared = typeof av === 'string' && typeof bv === 'string' ? av.localeCompare(bv, 'ko') : Number(av) - Number(bv)
|
<div className="text-center">
|
||||||
return sort.dir === 'asc' ? compared : -compared
|
{row.getIsPinned() ? 'Total' : (userNameMap[row.original.userId ?? ''] ?? row.original.userId ?? '')}
|
||||||
})
|
</div>
|
||||||
return list
|
),
|
||||||
}, [rows, sort, userNameMap])
|
},
|
||||||
|
{
|
||||||
const toggleSort = (key: SortKey) => {
|
id: 'totalCount',
|
||||||
setSort((prev) => {
|
header: 'Total',
|
||||||
if (!prev || prev.key !== key) return { key, dir: 'asc' }
|
accessorFn: (row) => row.totalCount ?? 0,
|
||||||
if (prev.dir === 'asc') return { key, dir: 'desc' }
|
cell: ({ row }) => <div className="text-center">{(row.original.totalCount ?? 0).toLocaleString()}</div>,
|
||||||
return null
|
},
|
||||||
})
|
...resultCodeColumns.map(({ resultCd, label }): DataTableColumn<ProgressUserResponse> => ({
|
||||||
}
|
id: `rc-${resultCd}`,
|
||||||
|
header: label,
|
||||||
const headerButtonClass = 'flex items-center gap-1 mx-auto cursor-pointer select-none'
|
accessorFn: (row) => row.resultCodeCountMap?.[resultCd] ?? 0,
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const count = row.original.resultCodeCountMap?.[resultCd] ?? 0
|
||||||
|
const rowTotal = row.original.totalCount ?? 0
|
||||||
|
return <div className="text-center">{count.toLocaleString()} {pct(count, rowTotal)}</div>
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
], [resultCodeColumns, userNameMap])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-md border overflow-auto max-h-[420px]">
|
<DataTable<ProgressUserResponse>
|
||||||
<table className="w-full text-sm whitespace-nowrap">
|
columns={columns}
|
||||||
<thead className="sticky top-0 z-20 bg-blue-50">
|
data={rows}
|
||||||
<tr>
|
getRowId={(row) => row.userId ?? ''}
|
||||||
<th className="h-9 px-3 text-center font-semibold border-b">
|
topPinnedRows={[totalRow]}
|
||||||
<button type="button" className={headerButtonClass} onClick={() => toggleSort('userId')}>
|
disablePagination
|
||||||
담당자 <SortIcon column="userId" sort={sort} />
|
maxBodyHeight="420px"
|
||||||
</button>
|
selectMode="click-event"
|
||||||
</th>
|
focusRowId={selectedUserId ?? undefined}
|
||||||
<th className="h-9 px-3 text-center font-semibold border-b">
|
onRowClick={(row) => onSelectUser(selectedUserId === (row.userId ?? '') ? null : (row.userId ?? null))}
|
||||||
<button type="button" className={headerButtonClass} onClick={() => toggleSort('totalCount')}>
|
/>
|
||||||
Total <SortIcon column="totalCount" sort={sort} />
|
|
||||||
</button>
|
|
||||||
</th>
|
|
||||||
{resultCodeColumns.map(({ resultCd, label }) => (
|
|
||||||
<th key={resultCd} className="h-9 px-3 text-center font-semibold border-b">
|
|
||||||
<button type="button" className={headerButtonClass} onClick={() => toggleSort(`rc-${resultCd}`)}>
|
|
||||||
{label} <SortIcon column={`rc-${resultCd}`} sort={sort} />
|
|
||||||
</button>
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr className="sticky top-9 z-10 bg-gray-100 font-semibold border-b">
|
|
||||||
<td className="h-9 px-3 text-center">Total</td>
|
|
||||||
<td className="h-9 px-3 text-center">{total.totalCount.toLocaleString()}</td>
|
|
||||||
{resultCodeColumns.map(({ resultCd }) => {
|
|
||||||
const count = total.resultCodeCountMap[resultCd] ?? 0
|
|
||||||
return (
|
|
||||||
<td key={resultCd} className="h-9 px-3 text-center">
|
|
||||||
{count.toLocaleString()} {pct(count, total.totalCount)}
|
|
||||||
</td>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
{sortedRows.length === 0 && (
|
|
||||||
<tr>
|
|
||||||
<td colSpan={2 + resultCodeColumns.length} className="h-16 text-center text-muted-foreground">
|
|
||||||
데이터가 없습니다.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{sortedRows.map((row) => {
|
|
||||||
const userId = row.userId ?? ''
|
|
||||||
const rowTotal = row.totalCount ?? 0
|
|
||||||
const selected = selectedUserId === userId
|
|
||||||
return (
|
|
||||||
<tr
|
|
||||||
key={userId}
|
|
||||||
className={cn(
|
|
||||||
'border-b last:border-b-0 cursor-pointer hover:bg-muted/50',
|
|
||||||
selected && 'bg-muted font-semibold',
|
|
||||||
)}
|
|
||||||
onClick={() => onSelectUser(selected ? null : userId)}
|
|
||||||
>
|
|
||||||
<td className="h-9 px-3 text-center">{userNameMap[userId] ?? userId}</td>
|
|
||||||
<td className="h-9 px-3 text-center">{rowTotal.toLocaleString()}</td>
|
|
||||||
{resultCodeColumns.map(({ resultCd }) => {
|
|
||||||
const count = row.resultCodeCountMap?.[resultCd] ?? 0
|
|
||||||
return (
|
|
||||||
<td key={resultCd} className="h-9 px-3 text-center">
|
|
||||||
{count.toLocaleString()} {pct(count, rowTotal)}
|
|
||||||
</td>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user