Repository navigation
feat(Table): Promise-based infinite loading with useTableInfiniteScroll #10570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f2b0bf4
test(Table): infinite loading and the renderState loading protocol (red)
cixzhang b4d9397
feat(Table): Promise-based infinite loading with useTableInfiniteScroll
cixzhang 7297108
refactor(Table): the Load more focus handoff uses the shared focus-le…
cixzhang 3a16845
Merge main into feat/table-infinite-loading and adopt main's shared o…
cixzhang 9732e3f
fix(Table): admit a loading plugin only with the Table-owned scroll w…
cixzhang fb6061b
fix(Table): the loading hook follows Table's loading admission
cixzhang 3297a8c
docs(Table): the infinite-loading record names the tests that exist
cixzhang 81fcf8f
Merge main into feat/table-infinite-loading
cixzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,8 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| '@astryxdesign/cli': patch | ||
| --- | ||
|
|
||
| [feature] Add Table infinite loading with `useTableInfiniteScroll({hasMore, isLoading, onLoadMore})`. One Promise request latch coordinates automatic and manual loading, failures pause automatic retry, and the persistent busy Button owns progress announcements and focus continuity. | ||
|
|
||
| @humbertovirtudes @cixzhang |
This file contains hidden or 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
This file contains hidden or 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,38 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| import {useState} from 'react'; | ||
| import type {Meta, StoryObj} from '@storybook/react-vite'; | ||
| import {Table, useTableInfiniteScroll} from '@astryxdesign/core'; | ||
| const rows = Array.from({length: 20}, (_, index) => ({ | ||
| id: String(index), | ||
| name: `Product ${index + 1}`, | ||
| })); | ||
| const meta: Meta = { | ||
| title: 'Core/Table infinite loading', | ||
| component: Table, | ||
| }; | ||
| export default meta; | ||
| function Example() { | ||
| const [data, setData] = useState(rows.slice(0, 4)); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const loading = useTableInfiniteScroll({ | ||
| hasMore: data.length < 20, | ||
| isLoading, | ||
| onLoadMore: async () => { | ||
| setIsLoading(true); | ||
| await new Promise(resolve => setTimeout(resolve, 400)); | ||
| setData(previous => rows.slice(0, previous.length + 4)); | ||
| setIsLoading(false); | ||
| }, | ||
| }); | ||
| return ( | ||
| <Table | ||
| data={data} | ||
| columns={[{key: 'name', header: 'Product'}]} | ||
| idKey="id" | ||
| plugins={{loading}} | ||
| /> | ||
| ); | ||
| } | ||
| export const ManualAndAutomaticLoading: StoryObj = { | ||
| render: () => <Example />, | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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
14 changes: 14 additions & 0 deletions
14
packages/cli/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs
This file contains hidden or 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,14 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */ | ||
| export const doc = { | ||
| type: 'block', | ||
| exampleFor: 'useTableInfiniteScroll', | ||
| name: 'useTableInfiniteScroll - Load More Products', | ||
| displayName: 'useTableInfiniteScroll - Load More Products', | ||
| description: | ||
| 'A Table appends product batches automatically or through its Load more command. The caller owns the rows, loading state and Promise-returning request. The command disappears when all products are loaded.', | ||
| isReady: true, | ||
| aspectRatio: 16 / 9, | ||
| componentsUsed: ['Table'], | ||
| }; |
33 changes: 33 additions & 0 deletions
33
packages/cli/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx
This file contains hidden or 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,33 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| 'use client'; | ||
|
|
||
| import {useState} from 'react'; | ||
| import {Table, useTableInfiniteScroll} from '@astryxdesign/core/Table'; | ||
|
|
||
| const products = Array.from({length: 20}, (_, index) => ({ | ||
| id: `product-${index}`, | ||
| name: `Product ${index + 1}`, | ||
| })); | ||
| const columns = [{key: 'name', header: 'Product'}]; | ||
|
|
||
| export default function InfiniteScrollHookUsage() { | ||
| const [data, setData] = useState(products.slice(0, 4)); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const loading = useTableInfiniteScroll({ | ||
| hasMore: data.length < products.length, | ||
| isLoading, | ||
| onLoadMore: async () => { | ||
| setIsLoading(true); | ||
| try { | ||
| const nextBatch = await Promise.resolve( | ||
| products.slice(data.length, data.length + 4), | ||
| ); | ||
| setData(previous => [...previous, ...nextBatch]); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }, | ||
| }); | ||
| return <Table data={data} columns={columns} idKey="id" plugins={{loading}} />; | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: "Pending:" is temporary status; keep the checks this row requires without it. Also,
verified_by(lines 14-24) dropsTable.perf.test.tsx, which exists, while the Performance row (line 199) still names it: keep the path or update the row.