-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incrementally load node diff in UI view (#5676)
- Loading branch information
1 parent
d11b870
commit 1c4a0f9
Showing
5 changed files
with
145 additions
and
60 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getDiffTreeFromApi } from "@/entities/diff/api/get-diff-tree-from-api"; | ||
import { DiffTree, DiffTreeQueryFilters } from "@/shared/api/graphql/generated/graphql"; | ||
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query"; | ||
|
||
export const DIFF_TREE_PER_PAGE = 30; | ||
|
||
export type GetDiffTreeParams = { | ||
branchName: string; | ||
filters?: DiffTreeQueryFilters; | ||
limit?: number; | ||
offset: number; | ||
}; | ||
|
||
export type GetDiffTree = (params: GetDiffTreeParams) => Promise<DiffTree>; | ||
|
||
export const getDiffTree: GetDiffTree = async ({ | ||
branchName, | ||
limit = DIFF_TREE_PER_PAGE, | ||
offset, | ||
filters, | ||
}) => { | ||
const { data } = await getDiffTreeFromApi({ branchName, limit, offset, filters }); | ||
|
||
return data.DiffTree; | ||
}; | ||
|
||
export type GetDiffTreeInfiniteQueryOptionsParams = { | ||
branchName: string; | ||
filters?: DiffTreeQueryFilters; | ||
}; | ||
|
||
export const getDiffTreeInfiniteQueryOptions = ({ | ||
branchName, | ||
filters, | ||
}: GetDiffTreeInfiniteQueryOptionsParams) => { | ||
return infiniteQueryOptions({ | ||
queryKey: ["diff-tree", branchName, filters], | ||
queryFn: ({ pageParam }) => getDiffTree({ branchName, filters, offset: pageParam }), | ||
initialPageParam: 0, | ||
getNextPageParam: (lastPage, _, lastPageParam) => { | ||
if (lastPage === null || (lastPage?.nodes && lastPage.nodes.length < DIFF_TREE_PER_PAGE)) { | ||
return undefined; | ||
} | ||
return lastPageParam + DIFF_TREE_PER_PAGE; | ||
}, | ||
}); | ||
}; | ||
|
||
export const useDiffTreeInfiniteQuery = (params: GetDiffTreeInfiniteQueryOptionsParams) => { | ||
return useInfiniteQuery(getDiffTreeInfiniteQueryOptions(params)); | ||
}; |
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