-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: Implement infra code for infinite scroll implementation. #39225
Open
rahulbarwal
wants to merge
15
commits into
release
Choose a base branch
from
rahulbarwal/issue39082/Implement-scroll-down-triger-to-load-next-page
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4b8cfce
feat: Add infinite scroll feature flag for TableWidgetV2
rahulbarwal 6a15d81
feat: Add infinite scroll support for TableWidgetV2
rahulbarwal 982dfce
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal ee26d53
Adds react window infinite loader package to package.json.
rahulbarwal 15ff22d
feat: Add infinite scroll support for table widget
rahulbarwal bbd9140
test: Add unit tests for useInfiniteVirtualization hook
rahulbarwal 79e657c
test: Add infiniteScrollEnabled flag to TableWidgetV2 test configuration
rahulbarwal e8876e2
added binary data handling
NilanshBansal e924358
feat: Add PDF download utility for binary data handling
rahulbarwal eea44c8
refactor: Simplify PDF file download condition
rahulbarwal 13f8d2d
Merge branches 'fix/issue-39109/file-upload-binary-octet' and 'releas…
rahulbarwal 27892e6
Revert "added binary data handling"
rahulbarwal 8c8c107
Revert "refactor: Simplify PDF file download condition"
rahulbarwal af1de45
Revert "feat: Add PDF download utility for binary data handling"
rahulbarwal 0c58fcf
refactor: Remove hardcoded infinite scroll flag in StaticTable
rahulbarwal 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 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 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 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 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
59 changes: 59 additions & 0 deletions
59
app/client/src/widgets/TableWidgetV2/component/TableBody/InifiniteScrollBody/index.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,59 @@ | ||
import React, { type Ref } from "react"; | ||
import type { Row as ReactTableRowType } from "react-table"; | ||
import { type ReactElementType } from "react-window"; | ||
import InfiniteLoader from "react-window-infinite-loader"; | ||
import type SimpleBar from "simplebar-react"; | ||
import type { TableSizes } from "../../Constants"; | ||
import { useInfiniteVirtualization } from "./useInfiniteVirtualization"; | ||
import { FixedInfiniteVirtualList } from "../VirtualList"; | ||
|
||
interface InfiniteScrollBodyProps { | ||
rows: ReactTableRowType<Record<string, unknown>>[]; | ||
height: number; | ||
tableSizes: TableSizes; | ||
innerElementType?: ReactElementType; | ||
isLoading: boolean; | ||
totalRecordsCount?: number; | ||
itemCount: number; | ||
loadMoreFromEvaluations: () => void; | ||
pageSize: number; | ||
} | ||
|
||
const InfiniteScrollBody = React.forwardRef( | ||
(props: InfiniteScrollBodyProps, ref: Ref<SimpleBar>) => { | ||
const { isLoading, loadMoreFromEvaluations, pageSize, rows } = props; | ||
const { isItemLoaded, itemCount, loadMoreItems } = | ||
useInfiniteVirtualization({ | ||
rows, | ||
totalRecordsCount: rows.length, | ||
rahulbarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isLoading, | ||
loadMore: loadMoreFromEvaluations, | ||
pageSize, | ||
}); | ||
|
||
return ( | ||
<div className="simplebar-content-wrapper"> | ||
<InfiniteLoader | ||
isItemLoaded={isItemLoaded} | ||
itemCount={itemCount + 5} | ||
loadMoreItems={loadMoreItems} | ||
> | ||
{({ onItemsRendered, ref: infiniteLoaderRef }) => ( | ||
<FixedInfiniteVirtualList | ||
height={props.height} | ||
infiniteLoaderListRef={infiniteLoaderRef} | ||
innerElementType={props.innerElementType} | ||
onItemsRendered={onItemsRendered} | ||
outerRef={ref} | ||
pageSize={props.pageSize} | ||
rows={props.rows} | ||
tableSizes={props.tableSizes} | ||
/> | ||
)} | ||
</InfiniteLoader> | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export default InfiniteScrollBody; |
152 changes: 152 additions & 0 deletions
152
.../TableWidgetV2/component/TableBody/InifiniteScrollBody/useInfiniteVirtualization.test.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,152 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import { useInfiniteVirtualization } from "./useInfiniteVirtualization"; | ||
import { act } from "@testing-library/react"; | ||
import type { Row as ReactTableRowType } from "react-table"; | ||
|
||
describe("useInfiniteVirtualization", () => { | ||
const mockRows: ReactTableRowType<Record<string, unknown>>[] = [ | ||
{ | ||
id: "1", | ||
original: { id: 1, name: "Test 1" }, | ||
index: 0, | ||
cells: [], | ||
values: {}, | ||
getRowProps: jest.fn(), | ||
allCells: [], | ||
subRows: [], | ||
isExpanded: false, | ||
canExpand: false, | ||
depth: 0, | ||
toggleRowExpanded: jest.fn(), | ||
state: {}, | ||
toggleRowSelected: jest.fn(), | ||
getToggleRowExpandedProps: jest.fn(), | ||
isSelected: false, | ||
isSomeSelected: false, | ||
isGrouped: false, | ||
groupByID: "", | ||
groupByVal: "", | ||
leafRows: [], | ||
getToggleRowSelectedProps: jest.fn(), | ||
setState: jest.fn(), | ||
}, | ||
{ | ||
id: "2", | ||
original: { id: 2, name: "Test 2" }, | ||
index: 1, | ||
cells: [], | ||
values: {}, | ||
getRowProps: jest.fn(), | ||
allCells: [], | ||
subRows: [], | ||
isExpanded: false, | ||
canExpand: false, | ||
depth: 0, | ||
toggleRowExpanded: jest.fn(), | ||
state: {}, | ||
toggleRowSelected: jest.fn(), | ||
getToggleRowExpandedProps: jest.fn(), | ||
isSelected: false, | ||
isSomeSelected: false, | ||
isGrouped: false, | ||
groupByID: "", | ||
groupByVal: "", | ||
leafRows: [], | ||
getToggleRowSelectedProps: jest.fn(), | ||
setState: jest.fn(), | ||
}, | ||
]; | ||
|
||
const defaultProps = { | ||
rows: mockRows, | ||
isLoading: false, | ||
loadMore: jest.fn(), | ||
pageSize: 10, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should return correct itemCount when totalRecordsCount is provided", () => { | ||
const totalRecordsCount = 100; | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization({ | ||
...defaultProps, | ||
totalRecordsCount, | ||
}), | ||
); | ||
|
||
expect(result.current.itemCount).toBe(totalRecordsCount); | ||
}); | ||
|
||
it("should return rows length as itemCount when totalRecordsCount is not provided", () => { | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization(defaultProps), | ||
); | ||
|
||
expect(result.current.itemCount).toBe(defaultProps.rows.length); | ||
}); | ||
|
||
it("should call loadMore when loadMoreItems is called and not loading", async () => { | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization(defaultProps), | ||
); | ||
|
||
await act(async () => { | ||
await result.current.loadMoreItems(0, 10); | ||
}); | ||
|
||
expect(defaultProps.loadMore).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("should not call loadMore when loadMoreItems is called and is loading", async () => { | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization({ | ||
...defaultProps, | ||
isLoading: true, | ||
}), | ||
); | ||
|
||
await act(async () => { | ||
await result.current.loadMoreItems(0, 10); | ||
}); | ||
|
||
expect(defaultProps.loadMore).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should return correct isItemLoaded state for different scenarios", () => { | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization(defaultProps), | ||
); | ||
|
||
// Index within rows length and not loading | ||
expect(result.current.isItemLoaded(1)).toBe(true); | ||
|
||
// Index beyond rows length and not loading | ||
expect(result.current.isItemLoaded(5)).toBe(false); | ||
}); | ||
|
||
it("should return false for isItemLoaded when loading", () => { | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization({ | ||
...defaultProps, | ||
isLoading: true, | ||
}), | ||
); | ||
|
||
// Even for index within rows length, should return false when loading | ||
expect(result.current.isItemLoaded(1)).toBe(false); | ||
}); | ||
|
||
it("should return zero itemCount when there are no records", () => { | ||
const { result } = renderHook(() => | ||
useInfiniteVirtualization({ | ||
...defaultProps, | ||
rows: [], | ||
}), | ||
); | ||
|
||
expect(result.current.itemCount).toBe(0); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...dgets/TableWidgetV2/component/TableBody/InifiniteScrollBody/useInfiniteVirtualization.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,37 @@ | ||
import { useCallback } from "react"; | ||
import type { Row as ReactTableRowType } from "react-table"; | ||
|
||
interface InfiniteVirtualizationProps { | ||
rows: ReactTableRowType<Record<string, unknown>>[]; | ||
totalRecordsCount?: number; | ||
isLoading: boolean; | ||
loadMore: () => void; | ||
pageSize: number; | ||
} | ||
|
||
interface UseInfiniteVirtualizationReturn { | ||
itemCount: number; | ||
loadMoreItems: (startIndex: number, stopIndex: number) => void; | ||
isItemLoaded: (index: number) => boolean; | ||
} | ||
|
||
export const useInfiniteVirtualization = ({ | ||
isLoading, | ||
loadMore, | ||
rows, | ||
totalRecordsCount, | ||
}: InfiniteVirtualizationProps): UseInfiniteVirtualizationReturn => { | ||
const loadMoreItems = useCallback(async () => { | ||
if (!isLoading) { | ||
loadMore(); | ||
} | ||
|
||
return Promise.resolve(); | ||
}, [isLoading, loadMore]); | ||
rahulbarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return { | ||
itemCount: totalRecordsCount ?? rows.length, | ||
loadMoreItems, | ||
isItemLoaded: (index) => !isLoading && index < rows.length, | ||
}; | ||
}; |
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.
🛠️ Refactor suggestion
Add error handling for binary data processing.
The binary data processing should include error handling for malformed data.
📝 Committable suggestion