Skip to content

Commit

Permalink
Tree grid (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
radubrehar authored Oct 28, 2024
1 parent 2f955c9 commit 011aae7
Show file tree
Hide file tree
Showing 77 changed files with 5,741 additions and 276 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Debug PW tests",
"cwd": "${workspaceFolder}/examples",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "play:test"]
"runtimeArgs": ["run-script", "test:watch"]
}
]
}
2 changes: 1 addition & 1 deletion examples/src/pages/tests/datasource/loadDataFn.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const data = sinon.spy(() => {
export default () => {
const { state } = useDataSourceInternal({
data,
primaryKey: 'id',
primaryKey: (d: any) => d.id,
});
(globalThis as any).dataSourceState = state;
return <div>hello</div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default test.describe.parallel('DataSource', () => {
data: persons[0],
id: persons[0].id,
indexInAll: 0,

rowSelected: false,
rowDisabled: false,
isTreeNode: false,
isGroupRow: false,
selfLoaded: true,
dataSourceHasGrouping: false,
Expand All @@ -31,6 +33,7 @@ export default test.describe.parallel('DataSource', () => {
indexInAll: 1,
rowSelected: false,
rowDisabled: false,
isTreeNode: false,
isGroupRow: false,
selfLoaded: true,
dataSourceHasGrouping: false,
Expand Down Expand Up @@ -59,6 +62,7 @@ export default test.describe.parallel('DataSource', () => {
rowDisabled: false,
// indexInGroup: 0,
isGroupRow: false,
isTreeNode: false,
selfLoaded: true,
},
{
Expand All @@ -70,6 +74,7 @@ export default test.describe.parallel('DataSource', () => {
// indexInGroup: 1,
id: persons[1].id,
isGroupRow: false,
isTreeNode: false,
selfLoaded: true,
},
]);
Expand Down
19 changes: 15 additions & 4 deletions examples/src/pages/tests/horizontal-layout/example.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const columns: InfiniteTablePropColumns<Developer> = {
// columnGroup: 'colgroup',
// },
// currency: { field: 'currency', style, columnGroup: 'colgroup' },
// country: { field: 'country', style, columnGroup: 'colgroup' },
country: { field: 'country' },
};

// const render: InfiniteTableColumn<Developer>['render'] = ({
Expand Down Expand Up @@ -296,7 +296,7 @@ export default () => {
const [cols, setCols] = React.useState(columns);
const [wrapRowsHorizontally, setWrapRowsHorizontally] = React.useState(true);
return (
<>
<div className="bg-black flex flex-col gap-2">
{Object.keys(columns).map((colId) => {
return (
<label key={colId}>
Expand All @@ -321,13 +321,15 @@ export default () => {
);
})}
<button
className="bg-white text-black"
onClick={() => {
setWrapRowsHorizontally((x) => !x);
}}
>
toggle
</button>
<button
className="bg-white text-black"
onClick={() => {
dataSourceApi?.updateData({
id: 16,
Expand Down Expand Up @@ -373,9 +375,18 @@ export default () => {
// },
// }}
wrapRowsHorizontally={wrapRowsHorizontally}
repeatWrappedGroupRows={(rowInfo) => {
if (!rowInfo.isGroupRow) {
return false;
}
// return true;
const res = rowInfo.groupNesting === 2;

return res;
}}
columnDefaultWidth={200}
columnDefaultEditable
defaultActiveRowIndex={168}
// defaultActiveRowIndex={168}
keyboardNavigation="row"
domProps={{
style: {
Expand All @@ -386,6 +397,6 @@ export default () => {
/>
</DataSource>
</React.StrictMode>
</>
</div>
);
};
82 changes: 82 additions & 0 deletions examples/src/pages/tests/multisort/nestedMultisort.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { test, expect } from '@playwright/test';
import { multisortNested } from '@src/utils/multisort';

const options = {
nodesKey: 'children',
isLeafNode: (item: any) => !item.children,
getNodeChildren: (item: any) => item.children,
toKey: (item: any) => item.id,
};
export default test.describe.parallel('Nested multisort', () => {
test('should sort empty array', () => {
expect(multisortNested([], [], options)).toEqual([]);
});

test('should not sort when no sort info provided', () => {
expect(multisortNested([], [3, 1, 2], options)).toEqual([3, 1, 2]);
});

test('should sort well', () => {
const data = [
{
id: 1,
size: 130,
name: 'Documents',
children: [
{
id: 2,
size: 110,
name: 'Work',
},
{
id: 3,
size: 20,
name: 'Vacation',
},
],
},
{
id: 4,
size: 100,
name: 'Downloads',
},
];

expect(
multisortNested(
[
{
dir: 1,
type: 'number',
field: 'size',
},
],
data,
options,
),
).toEqual([
{
id: 4,
size: 100,
name: 'Downloads',
},
{
id: 1,
size: 130,
name: 'Documents',
children: [
{
id: 3,
size: 20,
name: 'Vacation',
},
{
id: 2,
size: 110,
name: 'Work',
},
],
},
]);
});
});
164 changes: 164 additions & 0 deletions examples/src/pages/tests/table/props/data/basic-add-data.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import * as React from 'react';

import {
InfiniteTable,
DataSource,
InfiniteTableColumn,
DataSourceApi,
} from '@infinite-table/infinite-react';
import { CarSale } from '@examples/datasets/CarSale';
import { useState } from 'react';

const carsales: CarSale[] = [
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'RDX 2WD',
year: 2010,
sales: 15,
color: 'red',
id: 0,
},
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'RDX 4WD',
year: 2007,
sales: 1,
color: 'red',
id: 1,
},
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'RDX 4WD',
year: 2008,
sales: 2,
color: 'magenta',
id: 2,
},
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'RDX 4WD',
year: 2009,
sales: 136,
color: 'blue',
id: 3,
},
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'RDX 4WD',
year: 2010,
color: 'blue',
sales: 30,
id: 4,
},
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'TSX',
year: 2009,
sales: 14,
color: 'yellow',
id: 5,
},
{
category: '1 - Category 1 Truck',
make: 'Acura',
model: 'TSX',
year: 2010,
sales: 14,
color: 'red',
id: 6,
},
{
category: '1 - Category 1 Truck',
make: 'Audi',
model: 'A3',
year: 2009,
sales: 2,
color: 'magenta',
id: 7,
},
];

(globalThis as any).carsales = carsales;

const columns: Record<string, InfiniteTableColumn<CarSale>> = {
id: { field: 'id', defaultWidth: 80 },
make: { field: 'make' },
model: { field: 'model' },

category: {
field: 'category',
},
count: {
field: 'sales',
},
year: {
field: 'year',
type: 'number',
},
};

export default function DataTestPage() {
const [dataSourceApi, setDataSourceApi] =
useState<DataSourceApi<CarSale> | null>(null);
return (
<React.StrictMode>
<>
<button
onClick={() => {
dataSourceApi?.insertDataArray(
[
{
id: 9,
make: 'test',
model: 'test',
category: 'test',
year: 2024,
sales: 1,
color: 'test',
},
{
id: 10,
make: 'test',
model: 'test',
category: 'test',
year: 2024,
sales: 1,
color: 'test',
},
],
{
position: 'after',
primaryKey: 0,
},
);
}}
>
Insert row after ID=1
</button>
<DataSource<CarSale>
data={carsales}
primaryKey="id"
onReady={setDataSourceApi}
>
<InfiniteTable<CarSale>
domProps={{
style: {
margin: '5px',
height: 900,
border: '1px solid gray',
position: 'relative',
},
}}
columns={columns}
/>
</DataSource>
</>
</React.StrictMode>
);
}
Loading

0 comments on commit 011aae7

Please sign in to comment.