Skip to content

Commit

Permalink
remove support for columns/columnGroups as a Map
Browse files Browse the repository at this point in the history
  • Loading branch information
radubrehar committed Jun 3, 2024
1 parent 03f52db commit ee21656
Show file tree
Hide file tree
Showing 56 changed files with 951 additions and 1,371 deletions.
50 changes: 25 additions & 25 deletions examples/src/pages/tests/table/misc/buildColumnAndGroupTree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ type Person = {

export default test.describe.parallel('buildColumnAndGroupTree', () => {
test('should work correctly for groups that dont repeat twice', async () => {
const columnGroups: Map<string, InfiniteTableColumnGroup> = new Map([
['contact info', { header: 'Contact info' }],
['street', { header: 'street', columnGroup: 'address' }],
['address', { header: 'Address' }],
]);
const columnGroups: Record<string, InfiniteTableColumnGroup> = {
'contact info': { header: 'Contact info' },
street: { header: 'street', columnGroup: 'address' },
address: { header: 'Address' },
};
const columns: InfiniteTableComputedColumn<Person>[] = [
getComputedColumn({
field: 'id',
Expand Down Expand Up @@ -309,12 +309,12 @@ export default test.describe.parallel('buildColumnAndGroupTree', () => {
});

test('should work correctly for groups that are repeated', () => {
const columnGroups: Map<string, InfiniteTableColumnGroup> = new Map([
['contact info', { header: 'Contact info' }],
['street', { header: 'street', columnGroup: 'address' }],
['location', { header: 'location', columnGroup: 'address' }],
['address', { header: 'Address' }],
]);
const columnGroups: Record<string, InfiniteTableColumnGroup> = {
'contact info': { header: 'Contact info' },
street: { header: 'street', columnGroup: 'address' },
location: { header: 'location', columnGroup: 'address' },
address: { header: 'Address' },
};
const columns: InfiniteTableComputedColumn<Person>[] = [
getComputedColumn({
field: 'streetNo',
Expand Down Expand Up @@ -533,12 +533,12 @@ export default test.describe.parallel('buildColumnAndGroupTree', () => {
});

test('should work correctly for groups that are repeated - case 2', () => {
const columnGroups: Map<string, InfiniteTableColumnGroup> = new Map([
['contact info', { header: 'Contact info' }],
['street', { header: 'street', columnGroup: 'address' }],
['location', { header: 'location', columnGroup: 'address' }],
['address', { header: 'Address' }],
]);
const columnGroups: Record<string, InfiniteTableColumnGroup> = {
'contact info': { header: 'Contact info' },
street: { header: 'street', columnGroup: 'address' },
location: { header: 'location', columnGroup: 'address' },
address: { header: 'Address' },
};
const columns: InfiniteTableComputedColumn<Person>[] = [
getComputedColumn({
field: 'streetNo',
Expand Down Expand Up @@ -678,14 +678,14 @@ export default test.describe.parallel('buildColumnAndGroupTree', () => {
l: string;
k: string;
};
const columnGroups: Map<string, InfiniteTableColumnGroup> = new Map([
['c', { header: 'c', columnGroup: 'b' }],
['b', { header: 'b', columnGroup: 'a' }],
['a', { header: 'a', columnGroup: 'x' }],
['x', { header: 'x' }],
['h', { header: 'h', columnGroup: 'g' }],
['g', { header: 'g', columnGroup: 'x' }],
]);
const columnGroups: Record<string, InfiniteTableColumnGroup> = {
c: { header: 'c', columnGroup: 'b' },
b: { header: 'b', columnGroup: 'a' },
a: { header: 'a', columnGroup: 'x' },
x: { header: 'x' },
h: { header: 'h', columnGroup: 'g' },
g: { header: 'g', columnGroup: 'x' },
};
const columns: InfiniteTableComputedColumn<Alphabet>[] = [
getComputedColumn({
field: 'd',
Expand Down
49 changes: 23 additions & 26 deletions examples/src/pages/tests/table/misc/checkboxes.page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import * as React from 'react';

import {
InfiniteTableColumn,
InfiniteTable,
} from '@infinite-table/infinite-react';
import { DataSource } from '@infinite-table/infinite-react';
import { InfiniteTable, DataSource } from '@infinite-table/infinite-react';

interface FakeData {
id: number;
Expand Down Expand Up @@ -63,8 +59,13 @@ const initialData: FakeData[] = [
export default () => {
const [rowHeight] = React.useState(50);
const [data, setData] = React.useState(initialData);
const renderRow = (data: FakeData): React.ReactElement => {
const renderRow = (
data: Partial<FakeData> | null,
): React.ReactElement | null => {
const item = data;
if (!item) {
return null;
}
return (
<div
style={{ width: '180vw', border: '1px solid red' }}
Expand Down Expand Up @@ -108,26 +109,22 @@ export default () => {
columnDefaultWidth={150}
sortable={false}
rowHeight={rowHeight}
columns={
new Map(
[
{
field: 'id',
type: 'number',
sortable: true,
},
{
field: 'text',
},
{
field: 'checked',
render: ({ data }: { data: FakeData }) => {
return renderRow(data);
},
},
].map((c) => [c.field, c as InfiniteTableColumn<FakeData>]),
)
}
columns={{
id: {
field: 'id',
type: 'number',
defaultSortable: true,
},
text: {
field: 'text',
},
checked: {
field: 'checked',
render: ({ data }: { data: Partial<FakeData> | null }) => {
return renderRow(data);
},
},
}}
/>
</DataSource>
</React.StrictMode>
Expand Down
30 changes: 14 additions & 16 deletions examples/src/pages/tests/table/misc/datasource-events.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ const queryClient = new QueryClient({

const emptyArray: Employee[] = [];

export const columns = new Map<string, InfiniteTableColumn<Employee>>([
['id', { field: 'id' }],
[
'country',
{
field: 'country',
},
],
['city', { field: 'city' }],
['team', { field: 'team' }],
['department', { field: 'department' }],
['firstName', { field: 'firstName' }],
['lastName', { field: 'lastName' }],
['salary', { field: 'salary' }],
['age', { field: 'age' }],
]);
export const columns: Record<string, InfiniteTableColumn<Employee>> = {
id: { field: 'id' },

country: {
field: 'country',
},
city: { field: 'city' },
team: { field: 'team' },
department: { field: 'department' },
firstName: { field: 'firstName' },
lastName: { field: 'lastName' },
salary: { field: 'salary' },
age: { field: 'age' },
};

type Employee = {
id: number;
Expand Down
22 changes: 11 additions & 11 deletions examples/src/pages/tests/table/props/column-groups/columns.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { InfiniteTableColumn } from '@infinite-table/infinite-react';
import type { Person } from './rowData';

export const columns = new Map<string, InfiniteTableColumn<Person>>([
['id', { field: 'id' }], //todo when id is in address group, it should be repeated
['streetNo', { field: 'streetNo', columnGroup: 'street' }],
['city', { field: 'city', columnGroup: 'location' }],
export const columns: Record<string, InfiniteTableColumn<Person>> = {
id: { field: 'id' }, //todo when id is in address group, it should be repeated
streetNo: { field: 'streetNo', columnGroup: 'street' },
city: { field: 'city', columnGroup: 'location' },

['streetName', { field: 'streetName', columnGroup: 'street' }],
['firstName', { field: 'firstName' }],
streetName: { field: 'streetName', columnGroup: 'street' },
firstName: { field: 'firstName' },

['country', { field: 'country', columnGroup: 'location' }],
['region', { field: 'region', columnGroup: 'location' }],
country: { field: 'country', columnGroup: 'location' },
region: { field: 'region', columnGroup: 'location' },

['email', { field: 'email', columnGroup: 'contact info' }],
['phone', { field: 'phone', columnGroup: 'contact info' }],
]);
email: { field: 'email', columnGroup: 'contact info' },
phone: { field: 'phone', columnGroup: 'contact info' },
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { columns } from '../columns';
import { rowData, Person } from '../rowData';

const getColumnGroups = () => {
const columnGroups: Map<string, InfiniteTableColumnGroup> = new Map([
['contact info', { header: 'Contact info' }],
['street', { header: 'street', columnGroup: 'address' }],
['location', { header: 'location', columnGroup: 'address' }],
['address', { header: 'Address' }],
]);
const columnGroups: Record<string, InfiniteTableColumnGroup> = {
'contact info': { header: 'Contact info' },
street: { header: 'street', columnGroup: 'address' },
location: { header: 'location', columnGroup: 'address' },
address: { header: 'Address' },
};

return columnGroups;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ import { columns } from '../columns';
import { rowData, Person } from '../rowData';

const getColumnGroups = () => {
const columnGroups: Map<string, InfiniteTableColumnGroup> = new Map([
['contact info', { header: 'Contact info' }],
['street', { header: 'street', columnGroup: 'address' }],
['location', { header: 'location', columnGroup: 'address' }],
['address', { header: 'Address' }],
]);
const columnGroups: Record<string, InfiniteTableColumnGroup> = {
'contact info': { header: 'Contact info' },
street: { header: 'street', columnGroup: 'address' },
location: { header: 'location', columnGroup: 'address' },
address: { header: 'Address' },
};

return columnGroups;
};

const columnGroups = getColumnGroups();
const collapsedColumnGroups = new Map<string[], string>();
(globalThis as any).columnGroups = columnGroups;

(globalThis as any).collapsedColumnGroups = collapsedColumnGroups;

const App = () => {
const [columnGroups, setColumnGroups] = React.useState(getColumnGroups());

(globalThis as any).columnGroups = columnGroups;
(globalThis as any).setColumnGroups = setColumnGroups;
return (
<React.StrictMode>
<DataSource<Person> primaryKey="id" data={rowData}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
import { test, expect } from '@testing';

export default test.describe.parallel(
'Column groups should render correctly',
() => {
/*
*
* See ./current.png image in the current folder for how nesting should look like in this test
*
*/

test('should remove column when a new key is removed from the columns map', async ({
page,
}) => {
await page.load();
const locationText = await (
await page.locator(
'.InfiniteHeader [data-group-id="location,country,region"]',
)
).innerText();
const countryText = await (
await page.locator(
'.InfiniteHeader [data-col-index="5"][data-row-index="2"]',
)
).innerText();

expect(locationText).toEqual('location');
expect(countryText).toEqual('country');

const secondAddressNode = await page.locator(
'.InfiniteHeader [data-col-index="5"][data-row-index="0"]',
);

expect(
await secondAddressNode.evaluate((node) => node.dataset.groupId),
).toEqual('address,country,region');
expect(
await secondAddressNode.evaluate(
(node: HTMLElement) => node.offsetWidth,
),
).toEqual(480);

await page.evaluate(() => {
// update the groups via columnGroups.set method
(window as any).columnGroups.set('contact info', {
export default test.describe
.parallel('Column groups should render correctly', () => {
/*
*
* See ./current.png image in the current folder for how nesting should look like in this test
*
*/

test('should remove column when a new key is removed from the columns map', async ({
page,
}) => {
await page.load();
const locationText = await (
await page.locator(
'.InfiniteHeader [data-group-id="location,country,region"]',
)
).innerText();
const countryText = await (
await page.locator(
'.InfiniteHeader [data-col-index="5"][data-row-index="2"]',
)
).innerText();

expect(locationText).toEqual('location');
expect(countryText).toEqual('country');

const secondAddressNode = await page.locator(
'.InfiniteHeader [data-col-index="5"][data-row-index="0"]',
);

expect(
await secondAddressNode.evaluate((node) => node.dataset.groupId),
).toEqual('address,country,region');
expect(
await secondAddressNode.evaluate((node: HTMLElement) => node.offsetWidth),
).toEqual(480);

await page.evaluate(() => {
// update the groups
(window as any).setColumnGroups((columnGroups: any) => {
columnGroups = { ...columnGroups };
columnGroups['contact info'] = {
columnGroup: 'address',
header: 'Contact info',
});
};
return columnGroups;
});
});

await page.waitForTimeout(30);
await page.waitForTimeout(30);

expect(
await secondAddressNode.evaluate((node) => node.dataset.groupId),
).toEqual('address,country,region,email,phone');
expect(
await secondAddressNode.evaluate(
(node: HTMLElement) => node.offsetWidth,
),
).toEqual(960);
});
},
);
expect(
await secondAddressNode.evaluate((node) => node.dataset.groupId),
).toEqual('address,country,region,email,phone');
expect(
await secondAddressNode.evaluate((node: HTMLElement) => node.offsetWidth),
).toEqual(960);
});
});

0 comments on commit ee21656

Please sign in to comment.