Skip to content

Commit a573db5

Browse files
fix(common): use fallback ref ID for mock server creation with legacy collections (hoppscotch#5536)
Co-authored-by: jamesgeorge007 <[email protected]>
1 parent e607f9d commit a573db5

File tree

5 files changed

+14
-38
lines changed

5 files changed

+14
-38
lines changed

packages/hoppscotch-common/src/components/collections/Collection.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ const mockServerStatus = computed(() => {
473473
474474
const collectionId =
475475
props.collectionsType === "my-collections"
476-
? (props.data as HoppCollection).id
476+
? ((props.data as HoppCollection).id ??
477+
(props.data as HoppCollection)._ref_id)
477478
: (props.data as TeamCollection).id
478479
479480
return getMockServerStatus(collectionId || "")

packages/hoppscotch-common/src/components/collections/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,15 +1083,15 @@ const createMockServer = (payload: {
10831083
}) => {
10841084
// Import the mock server store dynamically to avoid circular dependencies
10851085
import("~/newstore/mockServers").then(({ showCreateMockServerModal$ }) => {
1086-
let collectionID = payload.collection.id ?? undefined
1086+
let collectionID = payload.collection.id ?? payload.collection._ref_id
10871087
10881088
// If this is a child collection (folder), we need to get the root collection ID
10891089
if (payload.collectionIndex.includes("/")) {
10901090
// Extract the root collection index from the path (e.g., "0/1/2" -> "0")
10911091
const rootIndex = payload.collectionIndex.split("/")[0]
10921092
const rootCollection = myCollections.value[parseInt(rootIndex)]
10931093
if (rootCollection) {
1094-
collectionID = rootCollection.id ?? undefined
1094+
collectionID = rootCollection.id ?? rootCollection._ref_id
10951095
}
10961096
}
10971097

packages/hoppscotch-common/src/components/mockServer/CreateMockServer.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ const isExistingMockServer = computed(() => !!existingMockServer.value)
386386
// Collection options for the selector (only root collections)
387387
const collectionOptions = computed(() => {
388388
return availableCollections.value.map((collection) => {
389-
const collectionId = collection.id
389+
const collectionId =
390+
currentWorkspace.value.type === "team"
391+
? collection.id
392+
: (collection.id ?? collection._ref_id) // TODO: fix this fallback logic for personal workspaces in the future
390393
const hasMockServer = mockServers.value.some(
391394
(server) => server.collectionID === collectionId
392395
)

packages/hoppscotch-common/src/composables/mockServerVisibility.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,21 @@
11
import { computed } from "vue"
2+
23
import { useSetting } from "~/composables/settings"
3-
import { platform } from "~/platform"
4-
import { useService } from "dioc/vue"
5-
import { WorkspaceService } from "~/services/workspace.service"
64

75
/**
8-
* Composable to determine mock server visibility based on experimental flags and platform configuration
6+
* Composable to determine mock server visibility based on experimental flags
97
*/
108
export function useMockServerVisibility() {
119
const ENABLE_EXPERIMENTAL_MOCK_SERVERS = useSetting(
1210
"ENABLE_EXPERIMENTAL_MOCK_SERVERS"
1311
)
1412

15-
const workspaceService = useService(WorkspaceService)
16-
1713
/**
18-
* Check if mock servers should be visible based on experimental flag and platform configuration
14+
* Check if mock servers should be visible based on experimental flag
1915
*/
20-
const isMockServerVisible = computed(() => {
21-
// First check if experimental mock servers are enabled
22-
if (!ENABLE_EXPERIMENTAL_MOCK_SERVERS.value) {
23-
return false
24-
}
25-
26-
// Check if platform disables mock servers in personal workspaces
27-
const disableInPersonalWorkspace =
28-
platform.platformFeatureFlags.disableMockServerInPersonalWorkspace ??
29-
false
30-
31-
// If platform disables mock servers in personal workspaces and current workspace is personal, hide mock servers
32-
if (
33-
disableInPersonalWorkspace &&
34-
workspaceService.currentWorkspace.value.type === "personal"
35-
) {
36-
return false
37-
}
38-
39-
return true
40-
})
16+
const isMockServerVisible = computed(
17+
() => ENABLE_EXPERIMENTAL_MOCK_SERVERS.value
18+
)
4119

4220
return {
4321
isMockServerVisible,

packages/hoppscotch-common/src/platform/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ export type PlatformDef = {
6666
* Whether to show the A/B testing workspace switcher click login flow or not
6767
*/
6868
workspaceSwitcherLogin?: Ref<boolean>
69-
70-
/**
71-
* Whether to disable mock servers in personal workspaces
72-
* If a value is not given, then the value is assumed to be false
73-
*/
74-
disableMockServerInPersonalWorkspace?: boolean
7569
}
7670
limits?: LimitsPlatformDef
7771
infra?: InfraPlatformDef

0 commit comments

Comments
 (0)