refactor: prevent storing entire collection data in the respective handle

This commit is contained in:
jamesgeorge007
2024-02-08 23:08:54 +05:30
parent d6a8e60239
commit f0dab55c99
4 changed files with 70 additions and 31 deletions

View File

@@ -140,12 +140,15 @@ import IconHelpCircle from "~icons/lucide/help-circle"
import IconPlus from "~icons/lucide/plus"
import {
cascadeParentCollectionForHeaderAuth,
navigateToFolderWithIndexPath,
restCollectionStore,
saveRESTRequestAs,
} from "~/newstore/collections"
import { cloneDeep } from "lodash-es"
import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data"
import { TeamCollection } from "~/helpers/backend/graphql"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { useStreamStatic } from "~/composables/stream"
const t = useI18n()
const toast = useToast()
@@ -784,7 +787,18 @@ const editCollectionProperties = async (collIndexPath: string) => {
return
}
const { collection } = collHandle.value.data
const restCollectionState = useStreamStatic(
restCollectionStore.subject$,
{ state: [] },
() => {
/* noop */
}
)[0]
const collection = navigateToFolderWithIndexPath(
restCollectionState.value.state,
collIndexPath.split("/").map((i) => parseInt(i))
)
editingProperties.value = {
collection,

View File

@@ -1,8 +1,4 @@
import {
HoppCollection,
isHoppRESTRequest,
makeCollection,
} from "@hoppscotch/data"
import { HoppCollection, makeCollection } from "@hoppscotch/data"
import { Service } from "dioc"
import * as E from "fp-ts/Either"
import { Ref, computed, markRaw, nextTick, ref, shallowRef } from "vue"
@@ -153,7 +149,7 @@ export class PersonalWorkspaceProviderService
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
collectionID: "", // Compute this and supply
collection: newRootCollection,
name: collectionName,
},
}
})
@@ -199,18 +195,13 @@ export class PersonalWorkspaceProviderService
platform: "rest",
})
const newCollection = navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
) as HoppCollection
return {
type: "ok",
data: {
providerID,
workspaceID,
collectionID,
collection: newCollection,
name: collectionName,
},
}
})
@@ -244,10 +235,23 @@ export class PersonalWorkspaceProviderService
}
}
const { collection, collectionID } = collHandle.value.data
const { collectionID } = collHandle.value.data
const collection: HoppCollection | null =
navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
)
if (!collection) {
return {
type: "invalid" as const,
reason: "COLLECTION_NOT_FOUND" as const,
}
}
const updatedCollection = {
...(collection as HoppCollection),
...collection,
name: newCollectionName,
}
@@ -289,10 +293,23 @@ export class PersonalWorkspaceProviderService
}
}
const { collection, collectionID } = collHandle.value.data
const { collectionID } = collHandle.value.data
const collection: HoppCollection | null =
navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
)
if (!collection) {
return {
type: "invalid" as const,
reason: "COLLECTION_NOT_FOUND" as const,
}
}
const updatedCollection = {
...(collection as HoppCollection),
...collection,
name: newCollectionName,
}
@@ -333,10 +350,23 @@ export class PersonalWorkspaceProviderService
}
}
const { collection, collectionID } = collHandle.value.data
const { collectionID } = collHandle.value.data
const { auth, headers } = updatedCollProps
const collection: HoppCollection | null =
navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
)
if (!collection) {
return {
type: "invalid" as const,
reason: "COLLECTION_NOT_FOUND" as const,
}
}
const updatedCollection = {
...collection,
auth,
@@ -515,7 +545,7 @@ export class PersonalWorkspaceProviderService
}
}
const { collectionID, providerID, workspaceID } =
const { collectionID, providerID, workspaceID, name } =
parentCollHandle.value.data
const newRequest = {
@@ -553,18 +583,13 @@ export class PersonalWorkspaceProviderService
platform: "rest",
})
const newCollection = navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
) as HoppCollection
return {
type: "ok",
data: {
providerID,
workspaceID,
collectionID,
collection: newCollection,
name,
},
}
})
@@ -746,7 +771,7 @@ export class PersonalWorkspaceProviderService
providerID,
workspaceID,
collectionID,
collection,
name: collection.name,
},
}
})
@@ -878,7 +903,7 @@ export class PersonalWorkspaceProviderService
type: "collection",
value: {
collectionID: `${collectionID}/${id}`,
collection: childColl,
name: childColl.name,
},
}
})
@@ -937,7 +962,7 @@ export class PersonalWorkspaceProviderService
return this.restCollectionState.value.state.map((coll, id) => {
return {
collectionID: id.toString(),
collection: coll,
name: coll.name,
}
})
}),

View File

@@ -1,10 +1,10 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { HoppRESTRequest } from "@hoppscotch/data"
import { Ref } from "vue"
export type RESTCollectionViewCollection = {
collectionID: string
collection: HoppCollection // Should not store children including folders and requests
name: string
}
export type RESTCollectionViewRequest = {

View File

@@ -13,7 +13,7 @@ export type WorkspaceCollection = {
workspaceID: string
collectionID: string
collection: HoppCollection | null
name: string
}
export type WorkspaceRequest = {