@ncds/ui-admin 1.8.26-alpha.8 → 1.8.26-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,28 +36,28 @@ const Pagination = _ref => {
36
36
  };
37
37
  (0, _react.useEffect)(() => {
38
38
  const lastGroupStart = Math.max(1, Math.floor((totalPage - 1) / pageCount) * pageCount + 1);
39
- // totalPage/pageCount 가 줄어 start 가 마지막 그룹을 넘으면 마지막 그룹으로 보정한다.
39
+ // totalPage/pageCount 가 줄어 start 가 마지막 그룹을 넘으면 마지막 그룹에서 시작해 아래 규칙을 계속 적용한다.
40
40
  // (예: 100→50 페이지로 축소 시 start 가 91 에 머물러 범위 밖 버튼을 표시하던 문제)
41
- if (start > lastGroupStart) {
42
- setStart(lastGroupStart);
43
- return;
41
+ // 바로 return 하면 새 검색으로 currentPage 가 1 이 돼도 1 이 목록에 없다 (PR #603 리뷰).
42
+ const baseStart = Math.min(start, lastGroupStart);
43
+ let nextStart = baseStart;
44
+ if (currentPage === baseStart + pageCount) {
45
+ nextStart = baseStart + pageCount;
44
46
  }
45
- if (currentPage === start + pageCount) {
46
- setStart(start + pageCount);
47
+ if (currentPage > baseStart + pageCount) {
48
+ nextStart = Math.floor((currentPage - 1) / pageCount) * pageCount + 1;
47
49
  }
48
- if (currentPage > start + pageCount) {
49
- const newStart = Math.floor((currentPage - 1) / pageCount) * pageCount + 1;
50
- setStart(newStart);
51
- }
52
- if (currentPage < start) {
53
- setStart(Math.max(1, start - pageCount));
50
+ if (currentPage < baseStart) {
51
+ nextStart = Math.max(1, baseStart - pageCount);
54
52
  }
55
53
  if (currentPage === 1) {
56
- setStart(1);
54
+ nextStart = 1;
57
55
  }
58
56
  if (currentPage === totalPage) {
59
- setStart(lastGroupStart);
57
+ nextStart = lastGroupStart;
60
58
  }
59
+ // currentPage 가 totalPage 를 넘는 값이어도 마지막 그룹을 넘지 않는다
60
+ setStart(Math.min(nextStart, lastGroupStart));
61
61
  // start 는 이 effect 가 setStart 로 갱신하는 대상이라 deps 에서 제외한다(넣으면 자기 갱신으로
62
62
  // 재실행). currentPage 외에 totalPage/pageCount 도 추적해, 이들이 줄어 start 가 범위를 벗어나면
63
63
  // 위에서 보정한다.
@@ -67,6 +67,23 @@ const nextOf = el => el.querySelector('.ncua-pagination__next');
67
67
  (0, _vitest.expect)(nums[0]).toBe(GROUP_START_50_PAGES);
68
68
  (0, _vitest.expect)(Math.max(...nums)).toBeLessThanOrEqual(LAST_PAGE_50);
69
69
  });
70
+ (0, _vitest.it)('totalPage 가 줄면서 currentPage 가 1 로 돌아오면 1 이 든 첫 그룹을 보인다 (PR #603 리뷰)', () => {
71
+ // 50 페이지 중 35 페이지(31~40 그룹) → 새 검색으로 25 페이지 결과의 1 페이지
72
+ const el = render({
73
+ totalCount: 750,
74
+ itemCountPerPage: 15,
75
+ pageCount: PAGE_GROUP_SIZE,
76
+ currentPage: 35
77
+ });
78
+ render({
79
+ totalCount: 375,
80
+ itemCountPerPage: 15,
81
+ pageCount: PAGE_GROUP_SIZE,
82
+ currentPage: 1
83
+ });
84
+ (0, _vitest.expect)(pageNums(el)[0]).toBe(1);
85
+ (0, _vitest.expect)(el.querySelector('.ncua-pagination__page-num.is-current')?.textContent).toBe('1');
86
+ });
70
87
  });
71
88
  (0, _vitest.describe)('Pagination — mo 모드 이전/다음 버튼 노출', () => {
72
89
  (0, _vitest.it)('페이지가 그룹 크기 이하여도 mo 에서는 이전·다음 버튼이 노출된다', () => {
@@ -29,28 +29,28 @@ export const Pagination = _ref => {
29
29
  };
30
30
  useEffect(() => {
31
31
  const lastGroupStart = Math.max(1, Math.floor((totalPage - 1) / pageCount) * pageCount + 1);
32
- // totalPage/pageCount 가 줄어 start 가 마지막 그룹을 넘으면 마지막 그룹으로 보정한다.
32
+ // totalPage/pageCount 가 줄어 start 가 마지막 그룹을 넘으면 마지막 그룹에서 시작해 아래 규칙을 계속 적용한다.
33
33
  // (예: 100→50 페이지로 축소 시 start 가 91 에 머물러 범위 밖 버튼을 표시하던 문제)
34
- if (start > lastGroupStart) {
35
- setStart(lastGroupStart);
36
- return;
34
+ // 바로 return 하면 새 검색으로 currentPage 가 1 이 돼도 1 이 목록에 없다 (PR #603 리뷰).
35
+ const baseStart = Math.min(start, lastGroupStart);
36
+ let nextStart = baseStart;
37
+ if (currentPage === baseStart + pageCount) {
38
+ nextStart = baseStart + pageCount;
37
39
  }
38
- if (currentPage === start + pageCount) {
39
- setStart(start + pageCount);
40
+ if (currentPage > baseStart + pageCount) {
41
+ nextStart = Math.floor((currentPage - 1) / pageCount) * pageCount + 1;
40
42
  }
41
- if (currentPage > start + pageCount) {
42
- const newStart = Math.floor((currentPage - 1) / pageCount) * pageCount + 1;
43
- setStart(newStart);
44
- }
45
- if (currentPage < start) {
46
- setStart(Math.max(1, start - pageCount));
43
+ if (currentPage < baseStart) {
44
+ nextStart = Math.max(1, baseStart - pageCount);
47
45
  }
48
46
  if (currentPage === 1) {
49
- setStart(1);
47
+ nextStart = 1;
50
48
  }
51
49
  if (currentPage === totalPage) {
52
- setStart(lastGroupStart);
50
+ nextStart = lastGroupStart;
53
51
  }
52
+ // currentPage 가 totalPage 를 넘는 값이어도 마지막 그룹을 넘지 않는다
53
+ setStart(Math.min(nextStart, lastGroupStart));
54
54
  // start 는 이 effect 가 setStart 로 갱신하는 대상이라 deps 에서 제외한다(넣으면 자기 갱신으로
55
55
  // 재실행). currentPage 외에 totalPage/pageCount 도 추적해, 이들이 줄어 start 가 범위를 벗어나면
56
56
  // 위에서 보정한다.
@@ -64,6 +64,23 @@ describe('#332 Pagination — totalPage 축소 시 start 보정', () => {
64
64
  expect(nums[0]).toBe(GROUP_START_50_PAGES);
65
65
  expect(Math.max(...nums)).toBeLessThanOrEqual(LAST_PAGE_50);
66
66
  });
67
+ it('totalPage 가 줄면서 currentPage 가 1 로 돌아오면 1 이 든 첫 그룹을 보인다 (PR #603 리뷰)', () => {
68
+ // 50 페이지 중 35 페이지(31~40 그룹) → 새 검색으로 25 페이지 결과의 1 페이지
69
+ const el = render({
70
+ totalCount: 750,
71
+ itemCountPerPage: 15,
72
+ pageCount: PAGE_GROUP_SIZE,
73
+ currentPage: 35
74
+ });
75
+ render({
76
+ totalCount: 375,
77
+ itemCountPerPage: 15,
78
+ pageCount: PAGE_GROUP_SIZE,
79
+ currentPage: 1
80
+ });
81
+ expect(pageNums(el)[0]).toBe(1);
82
+ expect(el.querySelector('.ncua-pagination__page-num.is-current')?.textContent).toBe('1');
83
+ });
67
84
  });
68
85
  describe('Pagination — mo 모드 이전/다음 버튼 노출', () => {
69
86
  it('페이지가 그룹 크기 이하여도 mo 에서는 이전·다음 버튼이 노출된다', () => {
@@ -19,28 +19,28 @@ export const Pagination = ({ className = '', totalCount, itemCountPerPage = 10,
19
19
  };
20
20
  useEffect(() => {
21
21
  const lastGroupStart = Math.max(1, Math.floor((totalPage - 1) / pageCount) * pageCount + 1);
22
- // totalPage/pageCount 가 줄어 start 가 마지막 그룹을 넘으면 마지막 그룹으로 보정한다.
22
+ // totalPage/pageCount 가 줄어 start 가 마지막 그룹을 넘으면 마지막 그룹에서 시작해 아래 규칙을 계속 적용한다.
23
23
  // (예: 100→50 페이지로 축소 시 start 가 91 에 머물러 범위 밖 버튼을 표시하던 문제)
24
- if (start > lastGroupStart) {
25
- setStart(lastGroupStart);
26
- return;
24
+ // 바로 return 하면 새 검색으로 currentPage 가 1 이 돼도 1 이 목록에 없다 (PR #603 리뷰).
25
+ const baseStart = Math.min(start, lastGroupStart);
26
+ let nextStart = baseStart;
27
+ if (currentPage === baseStart + pageCount) {
28
+ nextStart = baseStart + pageCount;
27
29
  }
28
- if (currentPage === start + pageCount) {
29
- setStart(start + pageCount);
30
+ if (currentPage > baseStart + pageCount) {
31
+ nextStart = Math.floor((currentPage - 1) / pageCount) * pageCount + 1;
30
32
  }
31
- if (currentPage > start + pageCount) {
32
- const newStart = Math.floor((currentPage - 1) / pageCount) * pageCount + 1;
33
- setStart(newStart);
34
- }
35
- if (currentPage < start) {
36
- setStart(Math.max(1, start - pageCount));
33
+ if (currentPage < baseStart) {
34
+ nextStart = Math.max(1, baseStart - pageCount);
37
35
  }
38
36
  if (currentPage === 1) {
39
- setStart(1);
37
+ nextStart = 1;
40
38
  }
41
39
  if (currentPage === totalPage) {
42
- setStart(lastGroupStart);
40
+ nextStart = lastGroupStart;
43
41
  }
42
+ // currentPage 가 totalPage 를 넘는 값이어도 마지막 그룹을 넘지 않는다
43
+ setStart(Math.min(nextStart, lastGroupStart));
44
44
  // start 는 이 effect 가 setStart 로 갱신하는 대상이라 deps 에서 제외한다(넣으면 자기 갱신으로
45
45
  // 재실행). currentPage 외에 totalPage/pageCount 도 추적해, 이들이 줄어 start 가 범위를 벗어나면
46
46
  // 위에서 보정한다.
@@ -64,6 +64,13 @@ describe('#332 Pagination — totalPage 축소 시 start 보정', () => {
64
64
  expect(nums[0]).toBe(GROUP_START_50_PAGES);
65
65
  expect(Math.max(...nums)).toBeLessThanOrEqual(LAST_PAGE_50);
66
66
  });
67
+ it('totalPage 가 줄면서 currentPage 가 1 로 돌아오면 1 이 든 첫 그룹을 보인다 (PR #603 리뷰)', () => {
68
+ // 50 페이지 중 35 페이지(31~40 그룹) → 새 검색으로 25 페이지 결과의 1 페이지
69
+ const el = render({ totalCount: 750, itemCountPerPage: 15, pageCount: PAGE_GROUP_SIZE, currentPage: 35 });
70
+ render({ totalCount: 375, itemCountPerPage: 15, pageCount: PAGE_GROUP_SIZE, currentPage: 1 });
71
+ expect(pageNums(el)[0]).toBe(1);
72
+ expect(el.querySelector('.ncua-pagination__page-num.is-current')?.textContent).toBe('1');
73
+ });
67
74
  });
68
75
  describe('Pagination — mo 모드 이전/다음 버튼 노출', () => {
69
76
  it('페이지가 그룹 크기 이하여도 mo 에서는 이전·다음 버튼이 노출된다', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ncds/ui-admin",
3
- "version": "1.8.26-alpha.8",
3
+ "version": "1.8.26-alpha.9",
4
4
  "description": "nhn-commerce의 어드민 디자인 시스템입니다.",
5
5
  "scripts": {
6
6
  "barrel": "node barrel.js",