diff --git a/graphql-server/schema.gql b/graphql-server/schema.gql index b7e37a06..e2c4458c 100644 --- a/graphql-server/schema.gql +++ b/graphql-server/schema.gql @@ -68,7 +68,8 @@ type Branch { """ scalar Timestamp -type BranchNamesList { +type BranchList { + nextOffset: Int list: [Branch!]! } @@ -282,7 +283,8 @@ type TagList { type Query { branch(databaseName: String!, branchName: String!): Branch branchOrDefault(databaseName: String!, branchName: String): Branch - branches(databaseName: String!, sortBy: SortBranchesBy): BranchNamesList! + branches(offset: Int, databaseName: String!, sortBy: SortBranchesBy): BranchList! + allBranches(offset: Int, databaseName: String!, sortBy: SortBranchesBy): [Branch!]! defaultBranch(databaseName: String!): Branch commits(offset: Int, databaseName: String!, refName: String, afterCommitId: String, twoDot: Boolean, excludingCommitsFromRefName: String): CommitList! currentDatabase: String diff --git a/graphql-server/src/branches/branch.model.ts b/graphql-server/src/branches/branch.model.ts index 01701da2..b1610e57 100644 --- a/graphql-server/src/branches/branch.model.ts +++ b/graphql-server/src/branches/branch.model.ts @@ -2,6 +2,7 @@ import { Field, GraphQLTimestamp, ID, ObjectType } from "@nestjs/graphql"; import { RawRow } from "../queryFactory/types"; import * as table from "../tables/table.model"; import { convertToUTCDate } from "../utils"; +import { ListOffsetRes } from "../utils/commonTypes"; @ObjectType() export class Branch { @@ -31,7 +32,7 @@ export class Branch { } @ObjectType() -export class BranchNamesList { +export class BranchList extends ListOffsetRes { @Field(_type => [Branch]) list: Branch[]; } diff --git a/graphql-server/src/branches/branch.resolver.ts b/graphql-server/src/branches/branch.resolver.ts index 3e67ec55..ca0abe22 100644 --- a/graphql-server/src/branches/branch.resolver.ts +++ b/graphql-server/src/branches/branch.resolver.ts @@ -9,11 +9,13 @@ import { Resolver, } from "@nestjs/graphql"; import { ConnectionResolver } from "../connections/connection.resolver"; +import { RawRow } from "../queryFactory/types"; import { Table } from "../tables/table.model"; import { TableResolver } from "../tables/table.resolver"; -import { BranchArgs, DBArgs } from "../utils/commonTypes"; +import { ROW_LIMIT, getNextOffset } from "../utils"; +import { BranchArgs, DBArgs, DBArgsWithOffset } from "../utils/commonTypes"; import { SortBranchesBy } from "./branch.enum"; -import { Branch, BranchNamesList, fromDoltBranchesRow } from "./branch.model"; +import { Branch, BranchList, fromDoltBranchesRow } from "./branch.model"; @ArgsType() export class GetBranchOrDefaultArgs extends DBArgs { @@ -43,7 +45,7 @@ export class CreateBranchArgs extends DBArgs { } @ArgsType() -class ListBranchesArgs extends DBArgs { +class ListBranchesArgs extends DBArgsWithOffset { @Field(_type => SortBranchesBy, { nullable: true }) sortBy?: SortBranchesBy; } @@ -75,13 +77,18 @@ export class BranchResolver { return branch; } - @Query(_returns => BranchNamesList) - async branches(@Args() args: ListBranchesArgs): Promise { + @Query(_returns => BranchList) + async branches(@Args() args: ListBranchesArgs): Promise { const conn = this.conn.connection(); - const res = await conn.getBranches(args); - return { - list: res.map(b => fromDoltBranchesRow(args.databaseName, b)), - }; + const res = await conn.getBranches({ ...args, offset: args.offset ?? 0 }); + return fromBranchListRes(res, args); + } + + @Query(_returns => [Branch]) + async allBranches(@Args() args: ListBranchesArgs): Promise { + const conn = this.conn.connection(); + const res = await conn.getAllBranches(args); + return res.map(b => fromDoltBranchesRow(args.databaseName, b)); } @Query(_returns => Branch, { nullable: true }) @@ -162,3 +169,15 @@ export function getDefaultBranchFromBranchesList( return options[0]; } + +function fromBranchListRes( + branches: RawRow[], + args: ListBranchesArgs, +): BranchList { + return { + list: branches + .slice(0, ROW_LIMIT) + .map(b => fromDoltBranchesRow(args.databaseName, b)), + nextOffset: getNextOffset(branches.length, args.offset ?? 0), + }; +} diff --git a/graphql-server/src/queryFactory/dolt/index.ts b/graphql-server/src/queryFactory/dolt/index.ts index e9fc20db..e7c38ed2 100644 --- a/graphql-server/src/queryFactory/dolt/index.ts +++ b/graphql-server/src/queryFactory/dolt/index.ts @@ -151,16 +151,35 @@ export class DoltQueryFactory ); } - async getBranches(args: t.DBArgs & { sortBy?: SortBranchesBy }): t.PR { + async getBranches( + args: t.DBArgs & { sortBy?: SortBranchesBy; offset: number }, + ): t.PR { return this.queryForBuilder(async em => { - let sel = em.createQueryBuilder().select("*").from("dolt_branches", ""); - if (args.sortBy) { - sel = sel.addOrderBy(qh.getOrderByColForBranches(args.sortBy), "DESC"); - } - return sel.getRawMany(); + const [orderBy, dir] = qh.getOrderByColForBranches(args.sortBy); + return em + .createQueryBuilder() + .select("*") + .from("dolt_branches", "") + .addOrderBy(orderBy, dir) + .limit(ROW_LIMIT + 1) + .offset(args.offset) + .getRawMany(); }, args.databaseName); } + async getAllBranches(args: t.DBArgs): t.PR { + return this.queryForBuilder( + async em => + em + .createQueryBuilder() + .select("*") + .from("dolt_branches", "") + .limit(1000) + .getRawMany(), + args.databaseName, + ); + } + async createNewBranch(args: t.BranchArgs & { fromRefName: string }): t.PR { return this.query( qh.callNewBranch, diff --git a/graphql-server/src/queryFactory/dolt/queries.ts b/graphql-server/src/queryFactory/dolt/queries.ts index e57e9420..a9b1167b 100644 --- a/graphql-server/src/queryFactory/dolt/queries.ts +++ b/graphql-server/src/queryFactory/dolt/queries.ts @@ -27,12 +27,14 @@ export const callNewBranch = `CALL DOLT_BRANCH(?, ?)`; export const callDeleteBranch = `CALL DOLT_BRANCH("-D", ?)`; -export function getOrderByColForBranches(sortBy?: SortBranchesBy): string { +export function getOrderByColForBranches( + sortBy?: SortBranchesBy, +): [string, "ASC" | "DESC"] { switch (sortBy) { case SortBranchesBy.LastUpdated: - return "latest_commit_date"; + return ["latest_commit_date", "DESC"]; default: - return ""; + return ["name", "ASC"]; } } diff --git a/graphql-server/src/queryFactory/index.ts b/graphql-server/src/queryFactory/index.ts index 6439f482..5c003d31 100644 --- a/graphql-server/src/queryFactory/index.ts +++ b/graphql-server/src/queryFactory/index.ts @@ -81,7 +81,11 @@ export declare class QueryFactory { getBranch(args: t.BranchArgs): t.UPR; - getBranches(args: t.DBArgs & { sortBy?: SortBranchesBy }): t.PR; + getBranches( + args: t.DBArgs & { sortBy?: SortBranchesBy; offset: number }, + ): t.PR; + + getAllBranches(args: t.DBArgs): t.PR; createNewBranch(args: t.BranchArgs & { fromRefName: string }): t.PR; diff --git a/graphql-server/src/queryFactory/mysql/index.ts b/graphql-server/src/queryFactory/mysql/index.ts index 9d563d03..d8055090 100644 --- a/graphql-server/src/queryFactory/mysql/index.ts +++ b/graphql-server/src/queryFactory/mysql/index.ts @@ -196,7 +196,11 @@ export class MySQLQueryFactory ]; } - async getBranches(args: t.DBArgs): t.PR { + async getBranches(args: t.DBArgs & { offset: number }): t.PR { + return this.getAllBranches(args); + } + + async getAllBranches(args: t.DBArgs): t.PR { const branch = await this.getBranch({ ...args, branchName: "main" }); return branch ?? []; } diff --git a/web/components/CustomFormSelect/BranchSelector/BranchSelectorQuery.tsx b/web/components/CustomFormSelect/BranchSelector/BranchSelectorQuery.tsx index 63b074a1..5d015390 100644 --- a/web/components/CustomFormSelect/BranchSelector/BranchSelectorQuery.tsx +++ b/web/components/CustomFormSelect/BranchSelector/BranchSelectorQuery.tsx @@ -34,7 +34,7 @@ export default function BranchSelectorQuery(props: BranchSelectorForRepoProps) { )} diff --git a/web/components/CustomFormSelect/BranchSelector/BranchSelectorWithTableQuery.tsx b/web/components/CustomFormSelect/BranchSelector/BranchSelectorWithTableQuery.tsx index f3be025e..510a36f8 100644 --- a/web/components/CustomFormSelect/BranchSelector/BranchSelectorWithTableQuery.tsx +++ b/web/components/CustomFormSelect/BranchSelector/BranchSelectorWithTableQuery.tsx @@ -50,7 +50,7 @@ export default function BranchSelectorWithTableQuery( )} diff --git a/web/components/CustomFormSelect/BranchSelector/index.tsx b/web/components/CustomFormSelect/BranchSelector/index.tsx index 3d83f792..c26c31ea 100644 --- a/web/components/CustomFormSelect/BranchSelector/index.tsx +++ b/web/components/CustomFormSelect/BranchSelector/index.tsx @@ -36,7 +36,7 @@ export default function CustomBranchSelector(props: CustomProps): JSX.Element { render={data => ( )} diff --git a/web/components/CustomFormSelect/mocks.ts b/web/components/CustomFormSelect/mocks.ts index 0d0d5898..839316df 100644 --- a/web/components/CustomFormSelect/mocks.ts +++ b/web/components/CustomFormSelect/mocks.ts @@ -78,10 +78,7 @@ export const branchSelectorMock = ( }, result: { data: { - branches: { - __typename: "BranchNamesList", - list: empty ? [] : [testBranch(params), mainBranch(params)], - }, + allBranches: empty ? [] : [testBranch(params), mainBranch(params)], }, }, }; @@ -95,10 +92,7 @@ export const noBranchMock = (params: DatabaseParams): MockedResponse => { }, result: { data: { - branches: { - __typename: "BranchNamesList", - list: [], - }, + allBranches: [], }, }, }; @@ -112,10 +106,7 @@ export const oneBranchMock = (params: DatabaseParams): MockedResponse => { }, result: { data: { - branches: { - __typename: "BranchNamesList", - list: [mainBranch(params)], - }, + allBranches: [mainBranch(params)], }, }, }; diff --git a/web/components/CustomFormSelect/queries.ts b/web/components/CustomFormSelect/queries.ts index ceab7be2..319886ca 100644 --- a/web/components/CustomFormSelect/queries.ts +++ b/web/components/CustomFormSelect/queries.ts @@ -6,10 +6,8 @@ export const BRANCH_SELECTOR_QUERY = gql` databaseName } query BranchesForSelector($databaseName: String!) { - branches(databaseName: $databaseName) { - list { - ...BranchForBranchSelector - } + allBranches(databaseName: $databaseName) { + ...BranchForBranchSelector } } `; diff --git a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/BranchList.tsx b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/BranchList.tsx index 80a3c84c..430e0a44 100644 --- a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/BranchList.tsx +++ b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/BranchList.tsx @@ -1,32 +1,46 @@ import { BranchFragment } from "@gen/graphql-types"; +import InfiniteScroll from "react-infinite-scroller"; import BranchRow from "./BranchRow"; import css from "./index.module.css"; type Props = { branches: BranchFragment[]; onDeleteClicked: (b: BranchFragment) => void; + loadMore: () => Promise; + hasMore: boolean; }; export default function BranchList(props: Props): JSX.Element { return ( - - - - - - - - - - {props.branches.map(b => ( - props.onDeleteClicked(b)} - key={b._id} - branch={b} - /> - ))} - -
Branch nameLast updated byLast updated
+ Loading branches ...} + useWindow={false} + initialLoad={false} + getScrollParent={() => document.getElementById("main-content")} + > + + + + + + + + + + {props.branches.map(b => ( + props.onDeleteClicked(b)} + key={b._id} + branch={b} + /> + ))} + +
Branch nameLast updated byLast updated
+
); } diff --git a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.tsx b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.tsx index 711dc0ef..e428335b 100644 --- a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.tsx +++ b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.tsx @@ -27,6 +27,8 @@ type Props = { type InnerProps = { branches: BranchFragment[]; + loadMore: () => Promise; + hasMore: boolean; sortBranches: (sortBy?: SortBranchesBy) => Promise; sortBy?: SortBranchesBy; } & Props; @@ -119,6 +121,8 @@ export default function BranchesPage({ params }: Props): JSX.Element { diff --git a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/queries.ts b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/queries.ts index a7e29108..b3baa950 100644 --- a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/queries.ts +++ b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/queries.ts @@ -8,11 +8,16 @@ export const BRANCHES_FOR_BRANCHES_PAGE_QUERY = gql` lastUpdated lastCommitter } - query BranchList($databaseName: String!, $sortBy: SortBranchesBy) { - branches(databaseName: $databaseName, sortBy: $sortBy) { + query BranchList( + $databaseName: String! + $sortBy: SortBranchesBy + $offset: Int + ) { + branches(databaseName: $databaseName, sortBy: $sortBy, offset: $offset) { list { ...Branch } + nextOffset } } `; diff --git a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/useBranchList.ts b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/useBranchList.ts index f9726abc..81822781 100644 --- a/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/useBranchList.ts +++ b/web/components/pageComponents/DatabasePage/ForBranches/BranchesPage/useBranchList.ts @@ -7,6 +7,7 @@ import { useBranchListQuery, } from "@gen/graphql-types"; import useApolloError from "@hooks/useApolloError"; +import Maybe from "@lib/Maybe"; import { handleCaughtApolloError } from "@lib/errors/helpers"; import { ApolloErrorType } from "@lib/errors/types"; import { DatabaseParams } from "@lib/params"; @@ -14,6 +15,8 @@ import { useEffect, useState } from "react"; type ReturnType = { branches?: BranchFragment[]; + loadMore: () => Promise; + hasMore: boolean; loading: boolean; error?: ApolloErrorType; refetch: () => Promise; @@ -28,6 +31,8 @@ export function useBranchList(params: DatabaseParams): ReturnType { }); const [branches, setBranches] = useState(data?.branches.list); const [sortBy, setSortBy] = useState(undefined); + const [offset, setOffset] = useState(data?.branches.nextOffset); + const [lastOffset, setLastOffset] = useState>(undefined); const [err, setErr] = useApolloError(res.error); const refetch = async () => { @@ -41,7 +46,30 @@ export function useBranchList(params: DatabaseParams): ReturnType { useEffect(() => { setBranches(data?.branches.list); - }, [data, setBranches]); + setOffset(data?.branches.nextOffset); + }, [data, setBranches, setOffset]); + + const loadMore = async () => { + if (!offset) { + return; + } + setLastOffset(offset); + try { + const result = await res.client.query< + BranchListQuery, + BranchListQueryVariables + >({ + query: BranchListDocument, + variables: { ...params, offset, sortBy }, + }); + const newBranches = result.data.branches.list; + const newOffset = result.data.branches.nextOffset; + setBranches((branches ?? []).concat(newBranches)); + setOffset(newOffset); + } catch (e) { + handleCaughtApolloError(e, setErr); + } + }; const sortBranches = async (sb?: SortBranchesBy) => { setSortBy(sb); @@ -54,12 +82,18 @@ export function useBranchList(params: DatabaseParams): ReturnType { variables: { ...params, sortBy: sb }, }); const newBranches = result.data.branches.list; + const newOffset = result.data.branches.nextOffset; setBranches(newBranches); + setOffset(newOffset); + setLastOffset(undefined); } catch (e) { handleCaughtApolloError(e, setErr); } }; + const hasMore = + offset !== undefined && offset !== null && offset !== lastOffset; + return { ...res, error: err, @@ -67,5 +101,7 @@ export function useBranchList(params: DatabaseParams): ReturnType { refetch, sortBranches, sortBy, + loadMore, + hasMore, }; } diff --git a/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/BranchSelect.tsx b/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/BranchSelect.tsx index 4d20133c..3c327710 100644 --- a/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/BranchSelect.tsx +++ b/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/BranchSelect.tsx @@ -1,9 +1,9 @@ import FormSelect from "@components/FormSelect"; -import { BranchFragment } from "@gen/graphql-types"; +import { BranchForBranchSelectorFragment } from "@gen/graphql-types"; import css from "./index.module.css"; type Props = { - branchList: BranchFragment[]; + branchList: BranchForBranchSelectorFragment[]; currentBranchName: string; onChange: (b: string) => void; label: string; diff --git a/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/index.tsx b/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/index.tsx index c6926cfa..d9f3f229 100644 --- a/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/index.tsx +++ b/web/components/pageComponents/DatabasePage/ForPulls/BranchSelectForm/index.tsx @@ -1,5 +1,8 @@ import QueryHandler from "@components/util/QueryHandler"; -import { BranchFragment, useBranchListQuery } from "@gen/graphql-types"; +import { + BranchForBranchSelectorFragment, + useBranchesForSelectorQuery, +} from "@gen/graphql-types"; import { PullParams } from "@lib/params"; import { pulls } from "@lib/urls"; import { BsArrowLeft } from "@react-icons/all-files/bs/BsArrowLeft"; @@ -12,7 +15,7 @@ type Props = { }; type InnerProps = Props & { - branches: BranchFragment[]; + branches: BranchForBranchSelectorFragment[]; }; function Inner(props: InnerProps) { @@ -58,12 +61,12 @@ function Inner(props: InnerProps) { } export default function BranchSelectForm(props: Props) { - const branchRes = useBranchListQuery({ variables: props.params }); + const branchRes = useBranchesForSelectorQuery({ variables: props.params }); return ( } + render={data => } /> ); } diff --git a/web/gen/graphql-types.tsx b/web/gen/graphql-types.tsx index 6944b4e6..7099c297 100644 --- a/web/gen/graphql-types.tsx +++ b/web/gen/graphql-types.tsx @@ -41,9 +41,10 @@ export type BranchTableNamesArgs = { filterSystemTables?: InputMaybe; }; -export type BranchNamesList = { - __typename?: 'BranchNamesList'; +export type BranchList = { + __typename?: 'BranchList'; list: Array; + nextOffset?: Maybe; }; export type ColConstraint = { @@ -340,9 +341,10 @@ export type PullWithDetails = { export type Query = { __typename?: 'Query'; + allBranches: Array; branch?: Maybe; branchOrDefault?: Maybe; - branches: BranchNamesList; + branches: BranchList; commits: CommitList; currentDatabase?: Maybe; databases: Array; @@ -372,6 +374,13 @@ export type Query = { }; +export type QueryAllBranchesArgs = { + databaseName: Scalars['String']['input']; + offset?: InputMaybe; + sortBy?: InputMaybe; +}; + + export type QueryBranchArgs = { branchName: Scalars['String']['input']; databaseName: Scalars['String']['input']; @@ -386,6 +395,7 @@ export type QueryBranchOrDefaultArgs = { export type QueryBranchesArgs = { databaseName: Scalars['String']['input']; + offset?: InputMaybe; sortBy?: InputMaybe; }; @@ -687,7 +697,7 @@ export type BranchesForSelectorQueryVariables = Exact<{ }>; -export type BranchesForSelectorQuery = { __typename?: 'Query', branches: { __typename?: 'BranchNamesList', list: Array<{ __typename?: 'Branch', branchName: string, databaseName: string }> } }; +export type BranchesForSelectorQuery = { __typename?: 'Query', allBranches: Array<{ __typename?: 'Branch', branchName: string, databaseName: string }> }; export type TagForListFragment = { __typename?: 'Tag', _id: string, tagName: string, message: string, taggedAt: any, commitId: string, tagger: { __typename?: 'DoltWriter', _id: string, username?: string | null, displayName: string, emailAddress: string } }; @@ -913,10 +923,11 @@ export type BranchFragment = { __typename?: 'Branch', _id: string, branchName: s export type BranchListQueryVariables = Exact<{ databaseName: Scalars['String']['input']; sortBy?: InputMaybe; + offset?: InputMaybe; }>; -export type BranchListQuery = { __typename?: 'Query', branches: { __typename?: 'BranchNamesList', list: Array<{ __typename?: 'Branch', _id: string, branchName: string, databaseName: string, lastUpdated: any, lastCommitter: string }> } }; +export type BranchListQuery = { __typename?: 'Query', branches: { __typename?: 'BranchList', nextOffset?: number | null, list: Array<{ __typename?: 'Branch', _id: string, branchName: string, databaseName: string, lastUpdated: any, lastCommitter: string }> } }; export type DeleteBranchMutationVariables = Exact<{ branchName: Scalars['String']['input']; @@ -1134,10 +1145,11 @@ export type BranchForCommitGraphFragment = { __typename?: 'Branch', branchName: export type BranchListForCommitGraphQueryVariables = Exact<{ databaseName: Scalars['String']['input']; + offset?: InputMaybe; }>; -export type BranchListForCommitGraphQuery = { __typename?: 'Query', branches: { __typename?: 'BranchNamesList', list: Array<{ __typename?: 'Branch', branchName: string, head?: string | null }> } }; +export type BranchListForCommitGraphQuery = { __typename?: 'Query', branches: { __typename?: 'BranchList', nextOffset?: number | null, list: Array<{ __typename?: 'Branch', branchName: string, head?: string | null }> } }; export type TableNamesQueryVariables = Exact<{ databaseName: Scalars['String']['input']; @@ -1595,10 +1607,8 @@ export type CreateSchemaMutationResult = Apollo.MutationResult; export const BranchesForSelectorDocument = gql` query BranchesForSelector($databaseName: String!) { - branches(databaseName: $databaseName) { - list { - ...BranchForBranchSelector - } + allBranches(databaseName: $databaseName) { + ...BranchForBranchSelector } } ${BranchForBranchSelectorFragmentDoc}`; @@ -2524,11 +2534,12 @@ export type RemoveConnectionMutationHookResult = ReturnType; export type RemoveConnectionMutationOptions = Apollo.BaseMutationOptions; export const BranchListDocument = gql` - query BranchList($databaseName: String!, $sortBy: SortBranchesBy) { - branches(databaseName: $databaseName, sortBy: $sortBy) { + query BranchList($databaseName: String!, $sortBy: SortBranchesBy, $offset: Int) { + branches(databaseName: $databaseName, sortBy: $sortBy, offset: $offset) { list { ...Branch } + nextOffset } } ${BranchFragmentDoc}`; @@ -2547,6 +2558,7 @@ export const BranchListDocument = gql` * variables: { * databaseName: // value for 'databaseName' * sortBy: // value for 'sortBy' + * offset: // value for 'offset' * }, * }); */ @@ -3408,11 +3420,12 @@ export type HistoryForBranchLazyQueryHookResult = ReturnType; export type HistoryForBranchQueryResult = Apollo.QueryResult; export const BranchListForCommitGraphDocument = gql` - query BranchListForCommitGraph($databaseName: String!) { - branches(databaseName: $databaseName) { + query BranchListForCommitGraph($databaseName: String!, $offset: Int) { + branches(databaseName: $databaseName, offset: $offset) { list { ...BranchForCommitGraph } + nextOffset } } ${BranchForCommitGraphFragmentDoc}`; @@ -3430,6 +3443,7 @@ export const BranchListForCommitGraphDocument = gql` * const { data, loading, error } = useBranchListForCommitGraphQuery({ * variables: { * databaseName: // value for 'databaseName' + * offset: // value for 'offset' * }, * }); */ diff --git a/web/hooks/useCommitListForCommitGraph/index.ts b/web/hooks/useCommitListForCommitGraph/index.ts index b145dcbc..36ad3d04 100644 --- a/web/hooks/useCommitListForCommitGraph/index.ts +++ b/web/hooks/useCommitListForCommitGraph/index.ts @@ -1,4 +1,7 @@ import { + BranchListForCommitGraphDocument, + BranchListForCommitGraphQuery, + BranchListForCommitGraphQueryVariables, CommitForHistoryFragment, HistoryForBranchDocument, HistoryForBranchQuery, @@ -55,16 +58,16 @@ export function useCommitListForCommitGraph( const [dataInitiallyLoaded, setDataInitiallyLoaded] = useState(false); const [branches, setBranches] = useState(branchesData?.branches.list); - // const [branchesPageToken, setBranchesPageToken] = useState( - // branchesData?.branches.nextPageToken, - // ); + const [branchesOffset, setBranchesOffset] = useState( + branchesData?.branches.nextOffset, + ); useEffect(() => { if (!data || !branchesData || (dataInitiallyLoaded && !reload)) return; setCommits(data.commits.list); setCommitsOffset(data.commits.nextOffset); setBranches(branchesData.branches.list); - // setBranchesPageToken(branchesData.branches.nextPageToken); + setBranchesOffset(branchesData.branches.nextOffset); setDataInitiallyLoaded(true); }, [ data, @@ -75,7 +78,7 @@ export function useCommitListForCommitGraph( params, branchesData, setBranches, - // setBranchesPageToken, + setBranchesOffset, ]); const loadMore = async () => { @@ -101,24 +104,24 @@ export function useCommitListForCommitGraph( handleCaughtApolloError(e, setErr); } } - // if (branchesPageToken) { - // try { - // const result = await branchesClient.query< - // BranchListForCommitGraphQuery, - // BranchListForCommitGraphQueryVariables - // >({ - // query: BranchListForCommitGraphDocument, - // variables: { ...params, pageToken: branchesPageToken }, - // }); - // const newBranches = result.data.branches.list; - // const newToken = result.data.branches.nextPageToken; - // const allBranches = (branches ?? []).concat(newBranches); - // setBranches(allBranches); - // setBranchesPageToken(newToken); - // } catch (e) { - // handleCaughtApolloError(e, setErr); - // } - // } + if (branchesOffset) { + try { + const result = await branchesRes.client.query< + BranchListForCommitGraphQuery, + BranchListForCommitGraphQueryVariables + >({ + query: BranchListForCommitGraphDocument, + variables: { ...params, offset: branchesOffset }, + }); + const newBranches = result.data.branches.list; + const newToken = result.data.branches.nextOffset; + const allBranches = (branches ?? []).concat(newBranches); + setBranches(allBranches); + setBranchesOffset(newToken); + } catch (e) { + handleCaughtApolloError(e, setErr); + } + } }; const branchHeads = diff --git a/web/hooks/useCommitListForCommitGraph/queries.ts b/web/hooks/useCommitListForCommitGraph/queries.ts index 1a36c7fb..bd2ace54 100644 --- a/web/hooks/useCommitListForCommitGraph/queries.ts +++ b/web/hooks/useCommitListForCommitGraph/queries.ts @@ -5,11 +5,12 @@ export const BRANCH_LIST_FOR_COMMIT_GRAPH_QUERY = gql` branchName head } - query BranchListForCommitGraph($databaseName: String!) { - branches(databaseName: $databaseName) { + query BranchListForCommitGraph($databaseName: String!, $offset: Int) { + branches(databaseName: $databaseName, offset: $offset) { list { ...BranchForCommitGraph } + nextOffset } } `;