Skip to content

Commit

Permalink
release version patch fix some keyboard shorcut issues
Browse files Browse the repository at this point in the history
  • Loading branch information
radubrehar committed May 23, 2024
1 parent cff5a76 commit 95e3304
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import * as React from 'react';

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

type Developer = {
id: number;

firstName: string;
lastName: string;

currency: string;
preferredLanguage: string;
stack: string;
canDesign: 'yes' | 'no';
salary: string;

age: number;
};

const data: Developer[] = [
{
id: 1,
firstName: 'John',
lastName: 'Bob',
age: 20,
canDesign: 'yes',
currency: 'USD',
preferredLanguage: 'JavaScript',
stack: 'frontend',
salary: '$ 1000',
},
{
id: 2,
firstName: 'Marry',
lastName: 'Bob',
age: 25,
canDesign: 'yes',
currency: 'USD',
preferredLanguage: 'JavaScript',
stack: 'frontend',
salary: '$ 11000',
},
{
id: 3,
firstName: 'Bill',
lastName: 'Bobson',
age: 30,
canDesign: 'no',
currency: 'CAD',
preferredLanguage: 'TypeScript',
stack: 'frontend',
salary: '$ 12000',
},
{
id: 4,
firstName: 'Mark',
lastName: 'Twain',
age: 31,
canDesign: 'yes',
currency: 'CAD',
preferredLanguage: 'Rust',
stack: 'backend',
salary: '£ 21000',
},
{
id: 5,
firstName: 'Matthew',
lastName: 'Hilson',
age: 29,
canDesign: 'yes',
currency: 'CAD',
preferredLanguage: 'Go',
stack: 'backend',
salary: '£ 9000',
},
];

const columns: InfiniteTablePropColumns<Developer> = {
id: {
field: 'id',
},
firstName: {
field: 'firstName',
},
age: {
field: 'age',
type: 'number',
},
salary: {
field: 'salary',
},

stack: { field: 'stack', renderMenuIcon: false },
currency: { field: 'currency' },
};

const combinations: number[] = [];
(globalThis as any).combinations = combinations;

function handler(index: number) {
return () => {
combinations[index] = combinations[index] || 0;
combinations[index]++;
};
}

export default () => {
return (
<>
<React.StrictMode>
<DataSource<Developer> data={data} primaryKey="id">
<InfiniteTable<Developer>
domProps={{
style: {
height: '100%',
},
}}
keyboardShortcuts={[
{
key: 'cmd+shift+x',
handler: handler(0),
},

{
key: 'alt+shift+arrowleft',
handler: handler(1),
},
{
key: 'Shift+PageDown',
handler: handler(2),
},
{
key: 'alt+shift+*',
handler: handler(3),
},
]}
keyboardNavigation="cell"
columnDefaultWidth={150}
columns={columns}
/>
</DataSource>
</React.StrictMode>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { test, expect, Page } from '@testing';

async function getValue(page: Page) {
return await page.evaluate(() => (globalThis as any).combinations);
}

export default test.describe.parallel('Mutations simple test', () => {
test('editing triggers onEditPersistSuccess with value from column.getValueToPersist', async ({
page,
rowModel,
}) => {
await page.waitForInfinite();
const cell = {
colId: 'age',
rowIndex: 1,
};
await rowModel.clickCell(cell);

await page.keyboard.press('Meta+Shift+Enter');
expect(await getValue(page)).toEqual([]);

await page.keyboard.press('Meta+Shift+x');
expect(await getValue(page)).toEqual([1]);

await page.keyboard.press('Alt+Shift+ArrowLeft');
expect(await getValue(page)).toEqual([1, 1, undefined, 1]);

await page.keyboard.press('Alt+Shift+ArrowRight');
expect(await getValue(page)).toEqual([1, 1, undefined, 2]);

await page.keyboard.press('Alt+Shift+x');
expect(await getValue(page)).toEqual([1, 1, undefined, 3]);

await page.keyboard.press('Meta+Shift+Escape');
expect(await getValue(page)).toEqual([1, 1, undefined, 3]);

await page.keyboard.press('Meta+Shift+Enter');
expect(await getValue(page)).toEqual([1, 1, undefined, 3]);

await page.keyboard.press('Shift+PageDown');
expect(await getValue(page)).toEqual([1, 1, 1, 3]);
});
});
130 changes: 130 additions & 0 deletions examples/src/pages/tests/table/props/shortcuts/shift-enter.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import * as React from 'react';

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

type Developer = {
id: number;

firstName: string;
lastName: string;

currency: string;
preferredLanguage: string;
stack: string;
canDesign: 'yes' | 'no';
salary: string;

age: number;
};

const data: Developer[] = [
{
id: 1,
firstName: 'John',
lastName: 'Bob',
age: 20,
canDesign: 'yes',
currency: 'USD',
preferredLanguage: 'JavaScript',
stack: 'frontend',
salary: '$ 1000',
},
{
id: 2,
firstName: 'Marry',
lastName: 'Bob',
age: 25,
canDesign: 'yes',
currency: 'USD',
preferredLanguage: 'JavaScript',
stack: 'frontend',
salary: '$ 11000',
},
{
id: 3,
firstName: 'Bill',
lastName: 'Bobson',
age: 30,
canDesign: 'no',
currency: 'CAD',
preferredLanguage: 'TypeScript',
stack: 'frontend',
salary: '$ 12000',
},
{
id: 4,
firstName: 'Mark',
lastName: 'Twain',
age: 31,
canDesign: 'yes',
currency: 'CAD',
preferredLanguage: 'Rust',
stack: 'backend',
salary: '£ 21000',
},
{
id: 5,
firstName: 'Matthew',
lastName: 'Hilson',
age: 29,
canDesign: 'yes',
currency: 'CAD',
preferredLanguage: 'Go',
stack: 'backend',
salary: '£ 9000',
},
];

const columns: InfiniteTablePropColumns<Developer> = {
id: {
field: 'id',
},
firstName: {
field: 'firstName',
},
age: {
field: 'age',
type: 'number',
},
salary: {
field: 'salary',
},

stack: { field: 'stack', renderMenuIcon: false },
currency: { field: 'currency' },
};

export default () => {
return (
<>
<React.StrictMode>
<DataSource<Developer> data={data} primaryKey="id">
<InfiniteTable<Developer>
domProps={{
style: {
height: '100%',
},
}}
keyboardShortcuts={[
{
key: 'Shift+Enter',
handler: () => {
(globalThis as any).working =
(globalThis as any).working || 0;
(globalThis as any).working++;
},
},
]}
keyboardNavigation="cell"
columnDefaultWidth={150}
columns={columns}
/>
</DataSource>
</React.StrictMode>
</>
);
};
31 changes: 31 additions & 0 deletions examples/src/pages/tests/table/props/shortcuts/shift-enter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, expect } from '@testing';

export default test.describe.parallel('Keyboard shortcuts', () => {
// this was shift+escape but for whatever reason playwright does not trigger shift+escape properly
test('should trigger shift+enter', async ({ page, rowModel }) => {
await page.waitForInfinite();
const cell = {
colId: 'age',
rowIndex: 1,
};
await rowModel.clickCell(cell);

await page.keyboard.press('Shift+Enter');
await page.waitForTimeout(50);
expect(
await page.evaluate(() => {
return (globalThis as any).working;
}),
).toEqual(1);

await page.keyboard.press('Shift+x');

await page.keyboard.press('Shift+Enter');
await page.waitForTimeout(50);
expect(
await page.evaluate(() => {
return (globalThis as any).working;
}),
).toEqual(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export async function onKeyDown<T>(
}
}

const res = await shortcut.handler(context, event);
const maybeStopNext = await shortcut.handler(context, event);

if (res && res.stopNext) {
if (maybeStopNext && maybeStopNext.stopNext) {
break;
}
}
Expand Down
Loading

0 comments on commit 95e3304

Please sign in to comment.