Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
feat: add loading collections stream to team collection adapter
Andrew Bastin5aa6bf0d5389
diff --git a/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts b/packages/hoppscotch-app/helpers/backend/caching/optimistic.tsindex 0ab5065d3..30d86a00b 100644--- a/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts+++ b/packages/hoppscotch-app/helpers/backend/caching/optimistic.ts@@ -1,13 +1,3 @@import { GraphCacheOptimisticUpdaters } from "../graphql"-export const optimisticDefs: GraphCacheOptimisticUpdaters = {- deleteTeam: () => true,- leaveTeam: () => true,- renameTeam: ({ teamID, newName }) => ({- __typename: "Team",- id: teamID,- name: newName,- }),- removeTeamMember: () => true,- revokeTeamInvitation: () => true,-}+export const optimisticDefs: GraphCacheOptimisticUpdaters = {}diff --git a/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts b/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.tsindex fdcd24113..dcfe57a8f 100644--- a/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts+++ b/packages/hoppscotch-app/helpers/teams/TeamCollectionAdapter.ts@@ -183,6 +183,9 @@ function findCollWithReqIDInTree(export default class NewTeamCollectionAdapter {collections$: BehaviorSubject<TeamCollection[]>+ // Stream to the list of collections/folders that are being loaded in+ loadingCollections$: BehaviorSubject<string[]>+private teamCollectionAdded$: Subscription | nullprivate teamCollectionUpdated$: Subscription | nullprivate teamCollectionRemoved$: Subscription | null@@ -192,6 +195,7 @@ export default class NewTeamCollectionAdapter {constructor(private teamID: string | null) {this.collections$ = new BehaviorSubject<TeamCollection[]>([])+ this.loadingCollections$ = new BehaviorSubject<string[]>([])this.teamCollectionAdded$ = nullthis.teamCollectionUpdated$ = null@@ -206,6 +210,7 @@ export default class NewTeamCollectionAdapter {changeTeamID(newTeamID: string | null) {this.teamID = newTeamIDthis.collections$.next([])+ this.loadingCollections$.next([])this.unsubscribeSubscriptions()@@ -262,6 +267,11 @@ export default class NewTeamCollectionAdapter {private async loadRootCollections() {if (this.teamID === null) throw new Error("Team ID is null")+ this.loadingCollections$.next([+ ...this.loadingCollections$.getValue(),+ "root",+ ])+const totalCollections: TeamCollection[] = []while (true) {@@ -276,8 +286,13 @@ export default class NewTeamCollectionAdapter {},})- if (E.isLeft(result))+ if (E.isLeft(result)) {+ this.loadingCollections$.next(+ this.loadingCollections$.getValue().filter((x) => x !== "root")+ )+throw new Error(`Error fetching root collections: ${result}`)+ }totalCollections.push(...result.right.rootCollectionsOfTeam.map(@@ -294,6 +309,10 @@ export default class NewTeamCollectionAdapter {break}+ this.loadingCollections$.next(+ this.loadingCollections$.getValue().filter((x) => x !== "root")+ )+this.collections$.next(totalCollections)}@@ -503,6 +522,11 @@ export default class NewTeamCollectionAdapter {const collections: TeamCollection[] = []+ this.loadingCollections$.next([+ ...this.loadingCollections$.getValue(),+ collectionID,+ ])+while (true) {const data = await runGQLQuery({query: GetCollectionChildrenDocument,@@ -515,10 +539,15 @@ export default class NewTeamCollectionAdapter {},})- if (E.isLeft(data))+ if (E.isLeft(data)) {+ this.loadingCollections$.next(+ this.loadingCollections$.getValue().filter((x) => x !== collectionID)+ )+throw new Error(`Child Collection Fetch Error for ${collectionID}: ${data.left}`)+ }collections.push(...data.right.collection!.children.map(@@ -548,8 +577,13 @@ export default class NewTeamCollectionAdapter {},})- if (E.isLeft(data))+ if (E.isLeft(data)) {+ this.loadingCollections$.next(+ this.loadingCollections$.getValue().filter((x) => x !== collectionID)+ )+throw new Error(`Child Request Fetch Error for ${data}: ${data.left}`)+ }requests.push(...data.right.requestsInCollection.map<TeamRequest>((el) => {@@ -569,6 +603,10 @@ export default class NewTeamCollectionAdapter {collection.children = collectionscollection.requests = requests+ this.loadingCollections$.next(+ this.loadingCollections$.getValue().filter((x) => x !== collectionID)+ )+this.collections$.next(tree)}}