Merge pull request '260917_01_fix: 컨택 목록 복귀 시 필터·정렬·페이지 상태 복원' (#37) from develop into master

Reviewed-on: #37
This commit is contained in:
2026-09-17 07:36:26 +09:00
3 changed files with 23 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ export function DataTable<TData, TValue = unknown>({
totalCount: serverTotalCount, totalCount: serverTotalCount,
pagination: externalPagination, pagination: externalPagination,
onPaginationChange: onServerPaginationChange, onPaginationChange: onServerPaginationChange,
sorting: externalSorting,
onSortingChange: onServerSortingChange, onSortingChange: onServerSortingChange,
selectMode = 'none', selectMode = 'none',
onRowClick, onRowClick,
@@ -41,7 +42,7 @@ export function DataTable<TData, TValue = unknown>({
bottomPinnedRows = 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 [internalSorting, setInternalSorting] = useState<SortingState>([])
const [rowSelection, setRowSelection] = useState<RowSelectionState>({}) const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
const scrollContainerRef = useRef<HTMLDivElement>(null) const scrollContainerRef = useRef<HTMLDivElement>(null)
const drag = usePreventClickOnDrag() const drag = usePreventClickOnDrag()
@@ -78,6 +79,7 @@ export function DataTable<TData, TValue = unknown>({
}, [columns, selectMode, selectionEnabled]) }, [columns, selectMode, selectionEnabled])
const pagination = isClient ? internalPagination : (externalPagination ?? internalPagination) const pagination = isClient ? internalPagination : (externalPagination ?? internalPagination)
const sorting = !isClient && externalSorting ? externalSorting : internalSorting
useEffect(() => { useEffect(() => {
setRowSelection({}) setRowSelection({})
@@ -100,6 +102,20 @@ export function DataTable<TData, TValue = unknown>({
[isClient, onServerPaginationChange], [isClient, onServerPaginationChange],
) )
const handleSortingChange = useCallback<OnChangeFn<SortingState>>(
(updater) => {
const nextSorting = typeof updater === 'function' ? updater(sorting) : updater
if (!isClient && onServerSortingChange) {
onServerSortingChange(nextSorting)
return
}
setInternalSorting(nextSorting)
},
[isClient, onServerSortingChange, sorting],
)
const combinedData = useMemo( const combinedData = useMemo(
() => [...topPinnedRows, ...data, ...bottomPinnedRows], () => [...topPinnedRows, ...data, ...bottomPinnedRows],
[topPinnedRows, data, bottomPinnedRows], [topPinnedRows, data, bottomPinnedRows],
@@ -128,7 +144,7 @@ export function DataTable<TData, TValue = unknown>({
enableRowPinning: true, enableRowPinning: true,
keepPinnedRows: true, keepPinnedRows: true,
onRowSelectionChange: setRowSelection, onRowSelectionChange: setRowSelection,
onSortingChange: setSorting, onSortingChange: handleSortingChange,
onPaginationChange: handlePaginationChange, onPaginationChange: handlePaginationChange,
getCoreRowModel: getCoreRowModel(), getCoreRowModel: getCoreRowModel(),
getSortedRowModel: isClient ? getSortedRowModel() : undefined, getSortedRowModel: isClient ? getSortedRowModel() : undefined,
@@ -139,10 +155,6 @@ export function DataTable<TData, TValue = unknown>({
getRowId: internalGetRowId, getRowId: internalGetRowId,
}) })
useEffect(() => {
if (!isClient) onServerSortingChange?.(sorting)
}, [isClient, onServerSortingChange, sorting])
useEffect(() => { useEffect(() => {
if (!selectionEnabled) return if (!selectionEnabled) return
onRowSelectionChange?.(table.getSelectedRowModel().rows.map((row) => row.original)) onRowSelectionChange?.(table.getSelectedRowModel().rows.map((row) => row.original))

View File

@@ -33,6 +33,7 @@ export interface DataTableProps<TData, TValue = unknown> {
totalCount?: number totalCount?: number
pagination?: PaginationState pagination?: PaginationState
onPaginationChange?: (updater: Updater<PaginationState>) => void onPaginationChange?: (updater: Updater<PaginationState>) => void
sorting?: SortingState
onSortingChange?: (sorting: SortingState) => void onSortingChange?: (sorting: SortingState) => void
selectMode?: SelectMode selectMode?: SelectMode
onRowClick?: (row: TData) => void onRowClick?: (row: TData) => void

View File

@@ -667,6 +667,8 @@ export function ListSearchTable({
}, [pagination, onPaginationChange]) }, [pagination, onPaginationChange])
useEffect(() => { useEffect(() => {
if (listHeaders.length === 0) return
setFilterRows((prev) => { setFilterRows((prev) => {
const next = prev.filter((row) => { const next = prev.filter((row) => {
const header = accessibleFilterHeaderById.get(row.headerId) const header = accessibleFilterHeaderById.get(row.headerId)
@@ -674,7 +676,7 @@ export function ListSearchTable({
}) })
return next.length === prev.length ? prev : next return next.length === prev.length ? prev : next
}) })
}, [accessibleFilterHeaderById, lockedListFilterHeaderTypes]) }, [accessibleFilterHeaderById, listHeaders.length, lockedListFilterHeaderTypes])
useEffect(() => { useEffect(() => {
if (!refreshKey || handledRefreshKeyRef.current === refreshKey) return if (!refreshKey || handledRefreshKeyRef.current === refreshKey) return
@@ -805,6 +807,7 @@ export function ListSearchTable({
totalCount={totalCount} totalCount={totalCount}
pagination={pagination} pagination={pagination}
onPaginationChange={setPagination} onPaginationChange={setPagination}
sorting={sorting}
onSortingChange={handleSortingChange} onSortingChange={handleSortingChange}
selectMode={selectMode} selectMode={selectMode}
onRowSelectionChange={handleRowSelectionChange} onRowSelectionChange={handleRowSelectionChange}