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 IconPlus from "~icons/lucide/plus"
import { import {
cascadeParentCollectionForHeaderAuth, cascadeParentCollectionForHeaderAuth,
navigateToFolderWithIndexPath,
restCollectionStore,
saveRESTRequestAs, saveRESTRequestAs,
} from "~/newstore/collections" } from "~/newstore/collections"
import { cloneDeep } from "lodash-es" import { cloneDeep } from "lodash-es"
import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data"
import { TeamCollection } from "~/helpers/backend/graphql" import { TeamCollection } from "~/helpers/backend/graphql"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { useStreamStatic } from "~/composables/stream"
const t = useI18n() const t = useI18n()
const toast = useToast() const toast = useToast()
@@ -784,7 +787,18 @@ const editCollectionProperties = async (collIndexPath: string) => {
return 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 = { editingProperties.value = {
collection, collection,

View File

@@ -1,8 +1,4 @@
import { import { HoppCollection, makeCollection } from "@hoppscotch/data"
HoppCollection,
isHoppRESTRequest,
makeCollection,
} from "@hoppscotch/data"
import { Service } from "dioc" import { Service } from "dioc"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { Ref, computed, markRaw, nextTick, ref, shallowRef } from "vue" import { Ref, computed, markRaw, nextTick, ref, shallowRef } from "vue"
@@ -153,7 +149,7 @@ export class PersonalWorkspaceProviderService
providerID: this.providerID, providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID, workspaceID: workspaceHandle.value.data.workspaceID,
collectionID: "", // Compute this and supply collectionID: "", // Compute this and supply
collection: newRootCollection, name: collectionName,
}, },
} }
}) })
@@ -199,18 +195,13 @@ export class PersonalWorkspaceProviderService
platform: "rest", platform: "rest",
}) })
const newCollection = navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
) as HoppCollection
return { return {
type: "ok", type: "ok",
data: { data: {
providerID, providerID,
workspaceID, workspaceID,
collectionID, 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 = { const updatedCollection = {
...(collection as HoppCollection), ...collection,
name: newCollectionName, 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 = { const updatedCollection = {
...(collection as HoppCollection), ...collection,
name: newCollectionName, 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 { 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 = { const updatedCollection = {
...collection, ...collection,
auth, auth,
@@ -515,7 +545,7 @@ export class PersonalWorkspaceProviderService
} }
} }
const { collectionID, providerID, workspaceID } = const { collectionID, providerID, workspaceID, name } =
parentCollHandle.value.data parentCollHandle.value.data
const newRequest = { const newRequest = {
@@ -553,18 +583,13 @@ export class PersonalWorkspaceProviderService
platform: "rest", platform: "rest",
}) })
const newCollection = navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id))
) as HoppCollection
return { return {
type: "ok", type: "ok",
data: { data: {
providerID, providerID,
workspaceID, workspaceID,
collectionID, collectionID,
collection: newCollection, name,
}, },
} }
}) })
@@ -746,7 +771,7 @@ export class PersonalWorkspaceProviderService
providerID, providerID,
workspaceID, workspaceID,
collectionID, collectionID,
collection, name: collection.name,
}, },
} }
}) })
@@ -878,7 +903,7 @@ export class PersonalWorkspaceProviderService
type: "collection", type: "collection",
value: { value: {
collectionID: `${collectionID}/${id}`, collectionID: `${collectionID}/${id}`,
collection: childColl, name: childColl.name,
}, },
} }
}) })
@@ -937,7 +962,7 @@ export class PersonalWorkspaceProviderService
return this.restCollectionState.value.state.map((coll, id) => { return this.restCollectionState.value.state.map((coll, id) => {
return { return {
collectionID: id.toString(), 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" import { Ref } from "vue"
export type RESTCollectionViewCollection = { export type RESTCollectionViewCollection = {
collectionID: string collectionID: string
collection: HoppCollection // Should not store children including folders and requests name: string
} }
export type RESTCollectionViewRequest = { export type RESTCollectionViewRequest = {

View File

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