fix(basic,admin_basic): 상한 목록의 페이저 소비단 정합 및 화면 표기
저장소가 총 건수를 상한까지만 세게 되면서 마지막 페이지 번호가 없는 목록이 생겼는데, 화면은 그 값을 1 로 접거나 페이저 노출 조건으로만 쓰고 있었다. 앞은 "1페이지뿐" 으로 잘못 말하고 뒤는 페이저를 통째로 지워 뒤쪽 페이지로 갈 방법 자체를 없앤다. 둘 다 예외도 404 도 내지 않아 화면은 정상으로 보이고 기능만 없다. Pagination 컴포넌트가 세 형태를 모두 이해하도록 넓혔다. 마지막 페이지를 알면 페이지 산술이 우선이고, 모를 때만 다음 페이지 존재 여부로 판정한다. 처음·마지막 버튼을 따로 켜고 끌 수 있게 나눠, 마지막 페이지를 모르는 목록에서는 그 버튼만 감춰지고 나머지 이동은 그대로 열려 있다. DataGrid 는 페이저를 그리는 두 경로 모두에 그 값을 전달한다 — 한쪽만 전달하면 그 화면만 첫 페이지에 갇힌다. 마이페이지 주문·마일리지·위시리스트·알림함, 게시판 목록, 상품 리뷰·문의, 내가 쓴 글, 관리자 설정 탭과 스케줄 이력의 소비 지점을 전건 옮겼다. 검색 화면은 총 건수를 정확히 세지 못한 경우 "N건 이상" 으로 표기하고 검색어를 좁히면 정확한 건수를 볼 수 있다고 안내한다. 탭 배지도 세지 못한 값을 정확한 숫자처럼 보여주지 않는다. 최신순은 첫 페이지부터 커서로 이동하며, 주소로 특정 페이지를 지목한 딥링크는 종전 동작을 유지한다. 쇼핑 첫 화면과 분류 화면을 단일 요청으로 재배선하고, 섹션 partial 이 부모가 선언한 이름을 읽도록 통일했다. 데이터소스 이름에 직결돼 있으면 다른 화면이 재사용할 때 폴백에 걸려 예외도 로그도 없이 섹션이 사라진다. 상품 상세의 "최근 본 상품" 이 계속 비어 있던 것은 존재하지 않는 라우트 파라미터를 읽고 있어서였다. 게시판 목록 세 스킨의 블라인드 아이콘 대비와 이미지 위 공통 색의 다크 모드 표기를 정리했다.
This commit is contained in:
1 parent
74a0a54016
commit
0d1105abfc
82 files changed
+1843
-460
No files matched your search
@@ -236,7 +236,20 @@ export interface DataGridProps {
|
||||
// 서버 사이드 페이지네이션 (API에서 페이지네이션 처리 시)
|
||||
serverSidePagination?: boolean;
|
||||
serverCurrentPage?: number;
|
||||
serverTotalPages?: number;
|
||||
/**
|
||||
* 서버가 알려준 마지막 페이지 번호
|
||||
*
|
||||
* 총 건수를 상한까지만 센 목록은 마지막 페이지를 계산할 수 없어 서버가 `null` 을 보낸다.
|
||||
* 1 로 채우면 화면이 "1페이지뿐" 이라고 잘못 말하므로 null 을 그대로 흘려보낸다.
|
||||
*/
|
||||
serverTotalPages?: number | null;
|
||||
/**
|
||||
* 다음 페이지 존재 여부 (총 건수를 모르는 목록에서 사용)
|
||||
*
|
||||
* 총 건수를 몰라도 서버는 이 값을 정확히 판정한다. 마지막 페이지를 계산할 수 없어도
|
||||
* "다음" 이동은 이 값으로 끝까지 열어 둘 수 있다.
|
||||
*/
|
||||
serverHasMorePages?: boolean;
|
||||
onPageChange?: (page: number) => void;
|
||||
|
||||
// 다국어 지원 텍스트 (레이아웃 JSON에서 $t: 문법으로 전달)
|
||||
@@ -651,6 +664,7 @@ export const DataGrid: React.FC<DataGridProps> = ({
|
||||
serverSidePagination = false,
|
||||
serverCurrentPage,
|
||||
serverTotalPages,
|
||||
serverHasMorePages,
|
||||
onPageChange,
|
||||
// 다국어 텍스트
|
||||
prevText,
|
||||
@@ -926,7 +940,18 @@ export const DataGrid: React.FC<DataGridProps> = ({
|
||||
|
||||
// 서버 사이드 페이지네이션인 경우 서버에서 전달된 값 사용
|
||||
const effectiveCurrentPage = serverSidePagination ? (serverCurrentPage || 1) : currentPage;
|
||||
const effectiveTotalPages = serverSidePagination ? (serverTotalPages || 1) : Math.ceil((sortedData?.length || 0) / pageSize);
|
||||
// 총 건수를 상한까지만 센 목록은 마지막 페이지가 null 로 온다. 1 로 채우면
|
||||
// 페이저가 통째로 접혀 1페이지 밖 행에 도달할 방법이 사라지므로 null 을 보존한다.
|
||||
const effectiveTotalPages: number | null = serverSidePagination
|
||||
? (serverTotalPages ?? null)
|
||||
: Math.ceil((sortedData?.length || 0) / pageSize);
|
||||
|
||||
// 마지막 페이지를 모르더라도 "다음" 이 열려 있거나 이미 2페이지 이상이면 페이저는 필요하다.
|
||||
const shouldShowPagination =
|
||||
alwaysShowPagination ||
|
||||
(effectiveTotalPages ?? 0) > 1 ||
|
||||
serverHasMorePages === true ||
|
||||
effectiveCurrentPage > 1;
|
||||
|
||||
// 페이지 변경 핸들러
|
||||
const handlePageChange = useCallback((page: number) => {
|
||||
@@ -1293,11 +1318,12 @@ export const DataGrid: React.FC<DataGridProps> = ({
|
||||
)}
|
||||
|
||||
{/* 페이지네이션 */}
|
||||
{pagination && (alwaysShowPagination || effectiveTotalPages > 1) && (
|
||||
{pagination && shouldShowPagination && (
|
||||
<Div className="flex justify-center mt-4">
|
||||
<Pagination
|
||||
currentPage={effectiveCurrentPage}
|
||||
totalPages={effectiveTotalPages}
|
||||
hasMorePages={serverSidePagination ? serverHasMorePages : undefined}
|
||||
onPageChange={handlePageChange}
|
||||
showFirstLast={showFirstLast}
|
||||
maxVisiblePages={5}
|
||||
@@ -1613,11 +1639,12 @@ export const DataGrid: React.FC<DataGridProps> = ({
|
||||
</Div>
|
||||
|
||||
{/* 페이지네이션 */}
|
||||
{pagination && (alwaysShowPagination || effectiveTotalPages > 1) && (
|
||||
{pagination && shouldShowPagination && (
|
||||
<Div className="flex justify-center mt-4">
|
||||
<Pagination
|
||||
currentPage={effectiveCurrentPage}
|
||||
totalPages={effectiveTotalPages}
|
||||
hasMorePages={serverSidePagination ? serverHasMorePages : undefined}
|
||||
onPageChange={handlePageChange}
|
||||
showFirstLast={showFirstLast}
|
||||
maxVisiblePages={5}
|
||||
|
||||
@@ -10,10 +10,40 @@ const t = (key: string, params?: Record<string, string | number>) =>
|
||||
|
||||
export interface PaginationProps {
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
/**
|
||||
* 마지막 페이지 번호
|
||||
*
|
||||
* 총 건수가 상한을 넘겨 정확히 세지 않은 목록은 마지막 페이지를 계산할 수 없다.
|
||||
* 그 경우 서버가 `null` 을 보내며, 페이지 번호 목록과 마지막 페이지 점프가 사라지고
|
||||
* 이전/다음 이동만 남는다. 0 이나 1 로 채우면 화면이 "1페이지뿐" 이라고 잘못 말하게 된다.
|
||||
*/
|
||||
totalPages: number | null;
|
||||
onPageChange: (page: number) => void;
|
||||
maxVisiblePages?: number;
|
||||
/**
|
||||
* 첫/마지막 페이지 버튼 표시 여부 (두 버튼의 기본값)
|
||||
*
|
||||
* 마지막 페이지만 따로 감춰야 하는 경우가 있으므로 `showLast` 로 덮어쓸 수 있다.
|
||||
*/
|
||||
showFirstLast?: boolean;
|
||||
/**
|
||||
* 첫 페이지 버튼 표시 여부 (미지정 시 showFirstLast 를 따른다)
|
||||
*/
|
||||
showFirst?: boolean;
|
||||
/**
|
||||
* 마지막 페이지 버튼 표시 여부 (미지정 시 showFirstLast 를 따른다)
|
||||
*
|
||||
* 총 건수가 부정확한 목록에서는 마지막 페이지를 계산할 수 없으므로,
|
||||
* `totalPages` 가 null 이면 이 값과 무관하게 감춰진다.
|
||||
*/
|
||||
showLast?: boolean;
|
||||
/**
|
||||
* 다음 페이지 존재 여부 (총 건수를 모르는 목록에서 사용)
|
||||
*
|
||||
* 총 건수를 몰라도 다음 페이지 존재 여부는 서버가 정확히 판정한다.
|
||||
* 지정하면 "다음" 버튼의 활성 여부를 이 값으로 정한다.
|
||||
*/
|
||||
hasMorePages?: boolean;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
prevText?: string;
|
||||
@@ -50,6 +80,9 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
onPageChange,
|
||||
maxVisiblePages = 5,
|
||||
showFirstLast = true,
|
||||
showFirst,
|
||||
showLast,
|
||||
hasMorePages,
|
||||
className = '',
|
||||
style,
|
||||
prevText,
|
||||
@@ -57,14 +90,35 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
id,
|
||||
editorAttrs,
|
||||
}) => {
|
||||
// 총 건수를 정확히 세지 못한 목록은 마지막 페이지를 계산할 수 없다.
|
||||
// 이때는 페이지 번호 목록과 마지막 페이지 점프를 감추고 이전/다음 이동만 남긴다 —
|
||||
// 끝까지 넘겨 보는 것은 그대로 가능하다.
|
||||
const isBounded = totalPages !== null && totalPages !== undefined;
|
||||
const resolvedTotalPages = isBounded ? (totalPages as number) : 0;
|
||||
|
||||
// 마지막 페이지를 알면 페이지 산술이 언제나 옳으므로 그쪽을 먼저 본다.
|
||||
// `hasMorePages` 를 우선하면, 응답에 `has_more_pages` 가 없어 레이아웃이 `?? false` 로
|
||||
// 채운 값이 정상 페이저의 "다음" 을 막아버린다 (실측: 1/2 페이지인데 다음 비활성).
|
||||
// 서버 판정이 필요한 자리는 마지막 페이지를 모르는 목록뿐이다.
|
||||
const canGoNext = isBounded
|
||||
? currentPage < resolvedTotalPages
|
||||
: (hasMorePages ?? false);
|
||||
|
||||
const displayFirst = (showFirst ?? showFirstLast) && isBounded;
|
||||
const displayLast = (showLast ?? showFirstLast) && isBounded;
|
||||
|
||||
// 페이지 번호 생성 알고리즘
|
||||
const pageNumbers = useMemo(() => {
|
||||
const pages: (number | string)[] = [];
|
||||
|
||||
if (totalPages <= maxVisiblePages + 2) {
|
||||
if (!isBounded) {
|
||||
// 마지막 페이지를 모르면 번호 목록을 만들 수 없다 (현재 페이지만 별도로 표시)
|
||||
return pages;
|
||||
}
|
||||
|
||||
if (resolvedTotalPages <= maxVisiblePages + 2) {
|
||||
// 페이지가 적으면 모두 표시
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
for (let i = 1; i <= resolvedTotalPages; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
} else {
|
||||
@@ -72,13 +126,13 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
const halfVisible = Math.floor(maxVisiblePages / 2);
|
||||
|
||||
let startPage = Math.max(2, currentPage - halfVisible);
|
||||
let endPage = Math.min(totalPages - 1, currentPage + halfVisible);
|
||||
let endPage = Math.min(resolvedTotalPages - 1, currentPage + halfVisible);
|
||||
|
||||
// 시작 또는 끝 근처일 때 조정
|
||||
if (currentPage <= halfVisible + 1) {
|
||||
endPage = maxVisiblePages;
|
||||
} else if (currentPage >= totalPages - halfVisible) {
|
||||
startPage = totalPages - maxVisiblePages + 1;
|
||||
} else if (currentPage >= resolvedTotalPages - halfVisible) {
|
||||
startPage = resolvedTotalPages - maxVisiblePages + 1;
|
||||
}
|
||||
|
||||
// 첫 페이지
|
||||
@@ -95,21 +149,22 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
}
|
||||
|
||||
// 끝 생략 부호
|
||||
if (endPage < totalPages - 1) {
|
||||
if (endPage < resolvedTotalPages - 1) {
|
||||
pages.push('...');
|
||||
}
|
||||
|
||||
// 마지막 페이지
|
||||
if (totalPages > 1) {
|
||||
pages.push(totalPages);
|
||||
if (resolvedTotalPages > 1) {
|
||||
pages.push(resolvedTotalPages);
|
||||
}
|
||||
}
|
||||
|
||||
return pages;
|
||||
}, [currentPage, totalPages, maxVisiblePages]);
|
||||
}, [currentPage, resolvedTotalPages, isBounded, maxVisiblePages]);
|
||||
|
||||
const handlePageClick = (page: number) => {
|
||||
if (page < 1 || page > totalPages || page === currentPage) return;
|
||||
if (page < 1 || page === currentPage) return;
|
||||
if (isBounded && page > resolvedTotalPages) return;
|
||||
onPageChange(page);
|
||||
};
|
||||
|
||||
@@ -120,7 +175,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (currentPage < totalPages) {
|
||||
if (canGoNext) {
|
||||
onPageChange(currentPage + 1);
|
||||
}
|
||||
};
|
||||
@@ -134,7 +189,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
id={id} {...editorAttrs}
|
||||
>
|
||||
{/* First Button */}
|
||||
{showFirstLast && (
|
||||
{displayFirst && (
|
||||
<Button
|
||||
onClick={() => handlePageClick(1)}
|
||||
disabled={currentPage === 1}
|
||||
@@ -155,8 +210,13 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
{prevText || <>‹</>}
|
||||
</Button>
|
||||
|
||||
{/* Page Numbers */}
|
||||
{/* Page Numbers — 마지막 페이지를 모르면 현재 페이지만 표시 */}
|
||||
<Div className="pagination">
|
||||
{!isBounded && (
|
||||
<Span className="px-3 py-1 text-sm text-gray-700 dark:text-gray-300">
|
||||
{currentPage}
|
||||
</Span>
|
||||
)}
|
||||
{pageNumbers.map((page, index) => {
|
||||
if (page === '...') {
|
||||
return (
|
||||
@@ -189,7 +249,7 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
{/* Next Button */}
|
||||
<Button
|
||||
onClick={handleNext}
|
||||
disabled={currentPage === totalPages}
|
||||
disabled={!canGoNext}
|
||||
className="pagination-btn"
|
||||
aria-label={t('common.next_page')}
|
||||
>
|
||||
@@ -197,10 +257,10 @@ export const Pagination: React.FC<PaginationProps> = ({
|
||||
</Button>
|
||||
|
||||
{/* Last Button */}
|
||||
{showFirstLast && (
|
||||
{displayLast && (
|
||||
<Button
|
||||
onClick={() => handlePageClick(totalPages)}
|
||||
disabled={currentPage === totalPages}
|
||||
onClick={() => handlePageClick(resolvedTotalPages)}
|
||||
disabled={currentPage === resolvedTotalPages}
|
||||
className="pagination-btn"
|
||||
aria-label={t('common.last_page')}
|
||||
>
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
/**
|
||||
* DataGrid 의 모든 Pagination 렌더 경로가 hasMorePages 를 넘기는지 전수 확인 (#519)
|
||||
*
|
||||
* DataGrid 는 표 뷰와 카드/모바일 뷰에서 Pagination 을 각각 렌더한다. 총 건수를 상한까지만
|
||||
* 센 목록은 `last_page` 가 null 로 오므로 "다음" 이동 가능 여부는 `hasMorePages` 로만
|
||||
* 판정된다. 렌더 경로 중 하나라도 그 값을 넘기지 않으면 그 뷰에서만 이전·다음이 모두
|
||||
* 비활성이 되어 1 페이지에 갇힌다 — 예외도 경고도 없이 화면에서만 드러난다.
|
||||
*
|
||||
* 실측 회귀 (2026-08-03): 관리자 활동 로그(88,792 건)에서 표 뷰 경로만 이 값을 빠뜨려
|
||||
* 이전·다음이 둘 다 비활성이었다. 한 곳을 고쳐도 다음에 추가되는 렌더 경로가 또 빠질 수
|
||||
* 있으므로 **개별 지점을 열거하지 않고 소스를 스캔해 전수로 강제한다**.
|
||||
*/
|
||||
describe('DataGrid — Pagination 렌더 경로의 hasMorePages 전달', () => {
|
||||
const source = readFileSync(
|
||||
resolve(dirname(fileURLToPath(import.meta.url)), '../DataGrid.tsx'),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
/**
|
||||
* `<Pagination ... />` 블록을 모두 잘라냅니다.
|
||||
*/
|
||||
const paginationBlocks = (): string[] => {
|
||||
const blocks: string[] = [];
|
||||
let from = 0;
|
||||
|
||||
for (;;) {
|
||||
const start = source.indexOf('<Pagination', from);
|
||||
if (start === -1) break;
|
||||
|
||||
const end = source.indexOf('/>', start);
|
||||
expect(end, 'Pagination 태그가 닫히지 않았습니다').toBeGreaterThan(start);
|
||||
|
||||
blocks.push(source.slice(start, end + 2));
|
||||
from = end + 2;
|
||||
}
|
||||
|
||||
return blocks;
|
||||
};
|
||||
|
||||
it('Pagination 렌더 경로가 하나 이상 존재한다', () => {
|
||||
// 스캔 대상이 0 개면 아래 단언이 조용히 통과한다 — 모집단부터 고정한다.
|
||||
expect(paginationBlocks().length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('모든 Pagination 렌더 경로가 hasMorePages 를 넘긴다', () => {
|
||||
const missing = paginationBlocks()
|
||||
.map((block, index) => ({ index, block }))
|
||||
.filter(({ block }) => !block.includes('hasMorePages'));
|
||||
|
||||
expect(
|
||||
missing.map(({ index }) => `#${index + 1}`),
|
||||
`hasMorePages 를 넘기지 않는 Pagination 렌더 경로가 있습니다:\n${missing
|
||||
.map(({ block }) => block)
|
||||
.join('\n---\n')}`
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('모든 Pagination 렌더 경로가 totalPages 로 null 을 보존한다', () => {
|
||||
// last_page 를 1 로 채우면 페이저가 접혀 1 페이지 밖 행에 도달할 수 없다.
|
||||
const blocks = paginationBlocks();
|
||||
|
||||
for (const block of blocks) {
|
||||
expect(block).toContain('totalPages');
|
||||
expect(block, `totalPages 에 1 을 폴백으로 채우면 안 됩니다:\n${block}`).not.toMatch(
|
||||
/totalPages=\{[^}]*\?\?\s*1\s*\}/
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
+45
@@ -164,4 +164,49 @@ describe('Pagination', () => {
|
||||
);
|
||||
expect(container.firstChild).toHaveClass('custom-pagination');
|
||||
});
|
||||
|
||||
/**
|
||||
* hasMorePages 와 last_page 의 우선순위 회귀 (#519)
|
||||
*
|
||||
* 총 건수가 정확해 last_page 를 아는 목록은 페이지 산술이 언제나 옳다. 그때 응답에
|
||||
* has_more_pages 가 없어 레이아웃이 `?? false` 로 채워 넣더라도 그 false 가 "다음" 을
|
||||
* 막아서는 안 된다. has_more_pages 가 필요한 자리는 last_page 를 모르는 목록뿐이다.
|
||||
*
|
||||
* 실측 회귀: /user/orders 응답에 has_more_pages 가 없어 1/2 페이지인데 다음이 비활성.
|
||||
*/
|
||||
describe('hasMorePages 와 last_page 의 우선순위', () => {
|
||||
it('last_page 를 알면 hasMorePages=false 여도 다음이 열려 있다', () => {
|
||||
render(
|
||||
<Pagination currentPage={1} totalPages={2} hasMorePages={false} onPageChange={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(screen.getByLabelText('다음 페이지')).not.toBeDisabled();
|
||||
});
|
||||
|
||||
it('last_page 를 알고 마지막 페이지면 다음이 막힌다', () => {
|
||||
render(
|
||||
<Pagination currentPage={2} totalPages={2} hasMorePages={false} onPageChange={vi.fn()} />
|
||||
);
|
||||
|
||||
expect(screen.getByLabelText('다음 페이지')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('last_page 가 null 이면 hasMorePages 가 다음 이동을 정한다', () => {
|
||||
const { rerender } = render(
|
||||
<Pagination currentPage={5} totalPages={null} hasMorePages={true} onPageChange={vi.fn()} />
|
||||
);
|
||||
expect(screen.getByLabelText('다음 페이지')).not.toBeDisabled();
|
||||
|
||||
rerender(
|
||||
<Pagination currentPage={5} totalPages={null} hasMorePages={false} onPageChange={vi.fn()} />
|
||||
);
|
||||
expect(screen.getByLabelText('다음 페이지')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('last_page 가 null 이고 hasMorePages 도 없으면 다음이 막힌다', () => {
|
||||
render(<Pagination currentPage={1} totalPages={null} onPageChange={vi.fn()} />);
|
||||
|
||||
expect(screen.getByLabelText('다음 페이지')).toBeDisabled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user