@ornery/ui-grid-react 0.1.6 → 0.1.7-hotfix-1
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/demo/main.tsx +1 -1
- package/demo/vite.config.ts +1 -1
- package/dist/UiGrid.d.ts +1 -1
- package/dist/UiGrid.d.ts.map +1 -1
- package/dist/gridStateMath.d.ts +1 -1
- package/dist/gridStateMath.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +388 -239
- package/dist/index.mjs +245 -96
- package/dist/rustWasmGridEngine.d.ts +1 -1
- package/dist/rustWasmGridEngine.d.ts.map +1 -1
- package/dist/useGridState.d.ts +3 -2
- package/dist/useGridState.d.ts.map +1 -1
- package/dist/vanillaAdapter.d.ts +14 -0
- package/dist/vanillaAdapter.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/UiGrid.test.tsx +61 -24
- package/src/UiGrid.tsx +320 -198
- package/src/gridStateMath.test.ts +10 -8
- package/src/gridStateMath.ts +20 -7
- package/src/index.ts +20 -5
- package/src/rustWasmGridEngine.test.ts +4 -4
- package/src/rustWasmGridEngine.ts +4 -4
- package/src/ui-grid.css +56 -17
- package/src/useGridState.ts +20 -6
- package/src/vanillaAdapter.test.ts +33 -0
- package/src/vanillaAdapter.ts +36 -0
- package/tsconfig.dts.json +1 -1
- package/tsconfig.json +1 -1
- package/vitest.config.ts +1 -1
package/src/UiGrid.test.tsx
CHANGED
|
@@ -3,8 +3,8 @@ import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
|
3
3
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
4
4
|
import { UiGrid } from './UiGrid';
|
|
5
5
|
import type { UiGridProps } from './UiGrid';
|
|
6
|
-
import type { GridOptions, UiGridApi, GridExpandableTemplateContext } from '@ornery/ui-grid';
|
|
7
|
-
import { SORT_DIRECTIONS, FILTER_CONDITIONS } from '@ornery/ui-grid';
|
|
6
|
+
import type { GridOptions, UiGridApi, GridExpandableTemplateContext } from '@ornery/ui-grid-core';
|
|
7
|
+
import { SORT_DIRECTIONS, FILTER_CONDITIONS } from '@ornery/ui-grid-core';
|
|
8
8
|
|
|
9
9
|
const baseData = [
|
|
10
10
|
{
|
|
@@ -35,7 +35,7 @@ const baseData = [
|
|
|
35
35
|
|
|
36
36
|
function createOptions(
|
|
37
37
|
overrides: Partial<GridOptions> = {},
|
|
38
|
-
onRegisterApi?: (api: UiGridApi) => void
|
|
38
|
+
onRegisterApi?: (api: UiGridApi) => void,
|
|
39
39
|
): GridOptions {
|
|
40
40
|
return {
|
|
41
41
|
id: 'spec-grid',
|
|
@@ -72,7 +72,7 @@ function createOptions(
|
|
|
72
72
|
|
|
73
73
|
function renderGrid(
|
|
74
74
|
overrides: Partial<GridOptions> = {},
|
|
75
|
-
props: Partial<Omit<UiGridProps, 'options'>> = {}
|
|
75
|
+
props: Partial<Omit<UiGridProps, 'options'>> = {},
|
|
76
76
|
): { container: HTMLElement; gridApi: UiGridApi } {
|
|
77
77
|
let gridApi!: UiGridApi;
|
|
78
78
|
const options = createOptions(overrides, (api) => {
|
|
@@ -81,7 +81,7 @@ function renderGrid(
|
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
const { container } = render(
|
|
84
|
-
<UiGrid options={options} onRegisterApi={options.onRegisterApi as any} {...props}
|
|
84
|
+
<UiGrid options={options} onRegisterApi={options.onRegisterApi as any} {...props} />,
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
return { container, gridApi };
|
|
@@ -96,11 +96,11 @@ describe('UiGrid React component', () => {
|
|
|
96
96
|
it('registers the API and renders headers and rows', () => {
|
|
97
97
|
const { container, gridApi } = renderGrid();
|
|
98
98
|
|
|
99
|
-
const headers = Array.from(container.querySelectorAll('.header-label')).map(
|
|
100
|
-
|
|
99
|
+
const headers = Array.from(container.querySelectorAll('.header-label')).map((el) =>
|
|
100
|
+
el.textContent?.trim(),
|
|
101
101
|
);
|
|
102
|
-
const bodyCells = Array.from(container.querySelectorAll('.body-cell')).map(
|
|
103
|
-
|
|
102
|
+
const bodyCells = Array.from(container.querySelectorAll('.body-cell')).map((el) =>
|
|
103
|
+
el.textContent?.trim(),
|
|
104
104
|
);
|
|
105
105
|
|
|
106
106
|
expect(gridApi).toBeTruthy();
|
|
@@ -132,7 +132,7 @@ describe('UiGrid React component', () => {
|
|
|
132
132
|
|
|
133
133
|
expect(gridApi.core.getVisibleRows()).toEqual([]);
|
|
134
134
|
expect(container.querySelector('.empty-state strong')?.textContent).toContain(
|
|
135
|
-
'Nothing to show'
|
|
135
|
+
'Nothing to show',
|
|
136
136
|
);
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -164,6 +164,47 @@ describe('UiGrid React component', () => {
|
|
|
164
164
|
]);
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
+
it('reorders visible columns by header drag and drop without shifting hidden columns', () => {
|
|
168
|
+
const { container } = renderGrid({
|
|
169
|
+
columnDefs: [
|
|
170
|
+
{ name: 'id', visible: false },
|
|
171
|
+
{ name: 'name', displayName: 'Customer' },
|
|
172
|
+
{ name: 'status' },
|
|
173
|
+
{ name: 'revenue' },
|
|
174
|
+
{ name: 'owner', field: 'account.owner' },
|
|
175
|
+
{ name: 'badge' },
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const dataTransfer = {
|
|
180
|
+
effectAllowed: 'all',
|
|
181
|
+
dropEffect: 'none',
|
|
182
|
+
store: new Map<string, string>(),
|
|
183
|
+
setData(type: string, value: string) {
|
|
184
|
+
this.store.set(type, value);
|
|
185
|
+
},
|
|
186
|
+
getData(type: string) {
|
|
187
|
+
return this.store.get(type) ?? '';
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const sourceHeader = container.querySelectorAll('.header-cell')[4] as HTMLElement;
|
|
192
|
+
const targetHeader = container.querySelectorAll('.header-cell')[1] as HTMLElement;
|
|
193
|
+
|
|
194
|
+
act(() => {
|
|
195
|
+
fireEvent.dragStart(sourceHeader, { dataTransfer });
|
|
196
|
+
fireEvent.dragOver(targetHeader, { dataTransfer });
|
|
197
|
+
fireEvent.drop(targetHeader, { dataTransfer });
|
|
198
|
+
fireEvent.dragEnd(sourceHeader, { dataTransfer });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const headers = Array.from(container.querySelectorAll('.header-label')).map((el) =>
|
|
202
|
+
el.textContent?.trim(),
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
expect(headers).toEqual(['Customer', 'Badge', 'Status', 'Revenue', 'Owner']);
|
|
206
|
+
});
|
|
207
|
+
|
|
167
208
|
it('groups rows and collapses groups', () => {
|
|
168
209
|
const { container, gridApi } = renderGrid();
|
|
169
210
|
|
|
@@ -180,7 +221,7 @@ describe('UiGrid React component', () => {
|
|
|
180
221
|
expect(container.querySelectorAll('.body-cell')).toHaveLength(15);
|
|
181
222
|
|
|
182
223
|
const activeGroup = Array.from(initialGroups).find((node) =>
|
|
183
|
-
node.textContent?.includes('status: Active')
|
|
224
|
+
node.textContent?.includes('status: Active'),
|
|
184
225
|
);
|
|
185
226
|
expect(activeGroup).toBeTruthy();
|
|
186
227
|
|
|
@@ -196,13 +237,9 @@ describe('UiGrid React component', () => {
|
|
|
196
237
|
const anchor = document.createElement('a');
|
|
197
238
|
const originalCreateElement = document.createElement.bind(document);
|
|
198
239
|
const clickSpy = vi.spyOn(anchor, 'click').mockImplementation(() => {});
|
|
199
|
-
vi.spyOn(document, 'createElement').mockImplementation(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
203
|
-
const createObjectUrlSpy = vi
|
|
204
|
-
.spyOn(URL, 'createObjectURL')
|
|
205
|
-
.mockReturnValue('blob:spec-grid');
|
|
240
|
+
vi.spyOn(document, 'createElement').mockImplementation(((tagName: string) =>
|
|
241
|
+
tagName === 'a' ? anchor : originalCreateElement(tagName)) as typeof document.createElement);
|
|
242
|
+
const createObjectUrlSpy = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:spec-grid');
|
|
206
243
|
vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => {});
|
|
207
244
|
|
|
208
245
|
act(() => {
|
|
@@ -287,7 +324,7 @@ describe('UiGrid React component', () => {
|
|
|
287
324
|
gridApi.edit.on.cancelCellEdit(cancelCellEdit);
|
|
288
325
|
|
|
289
326
|
const firstNameCell = container.querySelector(
|
|
290
|
-
'.body-cell[data-row-id="row-1"][data-col-name="name"]'
|
|
327
|
+
'.body-cell[data-row-id="row-1"][data-col-name="name"]',
|
|
291
328
|
) as HTMLElement;
|
|
292
329
|
|
|
293
330
|
await act(async () => {
|
|
@@ -296,7 +333,7 @@ describe('UiGrid React component', () => {
|
|
|
296
333
|
});
|
|
297
334
|
|
|
298
335
|
let editor = container.querySelector(
|
|
299
|
-
'.cell-editor[data-row-id="row-1"][data-col-name="name"]'
|
|
336
|
+
'.cell-editor[data-row-id="row-1"][data-col-name="name"]',
|
|
300
337
|
) as HTMLInputElement;
|
|
301
338
|
expect(editor).toBeTruthy();
|
|
302
339
|
expect(beginCellEdit).toHaveBeenCalled();
|
|
@@ -309,7 +346,7 @@ describe('UiGrid React component', () => {
|
|
|
309
346
|
expect(afterCellEdit).toHaveBeenCalled();
|
|
310
347
|
|
|
311
348
|
const ownerCell = container.querySelector(
|
|
312
|
-
'.body-cell[data-row-id="row-1"][data-col-name="owner"]'
|
|
349
|
+
'.body-cell[data-row-id="row-1"][data-col-name="owner"]',
|
|
313
350
|
) as HTMLElement;
|
|
314
351
|
|
|
315
352
|
await act(async () => {
|
|
@@ -318,7 +355,7 @@ describe('UiGrid React component', () => {
|
|
|
318
355
|
});
|
|
319
356
|
|
|
320
357
|
editor = container.querySelector(
|
|
321
|
-
'.cell-editor[data-row-id="row-1"][data-col-name="owner"]'
|
|
358
|
+
'.cell-editor[data-row-id="row-1"][data-col-name="owner"]',
|
|
322
359
|
) as HTMLInputElement;
|
|
323
360
|
expect(editor).toBeTruthy();
|
|
324
361
|
|
|
@@ -360,8 +397,8 @@ describe('UiGrid React component', () => {
|
|
|
360
397
|
],
|
|
361
398
|
});
|
|
362
399
|
|
|
363
|
-
const headers = Array.from(container.querySelectorAll('.header-label')).map(
|
|
364
|
-
|
|
400
|
+
const headers = Array.from(container.querySelectorAll('.header-label')).map((el) =>
|
|
401
|
+
el.textContent?.trim(),
|
|
365
402
|
);
|
|
366
403
|
expect(headers).toEqual(['Status', 'Owner']);
|
|
367
404
|
expect(container.querySelector('.filter-grid')).toBeNull();
|