@ncds/ui-admin 1.8.28-alpha.3 → 1.8.28-alpha.5
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.
- package/dist/cjs/assets/scripts/table/rowSpanBlock.js +97 -0
- package/dist/cjs/src/components/data-display/table/Table.js +135 -57
- package/dist/cjs/src/components/data-display/table/__tests__/Table.dnd.dragCell.test.js +7 -2
- package/dist/cjs/src/components/data-display/table/__tests__/Table.dnd.test.js +13 -8
- package/dist/cjs/src/components/data-display/table/__tests__/Table.rowGroup.test.js +54 -0
- package/dist/cjs/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.js +212 -0
- package/dist/cjs/src/components/data-display/table/__tests__/dnd-context.test.js +5 -2
- package/dist/cjs/src/components/data-display/table/__tests__/tableSelectableStyle.test.js +75 -0
- package/dist/cjs/src/components/data-display/table/dnd-context.js +4 -1
- package/dist/cjs/src/components/data-display/table/dnd-move.js +46 -0
- package/dist/cjs/src/components/data-display/table/dnd-preview.js +8 -3
- package/dist/cjs/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +16 -2
- package/dist/cjs/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +127 -0
- package/dist/cjs/src/generated/scoped-css.js +1 -1
- package/dist/esm/assets/scripts/table/rowSpanBlock.js +85 -0
- package/dist/esm/src/components/data-display/table/Table.js +135 -57
- package/dist/esm/src/components/data-display/table/__tests__/Table.dnd.dragCell.test.js +7 -2
- package/dist/esm/src/components/data-display/table/__tests__/Table.dnd.test.js +13 -8
- package/dist/esm/src/components/data-display/table/__tests__/Table.rowGroup.test.js +51 -0
- package/dist/esm/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.js +210 -0
- package/dist/esm/src/components/data-display/table/__tests__/dnd-context.test.js +5 -2
- package/dist/esm/src/components/data-display/table/__tests__/tableSelectableStyle.test.js +72 -0
- package/dist/esm/src/components/data-display/table/dnd-context.js +4 -1
- package/dist/esm/src/components/data-display/table/dnd-move.js +38 -0
- package/dist/esm/src/components/data-display/table/dnd-preview.js +8 -3
- package/dist/esm/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +16 -2
- package/dist/esm/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +127 -0
- package/dist/esm/src/generated/scoped-css.js +1 -1
- package/dist/temp/assets/scripts/table/rowSpanBlock.d.ts +29 -0
- package/dist/temp/assets/scripts/table/rowSpanBlock.js +77 -0
- package/dist/temp/src/components/data-display/table/Table.d.ts +7 -3
- package/dist/temp/src/components/data-display/table/Table.js +107 -47
- package/dist/temp/src/components/data-display/table/__tests__/Table.dnd.dragCell.test.js +10 -2
- package/dist/temp/src/components/data-display/table/__tests__/Table.dnd.test.js +16 -8
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroup.test.d.ts +1 -0
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroup.test.js +52 -0
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.d.ts +1 -0
- package/dist/temp/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.js +137 -0
- package/dist/temp/src/components/data-display/table/__tests__/dnd-context.test.js +2 -2
- package/dist/temp/src/components/data-display/table/__tests__/tableSelectableStyle.test.d.ts +1 -0
- package/dist/temp/src/components/data-display/table/__tests__/tableSelectableStyle.test.js +71 -0
- package/dist/temp/src/components/data-display/table/dnd-context.d.ts +3 -0
- package/dist/temp/src/components/data-display/table/dnd-context.js +1 -0
- package/dist/temp/src/components/data-display/table/dnd-move.d.ts +17 -0
- package/dist/temp/src/components/data-display/table/dnd-move.js +31 -0
- package/dist/temp/src/components/data-display/table/dnd-preview.d.ts +5 -1
- package/dist/temp/src/components/data-display/table/dnd-preview.js +7 -3
- package/dist/temp/src/components/data-display/table/types.d.ts +14 -5
- package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +16 -2
- package/dist/temp/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +92 -0
- package/dist/temp/src/generated/scoped-css.js +1 -1
- package/dist/types/assets/scripts/table/rowSpanBlock.d.ts +29 -0
- package/dist/types/src/components/data-display/table/Table.d.ts +7 -3
- package/dist/types/src/components/data-display/table/__tests__/Table.rowGroup.test.d.ts +1 -0
- package/dist/types/src/components/data-display/table/__tests__/Table.rowGroupDnd.test.d.ts +1 -0
- package/dist/types/src/components/data-display/table/__tests__/tableSelectableStyle.test.d.ts +1 -0
- package/dist/types/src/components/data-display/table/dnd-context.d.ts +3 -0
- package/dist/types/src/components/data-display/table/dnd-move.d.ts +17 -0
- package/dist/types/src/components/data-display/table/dnd-preview.d.ts +5 -1
- package/dist/types/src/components/data-display/table/types.d.ts +14 -5
- package/dist/ui-admin/assets/styles/style.css +60 -4
- package/package.json +1 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* 묶음은 스타일 레이어이므로 드래그앤드롭 동작이 묶음 유무와 무관해야 한다.
|
|
4
|
+
* 드롭 자체는 실제 포인터 이벤트가 필요해 jsdom 으로 재현할 수 없어, 감시 등록 횟수와 콜백 전달만 고정한다.
|
|
5
|
+
*/
|
|
6
|
+
import { createElement } from 'react';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import { act } from 'react-dom/test-utils';
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
10
|
+
const monitorCalls = [];
|
|
11
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop/element/adapter', () => ({
|
|
12
|
+
dropTargetForElements: () => () => undefined,
|
|
13
|
+
draggable: () => () => undefined,
|
|
14
|
+
monitorForElements: args => {
|
|
15
|
+
monitorCalls.push(args);
|
|
16
|
+
return () => undefined;
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview', () => ({
|
|
20
|
+
disableNativeDragPreview: () => undefined
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop-auto-scroll/element', () => ({
|
|
23
|
+
autoScrollForElements: () => () => undefined
|
|
24
|
+
}));
|
|
25
|
+
vi.mock('@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge', () => ({
|
|
26
|
+
attachClosestEdge: data => data,
|
|
27
|
+
extractClosestEdge: () => 'bottom'
|
|
28
|
+
}));
|
|
29
|
+
import { planMoveIds } from '../dnd-move';
|
|
30
|
+
const {
|
|
31
|
+
Table
|
|
32
|
+
} = await import('../Table');
|
|
33
|
+
let container;
|
|
34
|
+
let root;
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
monitorCalls.length = 0;
|
|
37
|
+
container = document.createElement('div');
|
|
38
|
+
document.body.appendChild(container);
|
|
39
|
+
act(() => {
|
|
40
|
+
root = createRoot(container);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
act(() => {
|
|
45
|
+
root.unmount();
|
|
46
|
+
});
|
|
47
|
+
container.remove();
|
|
48
|
+
});
|
|
49
|
+
const rowProps = id => ({
|
|
50
|
+
key: id,
|
|
51
|
+
dragId: id,
|
|
52
|
+
children: /*#__PURE__*/createElement(Table.Cell, null, id)
|
|
53
|
+
});
|
|
54
|
+
const row = id => /*#__PURE__*/createElement(Table.Row, rowProps(id));
|
|
55
|
+
const groupProps = (key, onRowDrop, ids) => ({
|
|
56
|
+
key,
|
|
57
|
+
onRowDrop,
|
|
58
|
+
children: ids.map(row)
|
|
59
|
+
});
|
|
60
|
+
const group = (key, onRowDrop, ids) => /*#__PURE__*/createElement(Table.RowGroup, groupProps(key, onRowDrop, ids));
|
|
61
|
+
const bodyProps = (onRowDrop, ids) => ({
|
|
62
|
+
onRowDrop,
|
|
63
|
+
children: ids.map(row)
|
|
64
|
+
});
|
|
65
|
+
const plainBodyProps = ids => ({
|
|
66
|
+
children: ids.map(row)
|
|
67
|
+
});
|
|
68
|
+
const tableProps = children => ({
|
|
69
|
+
type: 'horizontal',
|
|
70
|
+
draggable: true,
|
|
71
|
+
children
|
|
72
|
+
});
|
|
73
|
+
const renderTable = children => {
|
|
74
|
+
act(() => {
|
|
75
|
+
root.render(/*#__PURE__*/createElement(Table, tableProps(children)));
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
describe('Table.RowGroup — 드래그앤드롭', () => {
|
|
79
|
+
it('묶음이 여러 개여도 드롭 감시는 한 번만 등록된다', () => {
|
|
80
|
+
const onRowDrop = vi.fn();
|
|
81
|
+
renderTable([group('g1', onRowDrop, ['a', 'b']), group('g2', onRowDrop, ['c', 'd']), group('g3', onRowDrop, ['e'])]);
|
|
82
|
+
expect(monitorCalls).toHaveLength(1);
|
|
83
|
+
});
|
|
84
|
+
it('묶음에 넘긴 onRowDrop 이 드롭 1회에 1번만 호출된다', () => {
|
|
85
|
+
const onRowDrop = vi.fn();
|
|
86
|
+
renderTable([group('g1', onRowDrop, ['a', 'b']), group('g2', onRowDrop, ['c', 'd'])]);
|
|
87
|
+
for (const call of monitorCalls) {
|
|
88
|
+
call.onDrop({
|
|
89
|
+
source: {
|
|
90
|
+
data: {
|
|
91
|
+
id: 'a'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
location: {
|
|
95
|
+
current: {
|
|
96
|
+
dropTargets: [{
|
|
97
|
+
data: {
|
|
98
|
+
id: 'c'
|
|
99
|
+
}
|
|
100
|
+
}]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'c', 'bottom', ['a']);
|
|
107
|
+
});
|
|
108
|
+
it('다중 선택 드래그는 고른 행과 그 병합 블록을 모두 넘긴다', () => {
|
|
109
|
+
const onRowDrop = vi.fn();
|
|
110
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b', 'c', 'd'])));
|
|
111
|
+
const rows = Array.from(container.querySelectorAll('tbody tr'));
|
|
112
|
+
// a 가 b 를 덮고, c 는 혼자다 — a·c 를 고르면 b 도 따라와야 한다
|
|
113
|
+
rows[0].cells[0].rowSpan = 2;
|
|
114
|
+
rows[0].classList.add('ncua-table__row--selected');
|
|
115
|
+
rows[2].classList.add('ncua-table__row--selected');
|
|
116
|
+
monitorCalls[0].onDrop({
|
|
117
|
+
source: {
|
|
118
|
+
data: {
|
|
119
|
+
id: 'a',
|
|
120
|
+
moveIds: planMoveIds(rows[0])
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
location: {
|
|
124
|
+
current: {
|
|
125
|
+
dropTargets: [{
|
|
126
|
+
data: {
|
|
127
|
+
id: 'd'
|
|
128
|
+
}
|
|
129
|
+
}]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'd', 'bottom', ['a', 'b', 'c']);
|
|
134
|
+
});
|
|
135
|
+
it('고르지 않은 행을 잡으면 그 행의 블록만 넘긴다', () => {
|
|
136
|
+
const onRowDrop = vi.fn();
|
|
137
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b', 'c', 'd'])));
|
|
138
|
+
const rows = Array.from(container.querySelectorAll('tbody tr'));
|
|
139
|
+
rows[0].cells[0].rowSpan = 2;
|
|
140
|
+
rows[2].classList.add('ncua-table__row--selected');
|
|
141
|
+
monitorCalls[0].onDrop({
|
|
142
|
+
source: {
|
|
143
|
+
data: {
|
|
144
|
+
id: 'a',
|
|
145
|
+
moveIds: planMoveIds(rows[0])
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
location: {
|
|
149
|
+
current: {
|
|
150
|
+
dropTargets: [{
|
|
151
|
+
data: {
|
|
152
|
+
id: 'd'
|
|
153
|
+
}
|
|
154
|
+
}]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'd', 'bottom', ['a', 'b']);
|
|
159
|
+
});
|
|
160
|
+
it('onRowDrop 을 거두면 드롭이 더 이상 호출되지 않는다', () => {
|
|
161
|
+
const onRowDrop = vi.fn();
|
|
162
|
+
const drop = () => monitorCalls[0].onDrop({
|
|
163
|
+
source: {
|
|
164
|
+
data: {
|
|
165
|
+
id: 'a'
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
location: {
|
|
169
|
+
current: {
|
|
170
|
+
dropTargets: [{
|
|
171
|
+
data: {
|
|
172
|
+
id: 'b'
|
|
173
|
+
}
|
|
174
|
+
}]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b'])));
|
|
179
|
+
drop();
|
|
180
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
181
|
+
act(() => {
|
|
182
|
+
root.render(/*#__PURE__*/createElement(Table, tableProps(/*#__PURE__*/createElement(Table.Body, plainBodyProps(['a', 'b'])))));
|
|
183
|
+
});
|
|
184
|
+
drop();
|
|
185
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
186
|
+
});
|
|
187
|
+
it('Table.Body 의 onRowDrop 동작은 묶음 도입 전과 같다', () => {
|
|
188
|
+
const onRowDrop = vi.fn();
|
|
189
|
+
renderTable(/*#__PURE__*/createElement(Table.Body, bodyProps(onRowDrop, ['a', 'b'])));
|
|
190
|
+
expect(monitorCalls).toHaveLength(1);
|
|
191
|
+
monitorCalls[0].onDrop({
|
|
192
|
+
source: {
|
|
193
|
+
data: {
|
|
194
|
+
id: 'a'
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
location: {
|
|
198
|
+
current: {
|
|
199
|
+
dropTargets: [{
|
|
200
|
+
data: {
|
|
201
|
+
id: 'b'
|
|
202
|
+
}
|
|
203
|
+
}]
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
expect(onRowDrop).toHaveBeenCalledTimes(1);
|
|
208
|
+
expect(onRowDrop).toHaveBeenCalledWith('a', 'b', 'bottom', ['a']);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -46,13 +46,16 @@ describe('dnd-context — Provider 밖 기본값 (RSD-05)', () => {
|
|
|
46
46
|
});
|
|
47
47
|
expect(() => row?.setIsDragging(true)).not.toThrow();
|
|
48
48
|
});
|
|
49
|
-
it('RSD-05 TableDndContext 기본값은 드래그 비활성 · 빈 tableId
|
|
49
|
+
it('RSD-05 TableDndContext 기본값은 드래그 비활성 · 빈 tableId · 비어 있는 드롭 핸들러 자리다', () => {
|
|
50
50
|
const {
|
|
51
51
|
table
|
|
52
52
|
} = readDefaults();
|
|
53
53
|
expect(table).toEqual({
|
|
54
54
|
isDraggable: false,
|
|
55
|
-
tableId: ''
|
|
55
|
+
tableId: '',
|
|
56
|
+
onRowDropRef: {
|
|
57
|
+
current: undefined
|
|
58
|
+
}
|
|
56
59
|
});
|
|
57
60
|
});
|
|
58
61
|
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { compile as compileSass } from 'sass';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
// box-shadow 는 jsdom 에서 계산되지 않으므로, 컴파일된 CSS 에서 규칙을 검사한다.
|
|
5
|
+
// (page-title/__tests__/pageTitleStyle.test.ts 와 같은 방식)
|
|
6
|
+
const TABLE_SCSS_PATH = path.resolve(__dirname, '../../../../../assets/styles/components/table/_index.scss');
|
|
7
|
+
const compiledTableCss = compileSass(TABLE_SCSS_PATH).css;
|
|
8
|
+
/** 선택자 → 선언 목록. 같은 선택자가 여러 규칙에 나오면 선언을 이어 붙인다. */
|
|
9
|
+
const parseRules = css => {
|
|
10
|
+
const rules = new Map();
|
|
11
|
+
for (const [, selectorList, body] of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
|
12
|
+
const declarations = body.split(';').map(declaration => declaration.trim().replace(/\s+/g, ' ')).filter(Boolean);
|
|
13
|
+
for (const selector of selectorList.split(',').map(selector => selector.trim().replace(/\s+/g, ' '))) {
|
|
14
|
+
rules.set(selector, [...(rules.get(selector) ?? []), ...declarations]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return rules;
|
|
18
|
+
};
|
|
19
|
+
const rules = parseRules(compiledTableCss);
|
|
20
|
+
const declarationsOf = selector => rules.get(selector) ?? [];
|
|
21
|
+
const SELECTABLE = '.ncua-table--selectable';
|
|
22
|
+
const IN_DATA_GRID = '.ncua-table--in-data-grid.ncua-table--selectable';
|
|
23
|
+
const UNSELECTED_ROW = '.ncua-table__body .ncua-table__row:not(.ncua-table__row--selected)';
|
|
24
|
+
const HEADER_FIRST_CELL = '.ncua-table__header-cell:first-child';
|
|
25
|
+
const COMPENSATION_LINE = 'box-shadow: inset 1px 0 0 0 var(--gray-100)';
|
|
26
|
+
const NO_SHADOW = 'box-shadow: none';
|
|
27
|
+
describe('Table selectable — 좌측 border 보상선', () => {
|
|
28
|
+
it('행(tr)이 보상선을 갖는다 — 병합 셀이 덮은 행의 첫 셀은 표 왼쪽 끝이 아니다', () => {
|
|
29
|
+
// Given: 컴파일된 Table CSS 에서
|
|
30
|
+
// When: selectable 의 보상 규칙을 찾으면
|
|
31
|
+
const declarations = declarationsOf(`${SELECTABLE} ${UNSELECTED_ROW}`);
|
|
32
|
+
// Then: 셀이 아니라 행 전체에 보상선을 둔다
|
|
33
|
+
expect(declarations).toContain(COMPENSATION_LINE);
|
|
34
|
+
});
|
|
35
|
+
it('헤더 첫 칸도 보상선을 갖는다', () => {
|
|
36
|
+
// Given/When: 헤더 첫 칸 규칙을 찾으면
|
|
37
|
+
// Then: 기존 보상선이 그대로다
|
|
38
|
+
expect(declarationsOf(`${SELECTABLE} ${HEADER_FIRST_CELL}`)).toContain(COMPENSATION_LINE);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('Table selectable — DataGrid 안에서는 보상선을 거둔다', () => {
|
|
42
|
+
it('행(tr)의 보상선이 제거된다 — DataGrid wrapper 가 외곽 border 를 담당한다', () => {
|
|
43
|
+
// Given: 컴파일된 Table CSS 에서
|
|
44
|
+
// When: in-data-grid 조합의 행 규칙을 찾으면
|
|
45
|
+
const declarations = declarationsOf(`${IN_DATA_GRID} ${UNSELECTED_ROW}`);
|
|
46
|
+
// Then: 보상선을 지워 DataGrid 외곽선과 겹치지 않는다
|
|
47
|
+
expect(declarations).toContain(NO_SHADOW);
|
|
48
|
+
});
|
|
49
|
+
it('헤더 첫 칸의 보상선이 제거된다', () => {
|
|
50
|
+
// Given/When: in-data-grid 조합의 헤더 첫 칸 규칙을 찾으면
|
|
51
|
+
// Then: 보상선을 지운다
|
|
52
|
+
expect(declarationsOf(`${IN_DATA_GRID} ${HEADER_FIRST_CELL}`)).toContain(NO_SHADOW);
|
|
53
|
+
});
|
|
54
|
+
it('보상선을 받는 모든 자리에 제거 규칙이 대응한다 — 한쪽만 넓어지면 선이 남는다', () => {
|
|
55
|
+
// Given: 보상선을 받는 selectable 선택자를 모두 모으고
|
|
56
|
+
const compensated = [...rules].filter(_ref => {
|
|
57
|
+
let [selector, declarations] = _ref;
|
|
58
|
+
return selector.startsWith(SELECTABLE) && declarations.includes(COMPENSATION_LINE);
|
|
59
|
+
}).map(_ref2 => {
|
|
60
|
+
let [selector] = _ref2;
|
|
61
|
+
return selector;
|
|
62
|
+
});
|
|
63
|
+
// When: 각 선택자의 in-data-grid 대응 규칙을 찾으면
|
|
64
|
+
const uncovered = compensated.filter(selector => {
|
|
65
|
+
const counterpart = selector.replace(SELECTABLE, IN_DATA_GRID);
|
|
66
|
+
return !declarationsOf(counterpart).includes(NO_SHADOW);
|
|
67
|
+
});
|
|
68
|
+
// Then: 대응 없이 남는 자리가 없다
|
|
69
|
+
expect(compensated.length).toBeGreaterThan(0);
|
|
70
|
+
expect(uncovered).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
const TableDndContext = /*#__PURE__*/createContext({
|
|
3
3
|
isDraggable: false,
|
|
4
|
-
tableId: ''
|
|
4
|
+
tableId: '',
|
|
5
|
+
onRowDropRef: {
|
|
6
|
+
current: undefined
|
|
7
|
+
}
|
|
5
8
|
});
|
|
6
9
|
const RowDndContext = /*#__PURE__*/createContext({
|
|
7
10
|
dragId: undefined,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { computeRowSpanBlock, expandRowsToBlocks, locateRow as locateInBody, readRowSpans } from '../../../../assets/scripts/table/rowSpanBlock';
|
|
2
|
+
const DRAG_ID_ATTRIBUTE = 'data-draggable-id';
|
|
3
|
+
const toDragIds = rows => rows.map(row => row.getAttribute(DRAG_ID_ATTRIBUTE)).filter(id => id !== null);
|
|
4
|
+
/** 행 위치는 `tbody` 기준이라 묶음이 여러 개면 서로 겹친다 — 어느 `tbody` 인지 함께 본다 */
|
|
5
|
+
export const locateRow = rowEl => {
|
|
6
|
+
const located = locateInBody(rowEl);
|
|
7
|
+
const table = located?.body.closest('table');
|
|
8
|
+
if (!located || !table) return null;
|
|
9
|
+
return {
|
|
10
|
+
...located,
|
|
11
|
+
bodyIndex: Array.from(table.tBodies).indexOf(located.body)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** 병합이 덮는 행은 따로 옮길 수 없다. 드래그 단위를 그 행이 속한 병합 블록으로 넓힌다. */
|
|
15
|
+
export const findRowSpanBlock = rowEl => {
|
|
16
|
+
const located = locateRow(rowEl);
|
|
17
|
+
if (!located) return null;
|
|
18
|
+
const {
|
|
19
|
+
body,
|
|
20
|
+
bodyIndex,
|
|
21
|
+
index
|
|
22
|
+
} = located;
|
|
23
|
+
const block = computeRowSpanBlock(readRowSpans(body), index);
|
|
24
|
+
return {
|
|
25
|
+
...block,
|
|
26
|
+
bodyIndex,
|
|
27
|
+
rows: Array.from(body.rows).slice(block.start, block.end + 1)
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/** 이번 드래그로 옮겨야 하는 행 전부. 고른 행이 여럿이면 각자의 병합 블록까지 끌고 온다. */
|
|
31
|
+
export const planMoveIds = rowEl => {
|
|
32
|
+
const tableEl = rowEl.closest('table');
|
|
33
|
+
const selectedRows = tableEl ? Array.from(tableEl.querySelectorAll('tbody > .ncua-table__row--selected')) : [];
|
|
34
|
+
const isMultiSelect = selectedRows.length > 1 && selectedRows.includes(rowEl);
|
|
35
|
+
const rows = isMultiSelect ? expandRowsToBlocks(selectedRows) : findRowSpanBlock(rowEl)?.rows ?? [rowEl];
|
|
36
|
+
return toDragIds(rows);
|
|
37
|
+
};
|
|
38
|
+
export { DRAG_ID_ATTRIBUTE };
|
|
@@ -87,11 +87,16 @@ const buildRowCard = _ref => {
|
|
|
87
87
|
wrapper.appendChild(table);
|
|
88
88
|
return wrapper;
|
|
89
89
|
};
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @param rows 미리보기에 그릴 행. 병합 묶음은 한 건이라도 행이 여러 개다
|
|
92
|
+
* @param itemCount 옮기는 건수. 병합 묶음은 행 수와 다르므로, 생략하면 행 수를 건수로 본다
|
|
93
|
+
*/
|
|
94
|
+
const buildDragPreview = function (rows, rowRect) {
|
|
95
|
+
let itemCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : rows.length;
|
|
91
96
|
const visibleCount = Math.min(rows.length, PREVIEW_MAX_ROWS);
|
|
92
97
|
const hasSummary = rows.length > visibleCount;
|
|
93
98
|
const totalCards = visibleCount + (hasSummary ? 1 : 0);
|
|
94
|
-
const isMulti =
|
|
99
|
+
const isMulti = itemCount > 1;
|
|
95
100
|
const parentTable = rows[0]?.closest('table') ?? null;
|
|
96
101
|
const rowWidth = Math.round(rowRect.width);
|
|
97
102
|
const rowHeight = Math.round(rowRect.height);
|
|
@@ -101,7 +106,7 @@ const buildDragPreview = (rows, rowRect) => {
|
|
|
101
106
|
width: `${PREVIEW_BADGE_HALF + rowWidth}px`,
|
|
102
107
|
height: `${PREVIEW_BADGE_HALF + rowHeight + PREVIEW_STACK_OFFSET * (totalCards - 1)}px`
|
|
103
108
|
});
|
|
104
|
-
if (isMulti) container.appendChild(buildCountBadge(
|
|
109
|
+
if (isMulti) container.appendChild(buildCountBadge(itemCount));
|
|
105
110
|
if (hasSummary) container.appendChild(buildSummaryCard(rowRect));
|
|
106
111
|
// 뒤쪽 행 카드부터 렌더해서 앞쪽이 위로 올라오게
|
|
107
112
|
for (let i = visibleCount - 1; i >= 0; i--) {
|
|
@@ -14,6 +14,8 @@ const PAGE_SIZE = 15;
|
|
|
14
14
|
const PAGER_WINDOW = 10;
|
|
15
15
|
/** 검색 조합 안내 문구를 띄우는 기준 — 결과가 이 수를 넘을 때만 노출한다 */
|
|
16
16
|
const SEARCH_HINT_MIN_TOTAL_COUNT = 30;
|
|
17
|
+
/** 기획서 케이스 2 — 이 길이 미만이면 검색하지 않는다 */
|
|
18
|
+
const MIN_SEARCH_QUERY_LENGTH = 2;
|
|
17
19
|
/** 반응형 전환 기준 — assets/styles/base/_variable.scss 의 $breakpoint 와 동일 */
|
|
18
20
|
const MOBILE_BREAKPOINT = 768;
|
|
19
21
|
/** 본문 스크롤 컨테이너. Modal.Content 가 overflow-y:auto 를 갖는다. */
|
|
@@ -42,6 +44,8 @@ const resultKey = _ref => {
|
|
|
42
44
|
} = _ref;
|
|
43
45
|
return `${zipCode}|${roadAddress}|${jibunAddress}`;
|
|
44
46
|
};
|
|
47
|
+
/** 앞뒤 공백만 자르고 센다. 가운데 공백은 글자 수에 포함한다. */
|
|
48
|
+
const isSearchQueryTooShort = query => query.trim().length < MIN_SEARCH_QUERY_LENGTH;
|
|
45
49
|
/** SSR(도큐사우루스 등)에서는 초기값을 false(=PC)로 두고 mount 이후 갱신한다. */
|
|
46
50
|
const useIsMobileViewport = () => {
|
|
47
51
|
const [isMobile, setIsMobile] = useState(false);
|
|
@@ -109,6 +113,10 @@ const PostcodeSearchModal = _ref2 => {
|
|
|
109
113
|
// 검색이 실행된 검색어. 입력 중에는 갱신되지 않는다.
|
|
110
114
|
// 초기값은 마운트 시점의 searchQuery — 사용처가 검색어를 채운 채로 열면 그 검색은 이미 실행된 것으로 본다.
|
|
111
115
|
const [searchedQuery, setSearchedQuery] = useState(searchQuery);
|
|
116
|
+
// 검색어 길이 검사에 걸렸을 때의 오류코드. 사용처 errorCode 보다 앞선다.
|
|
117
|
+
// 사용처가 결과를 지우지 않아도 이 값이 있는 동안 목록을 숨긴다(늦게 온 응답 포함).
|
|
118
|
+
const [validationErrorCode, setValidationErrorCode] = useState();
|
|
119
|
+
const activeErrorCode = validationErrorCode ?? errorCode;
|
|
112
120
|
// Modal 은 닫혀도 이 컴포넌트를 언마운트하지 않아 내부 상태가 다음 열기까지 남는다.
|
|
113
121
|
// 열리는 순간 이전 세션의 선택·검색 상태를 지운다.
|
|
114
122
|
// biome-ignore lint/correctness/useExhaustiveDependencies: searchQuery 를 deps 에 넣으면 입력할 때마다 초기화된다
|
|
@@ -116,8 +124,9 @@ const PostcodeSearchModal = _ref2 => {
|
|
|
116
124
|
if (!open) return;
|
|
117
125
|
setSelectedKey(undefined);
|
|
118
126
|
setSearchedQuery(searchQuery);
|
|
127
|
+
setValidationErrorCode(undefined);
|
|
119
128
|
}, [open]);
|
|
120
|
-
const hasError = Boolean(
|
|
129
|
+
const hasError = Boolean(activeErrorCode);
|
|
121
130
|
const hasResults = !hasError && results.length > 0;
|
|
122
131
|
// 결과가 적으면 굳이 검색 조합을 안내하지 않는다.
|
|
123
132
|
const showSearchHint = hasResults && totalCount > SEARCH_HINT_MIN_TOTAL_COUNT;
|
|
@@ -130,6 +139,11 @@ const PostcodeSearchModal = _ref2 => {
|
|
|
130
139
|
onSearchQueryChange(event.target.value);
|
|
131
140
|
};
|
|
132
141
|
const handleSearch = () => {
|
|
142
|
+
if (isSearchQueryTooShort(searchQuery)) {
|
|
143
|
+
setValidationErrorCode('E0008');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
setValidationErrorCode(undefined);
|
|
133
147
|
setSearchedQuery(searchQuery);
|
|
134
148
|
onSearch();
|
|
135
149
|
};
|
|
@@ -170,7 +184,7 @@ const PostcodeSearchModal = _ref2 => {
|
|
|
170
184
|
onKeyDown: handleSearchKeyDown,
|
|
171
185
|
placeholder: SEARCH_PLACEHOLDER,
|
|
172
186
|
destructive: hasError,
|
|
173
|
-
hintText:
|
|
187
|
+
hintText: activeErrorCode ? ERROR_HINT[activeErrorCode] ?? DEFAULT_ERROR_HINT : undefined
|
|
174
188
|
}), _jsx(Button, {
|
|
175
189
|
className: "ncua-postcode-search-modal__search-button",
|
|
176
190
|
label: SEARCH_BUTTON_LABEL,
|
package/dist/esm/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js
CHANGED
|
@@ -617,4 +617,131 @@ describe('PostcodeSearchModal — 검색 영역 고정 표시', () => {
|
|
|
617
617
|
// Then: 고정할 대상이 없으므로 클래스는 붙지 않는다
|
|
618
618
|
expect(isFixedSearchArea(el)).toBe(false);
|
|
619
619
|
});
|
|
620
|
+
});
|
|
621
|
+
describe('PostcodeSearchModal — 검색어 2글자 미만 검사 (#678)', () => {
|
|
622
|
+
const SHORT_QUERY_HINT = '검색어를 두 글자 이상 입력해주세요.';
|
|
623
|
+
const searchButtonOf = el => el.querySelector('.ncua-postcode-search-modal__search-button');
|
|
624
|
+
const clickSearch = el => {
|
|
625
|
+
act(() => {
|
|
626
|
+
searchButtonOf(el)?.click();
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
it.each(['', ' ', '가', ' 가 '])('trim 후 2글자 미만("%s")이면 onSearch 를 부르지 않고 오류 문구를 보인다', searchQuery => {
|
|
630
|
+
// Given: 검색어가 trim 후 2글자 미만인 상태에서
|
|
631
|
+
const onSearch = vi.fn();
|
|
632
|
+
const el = render(baseProps({
|
|
633
|
+
searchQuery,
|
|
634
|
+
onSearch
|
|
635
|
+
}));
|
|
636
|
+
// When: 검색 버튼을 누르면
|
|
637
|
+
clickSearch(el);
|
|
638
|
+
// Then: 검색은 실행되지 않고 입력칸이 오류 상태가 된다
|
|
639
|
+
expect(onSearch).not.toHaveBeenCalled();
|
|
640
|
+
expect(hintOf(el)?.textContent).toBe(SHORT_QUERY_HINT);
|
|
641
|
+
expect(inputRootOf(el)?.classList.contains('destructive')).toBe(true);
|
|
642
|
+
});
|
|
643
|
+
it.each(['가나', ' 가나 '])('trim 후 2글자 이상("%s")이면 onSearch 를 부르고 오류가 없다', searchQuery => {
|
|
644
|
+
// Given: 검색어가 trim 후 2글자 이상인 상태에서
|
|
645
|
+
const onSearch = vi.fn();
|
|
646
|
+
const el = render(baseProps({
|
|
647
|
+
searchQuery,
|
|
648
|
+
onSearch
|
|
649
|
+
}));
|
|
650
|
+
// When: 검색 버튼을 누르면
|
|
651
|
+
clickSearch(el);
|
|
652
|
+
// Then: 검색이 실행되고 입력칸은 오류 상태가 아니다
|
|
653
|
+
expect(onSearch).toHaveBeenCalledTimes(1);
|
|
654
|
+
expect(hintOf(el)).toBeNull();
|
|
655
|
+
expect(inputRootOf(el)?.classList.contains('destructive')).toBe(false);
|
|
656
|
+
});
|
|
657
|
+
it('결과를 보여 주는 중에 1글자로 검색하면 목록·페이지네이션을 숨기고 Tip 을 보인다', () => {
|
|
658
|
+
// Given: 결과가 보이는 상태에서 검색어를 1글자로 바꾸고
|
|
659
|
+
const results = makeResults(SMALL_RESULT_COUNT);
|
|
660
|
+
render(baseProps({
|
|
661
|
+
searchQuery: '판교로',
|
|
662
|
+
results,
|
|
663
|
+
totalCount: SMALL_RESULT_COUNT
|
|
664
|
+
}));
|
|
665
|
+
const el = render(baseProps({
|
|
666
|
+
searchQuery: '가',
|
|
667
|
+
results,
|
|
668
|
+
totalCount: SMALL_RESULT_COUNT
|
|
669
|
+
}));
|
|
670
|
+
expect(itemsOf(el)).toHaveLength(SMALL_RESULT_COUNT);
|
|
671
|
+
// When: 검색 버튼을 누르면
|
|
672
|
+
clickSearch(el);
|
|
673
|
+
// Then: 사용처가 결과를 지우지 않아도 지난 목록은 보이지 않는다
|
|
674
|
+
expect(el.querySelector('.ncua-postcode-search-modal__list')).toBeNull();
|
|
675
|
+
expect(paginationOf(el)).toBeNull();
|
|
676
|
+
expect(tipOf(el)).not.toBeNull();
|
|
677
|
+
});
|
|
678
|
+
it('검사에 걸린 뒤 2글자 이상으로 다시 검색하면 오류가 풀리고 onSearch 를 부른다', () => {
|
|
679
|
+
// Given: 1글자로 검색해 검사에 걸린 상태에서
|
|
680
|
+
const onSearch = vi.fn();
|
|
681
|
+
const el = render(baseProps({
|
|
682
|
+
searchQuery: '가',
|
|
683
|
+
onSearch
|
|
684
|
+
}));
|
|
685
|
+
clickSearch(el);
|
|
686
|
+
// When: 2글자로 고쳐 다시 검색하면
|
|
687
|
+
render(baseProps({
|
|
688
|
+
searchQuery: '가나',
|
|
689
|
+
onSearch
|
|
690
|
+
}));
|
|
691
|
+
clickSearch(el);
|
|
692
|
+
// Then: 오류가 풀리고 검색이 실행된다
|
|
693
|
+
expect(onSearch).toHaveBeenCalledTimes(1);
|
|
694
|
+
expect(hintOf(el)).toBeNull();
|
|
695
|
+
expect(inputRootOf(el)?.classList.contains('destructive')).toBe(false);
|
|
696
|
+
});
|
|
697
|
+
it('검사에 걸린 뒤 모달을 닫았다 다시 열면 오류가 없다', () => {
|
|
698
|
+
// Given: 1글자로 검색해 검사에 걸린 상태에서
|
|
699
|
+
const el = render(baseProps({
|
|
700
|
+
searchQuery: '가'
|
|
701
|
+
}));
|
|
702
|
+
clickSearch(el);
|
|
703
|
+
// When: 모달을 닫았다가 다시 열면
|
|
704
|
+
render(baseProps({
|
|
705
|
+
open: false,
|
|
706
|
+
searchQuery: '가'
|
|
707
|
+
}));
|
|
708
|
+
const reopened = render(baseProps({
|
|
709
|
+
searchQuery: '가'
|
|
710
|
+
}));
|
|
711
|
+
// Then: 지난 검사 오류는 남지 않는다
|
|
712
|
+
expect(hintOf(reopened)).toBeNull();
|
|
713
|
+
expect(inputRootOf(reopened)?.classList.contains('destructive')).toBe(false);
|
|
714
|
+
});
|
|
715
|
+
it('앱 errorCode(E0006) 가 있어도 1글자로 검색하면 검사 오류 문구(E0008)를 보인다', () => {
|
|
716
|
+
// Given: 사용처가 E0006 을 넘긴 상태에서 검색어를 1글자로 바꾸고
|
|
717
|
+
const el = render(baseProps({
|
|
718
|
+
searchQuery: '가',
|
|
719
|
+
errorCode: 'E0006'
|
|
720
|
+
}));
|
|
721
|
+
// When: 검색 버튼을 누르면
|
|
722
|
+
clickSearch(el);
|
|
723
|
+
// Then: 컴포넌트 검사 오류가 앞선다
|
|
724
|
+
expect(hintOf(el)?.textContent).toBe(SHORT_QUERY_HINT);
|
|
725
|
+
});
|
|
726
|
+
it('Enter 로 1글자 검색해도 버튼과 같이 onSearch 를 부르지 않고 오류 문구를 보인다', () => {
|
|
727
|
+
// Given: 검색어가 1글자인 상태에서
|
|
728
|
+
const onSearch = vi.fn();
|
|
729
|
+
const el = render(baseProps({
|
|
730
|
+
searchQuery: '가',
|
|
731
|
+
onSearch
|
|
732
|
+
}));
|
|
733
|
+
const input = el.querySelector('.ncua-input input');
|
|
734
|
+
if (!input) throw new Error('검색 인풋이 렌더되지 않았습니다');
|
|
735
|
+
// When: Enter 를 누르면
|
|
736
|
+
act(() => {
|
|
737
|
+
input.dispatchEvent(new KeyboardEvent('keydown', {
|
|
738
|
+
key: 'Enter',
|
|
739
|
+
bubbles: true
|
|
740
|
+
}));
|
|
741
|
+
});
|
|
742
|
+
// Then: 버튼을 누른 것과 결과가 같다
|
|
743
|
+
expect(onSearch).not.toHaveBeenCalled();
|
|
744
|
+
expect(hintOf(el)?.textContent).toBe(SHORT_QUERY_HINT);
|
|
745
|
+
expect(inputRootOf(el)?.classList.contains('destructive')).toBe(true);
|
|
746
|
+
});
|
|
620
747
|
});
|