Skip to content

Commit

Permalink
fix: ensure requests within search results are translated to the late…
Browse files Browse the repository at this point in the history
…st version
  • Loading branch information
jamesgeorge007 committed Mar 23, 2024
1 parent f23ef92 commit e563494
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
Expand Up @@ -37,6 +37,7 @@ export const hoppRESTImporter = (content: string[]) =>
*/
const validateCollection = (collection: unknown) => {
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)

if (collectionSchemaParsedResult.type === "ok") {
const requests = collectionSchemaParsedResult.value.requests.map(
(request) => {
Expand Down Expand Up @@ -83,19 +84,24 @@ export const hoppGQLImporter = (content: string) =>
* @returns the collection if it is valid, else a translated version of the collection
*/
export const validateGQLCollection = (collection: unknown) => {
const result = HoppCollection.safeParse(collection)
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)

if (result.type === "ok")
return O.some({
...result.value,
requests: result.value.requests.map((request) => {
if (collectionSchemaParsedResult.type === "ok") {
const requests = collectionSchemaParsedResult.value.requests.map(
(request) => {
const requestSchemaParsedResult = HoppRESTRequest.safeParse(request)

return requestSchemaParsedResult.type === "ok"
? requestSchemaParsedResult.value
: getDefaultGQLRequest()
}),
}
)

return O.some({
...collectionSchemaParsedResult.value,
requests,
})
}

return O.some(translateToNewGQLCollection(collection))
}
@@ -1,4 +1,14 @@
import { ref } from "vue"
import {
HoppRESTAuth,
HoppRESTHeader,
HoppRESTRequest,
getDefaultRESTRequest,
} from "@hoppscotch/data"
import axios from "axios"
import { Service } from "dioc"
import * as E from "fp-ts/Either"
import { Ref, ref } from "vue"

import { runGQLQuery } from "../backend/GQLClient"
import {
GetCollectionChildrenDocument,
Expand All @@ -7,15 +17,10 @@ import {
GetSingleRequestDocument,
} from "../backend/graphql"
import { TeamCollection } from "./TeamCollection"
import { HoppRESTAuth, HoppRESTHeader } from "@hoppscotch/data"

import * as E from "fp-ts/Either"
import { platform } from "~/platform"
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
import { TeamRequest } from "./TeamRequest"
import { Service } from "dioc"
import axios from "axios"
import { Ref } from "vue"
import { platform } from "~/platform"

type CollectionSearchMeta = {
isSearchResult?: boolean
Expand Down Expand Up @@ -150,12 +155,21 @@ function convertToTeamTree(
if (isAlreadyInserted) return

if (parentCollection) {
const requestSchemaParsedResult = HoppRESTRequest.safeParse(
request.request
)

const effectiveRequest =
requestSchemaParsedResult.type === "ok"
? requestSchemaParsedResult.value
: getDefaultRESTRequest()

parentCollection.requests = parentCollection.requests || []
parentCollection.requests.push({
id: request.id,
collectionID: request.collectionID,
title: request.title,
request: request.request,
request: effectiveRequest,
})
}
})
Expand Down

0 comments on commit e563494

Please sign in to comment.