diff --git a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue index a4dd4c197..7d9c62a6c 100644 --- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue +++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue @@ -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, diff --git a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts index 04a0398ae..0118c2bdd 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts @@ -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, } }) }), diff --git a/packages/hoppscotch-common/src/services/new-workspace/view.ts b/packages/hoppscotch-common/src/services/new-workspace/view.ts index d4d476a49..fc6a97ce9 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/view.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/view.ts @@ -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 = { diff --git a/packages/hoppscotch-common/src/services/new-workspace/workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/workspace.ts index f4da935c8..6fca2694a 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/workspace.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/workspace.ts @@ -13,7 +13,7 @@ export type WorkspaceCollection = { workspaceID: string collectionID: string - collection: HoppCollection | null + name: string } export type WorkspaceRequest = {