From e622f0eca3554d72d291d90d0aa2d34f0ed44768 Mon Sep 17 00:00:00 2001 From: Jack Kavanagh Date: Fri, 8 Mar 2024 15:04:28 +0100 Subject: [PATCH] fix: use collection name when importing from postman (#7142) * detect postman workspace name * check import type --- packages/insomnia/src/common/import.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/insomnia/src/common/import.ts b/packages/insomnia/src/common/import.ts index cc8222457..a20e5b6b5 100644 --- a/packages/insomnia/src/common/import.ts +++ b/packages/insomnia/src/common/import.ts @@ -8,6 +8,7 @@ import { BaseModel, getModel } from '../models/index'; import * as models from '../models/index'; import { isMockRoute, MockRoute } from '../models/mock-route'; import { isRequest, Request } from '../models/request'; +import { isRequestGroup } from '../models/request-group'; import { isUnitTest, UnitTest } from '../models/unit-test'; import { isUnitTestSuite, UnitTestSuite } from '../models/unit-test-suite'; import { @@ -151,10 +152,19 @@ export async function importResourcesToProject({ projectId }: { projectId: strin invariant(ResourceCache, 'No resources to import'); const resources = ResourceCache.resources; const bufferId = await db.bufferChanges(); + const postmanTopLevelFolder = resources.find( + resource => isRequestGroup(resource) && resource.parentId === '__WORKSPACE_ID__' + ) as Workspace | undefined; + if (ResourceCache.type.id === 'postman' && postmanTopLevelFolder) { + await importResourcesToNewWorkspace(projectId, postmanTopLevelFolder); + return { resources }; + } + // No workspace, so create one if (!resources.find(isWorkspace)) { await importResourcesToNewWorkspace(projectId); return { resources }; } + // One or more workspaces const r = await Promise.all(resources.filter(isWorkspace) .map(resource => importResourcesToNewWorkspace(projectId, resource)));