-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release version patch fix some keyboard shorcut issues
- Loading branch information
1 parent
cff5a76
commit 95e3304
Showing
9 changed files
with
403 additions
and
8 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
examples/src/pages/tests/table/props/shortcuts/custom-shortcuts.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
examples/src/pages/tests/table/props/shortcuts/custom-shortcuts.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
130
examples/src/pages/tests/table/props/shortcuts/shift-enter.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
examples/src/pages/tests/table/props/shortcuts/shift-enter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.