Skip to content

Commit 9504369

Browse files
nivedinCopilotjamesgeorge007
authored
fix: handle edge cases and bugs in collection variables (hoppscotch#5348)
Co-authored-by: Copilot <[email protected]> Co-authored-by: jamesgeorge007 <[email protected]>
1 parent a0c2635 commit 9504369

File tree

18 files changed

+610
-539
lines changed

18 files changed

+610
-539
lines changed

packages/hoppscotch-common/src/components/app/Inspection.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@
5151
<icon-lucide-arrow-up-right class="svg-icons" />
5252
</HoppSmartLink>
5353
</span>
54-
<span v-if="inspector.action" class="flex space-x-2 p-2">
54+
<span
55+
v-if="inspector.action ? inspector.action.showAction : true"
56+
class="flex space-x-2 p-2"
57+
>
5558
<HoppButtonSecondary
56-
:label="inspector.action.text"
59+
:label="inspector.action?.text"
5760
outline
5861
filled
5962
@click="

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
emit('export-data', node.data.data.data)
109109
"
110110
@remove-collection="emit('remove-collection', node.id)"
111-
@drop-event="dropEvent($event, node.id)"
111+
@drop-event="dropEvent($event, node.id, getPath(node.id, false))"
112112
@drag-event="dragEvent($event, node.id)"
113113
@update-collection-order="
114114
updateCollectionOrder($event, {
@@ -210,8 +210,12 @@
210210
node.data.type === 'folders' &&
211211
emit('remove-folder', node.data.data.data.id)
212212
"
213-
@drop-event="dropEvent($event, node.data.data.data.id)"
214-
@drag-event="dragEvent($event, node.data.data.data.id)"
213+
@drop-event="
214+
dropEvent($event, node.data.data.data.id, getPath(node.id, false))
215+
"
216+
@drag-event="
217+
dragEvent($event, node.data.data.data.id, getPath(node.id, true))
218+
"
215219
@update-collection-order="
216220
updateCollectionOrder($event, {
217221
destinationCollectionIndex: node.data.data.data.id,
@@ -640,6 +644,8 @@ const emit = defineEmits<{
640644
payload: {
641645
collectionIndexDragged: string
642646
destinationCollectionIndex: string
647+
destinationParentPath?: string
648+
currentParentIndex?: string
643649
}
644650
): void
645651
(
@@ -678,9 +684,9 @@ const emit = defineEmits<{
678684
): void
679685
}>()
680686
681-
const getPath = (path: string) => {
687+
const getPath = (path: string, pop: boolean = true) => {
682688
const pathArray = path.split("/")
683-
pathArray.pop()
689+
if (pop) pathArray.pop()
684690
return pathArray.join("/")
685691
}
686692
@@ -783,17 +789,25 @@ const dragRequest = (
783789
dataTransfer.setData("requestIndex", requestIndex)
784790
}
785791
786-
const dragEvent = (dataTransfer: DataTransfer, collectionIndex: string) => {
792+
const dragEvent = (
793+
dataTransfer: DataTransfer,
794+
collectionIndex: string,
795+
parentIndex?: string
796+
) => {
787797
dataTransfer.setData("collectionIndex", collectionIndex)
798+
if (parentIndex) dataTransfer.setData("parentIndex", parentIndex)
788799
}
789800
790801
const dropEvent = (
791802
dataTransfer: DataTransfer,
792-
destinationCollectionIndex: string
803+
destinationCollectionIndex: string,
804+
destinationParentPath?: string
793805
) => {
794806
const folderPath = dataTransfer.getData("folderPath")
795807
const requestIndex = dataTransfer.getData("requestIndex")
796808
const collectionIndexDragged = dataTransfer.getData("collectionIndex")
809+
const currentParentIndex = dataTransfer.getData("parentIndex")
810+
797811
if (folderPath && requestIndex) {
798812
emit("drop-request", {
799813
folderPath,
@@ -804,6 +818,8 @@ const dropEvent = (
804818
emit("drop-collection", {
805819
collectionIndexDragged,
806820
destinationCollectionIndex,
821+
destinationParentPath,
822+
currentParentIndex,
807823
})
808824
}
809825
}

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,8 +2296,15 @@ const isMoveToSameLocation = (
22962296
const dropCollection = (payload: {
22972297
collectionIndexDragged: string
22982298
destinationCollectionIndex: string
2299+
destinationParentPath?: string
2300+
currentParentIndex?: string
22992301
}) => {
2300-
const { collectionIndexDragged, destinationCollectionIndex } = payload
2302+
const {
2303+
collectionIndexDragged,
2304+
destinationCollectionIndex,
2305+
destinationParentPath,
2306+
currentParentIndex,
2307+
} = payload
23012308
if (!collectionIndexDragged || !destinationCollectionIndex) return
23022309
if (collectionIndexDragged === destinationCollectionIndex) return
23032310
@@ -2339,18 +2346,20 @@ const dropCollection = (payload: {
23392346
"drop"
23402347
)
23412348
2349+
const newCollectionPath = `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`
2350+
23422351
updateSaveContextForAffectedRequests(
23432352
collectionIndexDragged,
2344-
`${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`
2353+
newCollectionPath
23452354
)
23462355
23472356
const inheritedProperty = cascadeParentCollectionForProperties(
2348-
`${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
2357+
newCollectionPath,
23492358
"rest"
23502359
)
23512360
23522361
updateInheritedPropertiesForAffectedRequests(
2353-
`${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
2362+
newCollectionPath,
23542363
inheritedProperty,
23552364
"rest"
23562365
)
@@ -2381,16 +2390,25 @@ const dropCollection = (payload: {
23812390
1
23822391
)
23832392
2393+
if (destinationParentPath && currentParentIndex) {
2394+
updateSaveContextForAffectedRequests(
2395+
currentParentIndex,
2396+
`${destinationParentPath}`
2397+
)
2398+
}
2399+
23842400
const inheritedProperty =
23852401
teamCollectionAdapter.cascadeParentCollectionForProperties(
2386-
destinationCollectionIndex
2402+
`${destinationParentPath}/${collectionIndexDragged}`
23872403
)
23882404
2389-
updateInheritedPropertiesForAffectedRequests(
2390-
`${destinationCollectionIndex}`,
2391-
inheritedProperty,
2392-
"rest"
2393-
)
2405+
setTimeout(() => {
2406+
updateInheritedPropertiesForAffectedRequests(
2407+
`${destinationParentPath}/${collectionIndexDragged}`,
2408+
inheritedProperty,
2409+
"rest"
2410+
)
2411+
}, 300)
23942412
}
23952413
)
23962414
)()
@@ -2430,6 +2448,17 @@ const dropToRoot = ({ dataTransfer }: DragEvent) => {
24302448
collectionIndexDragged,
24312449
`${rootLength - 1}`
24322450
)
2451+
2452+
const inheritedProperty = cascadeParentCollectionForProperties(
2453+
`${rootLength - 1}`,
2454+
"rest"
2455+
)
2456+
2457+
updateInheritedPropertiesForAffectedRequests(
2458+
`${rootLength - 1}`,
2459+
inheritedProperty,
2460+
"rest"
2461+
)
24332462
}
24342463
24352464
draggingToRoot.value = false
@@ -2989,7 +3018,7 @@ const setCollectionProperties = (newCollection: {
29893018
"rest",
29903019
collectionId
29913020
)
2992-
}, 200)
3021+
}, 300)
29933022
}
29943023
29953024
displayModalEditProperties(false)

packages/hoppscotch-common/src/components/importExport/ImportExportSteps/AllCollectionImport.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import {
9595
GQLHeader,
9696
HoppCollection,
97+
HoppCollectionVariable,
9798
HoppGQLAuth,
9899
HoppGQLRequest,
99100
HoppRESTAuth,
@@ -261,11 +262,13 @@ const convertToInheritedProperties = (
261262
): {
262263
auth: HoppRESTAuth | HoppGQLAuth
263264
headers: Array<HoppRESTHeader | GQLHeader>
265+
variables: HoppCollectionVariable[]
264266
} => {
265267
const collectionLevelAuthAndHeaders = data
266268
? (JSON.parse(data) as {
267269
auth: HoppRESTAuth | HoppGQLAuth
268270
headers: Array<HoppRESTHeader | GQLHeader>
271+
variables: HoppCollectionVariable[]
269272
})
270273
: null
271274
@@ -276,9 +279,12 @@ const convertToInheritedProperties = (
276279
authActive: true,
277280
}
278281
282+
const variables = collectionLevelAuthAndHeaders?.variables ?? []
283+
279284
return {
280285
auth,
281286
headers,
287+
variables,
282288
}
283289
}
284290

packages/hoppscotch-common/src/components/smart/EnvInput.vue

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -392,33 +392,52 @@ const aggregateEnvs = useReadonlyStream(
392392
const tabs = useService(RESTTabService)
393393
394394
const envVars = computed(() => {
395+
// If envs are passed directly as props, mask secrets and return them
395396
if (props.envs?.length) {
396-
return props.envs.map((x) => {
397-
const { key, secret } = x
398-
const currentValue = secret ? "********" : x.currentValue
399-
const initialValue = secret ? "********" : x.initialValue
400-
const sourceEnv = "sourceEnv" in x ? x.sourceEnv : ""
401-
return {
397+
return props.envs.map(
398+
({ key, currentValue, initialValue, secret, sourceEnv }) => ({
402399
key,
403-
currentValue,
404-
initialValue,
405-
sourceEnv,
400+
currentValue: secret ? "********" : currentValue,
401+
initialValue: secret ? "********" : initialValue,
402+
sourceEnv: sourceEnv ?? "",
406403
secret,
407-
}
408-
})
404+
})
405+
)
409406
}
410407
408+
const currentTab = tabs.currentActiveTab.value
409+
const { document } = currentTab
410+
const isRequest = document.type === "request"
411+
const isExample = document.type === "example-response"
412+
413+
// variables inherited from the collection if we're in a request or example
411414
const collectionVariables =
412-
tabs.currentActiveTab.value.document.type === "request" ||
413-
tabs.currentActiveTab.value.document.type === "example-response"
415+
isRequest || isExample
414416
? transformInheritedCollectionVariablesToAggregateEnv(
415-
tabs.currentActiveTab.value.document.inheritedProperties?.variables ??
416-
[],
417+
document.inheritedProperties?.variables ?? [],
417418
false
418419
)
419420
: []
420421
421-
return [...collectionVariables, ...aggregateEnvs.value]
422+
// request-level variables
423+
const rawRequestVars = isRequest
424+
? document.request.requestVariables
425+
: isExample
426+
? document.response.originalRequest.requestVariables
427+
: []
428+
429+
// formated request variables
430+
const requestVariables = rawRequestVars
431+
.filter((v) => v.active)
432+
.map(({ key, value }) => ({
433+
key,
434+
currentValue: value,
435+
initialValue: value,
436+
sourceEnv: "RequestVariable",
437+
secret: false,
438+
}))
439+
440+
return [...requestVariables, ...collectionVariables, ...aggregateEnvs.value]
422441
})
423442
424443
function envAutoCompletion(context: CompletionContext) {

packages/hoppscotch-common/src/helpers/backend/gql/subscriptions/TeamCollectionMoved.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ subscription TeamCollectionMoved($teamID: ID!) {
55
parent {
66
id
77
}
8+
data
89
}
910
}

0 commit comments

Comments
 (0)