Skip to content

Commit

Permalink
fix: runner result adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarulislam committed Dec 8, 2023
1 parent bd165d1 commit 3f91480
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 240 deletions.
Expand Up @@ -33,7 +33,7 @@
</div>

<div v-else class="flex flex-col flex-1">
<HttpTestRunnerConfig v-model="tab" v-model:config="testRunnerConfig" />
<HttpTestRunnerConfig v-model="tab" v-model:config="testRunnerConfig" />
</div>
</template>
<template #secondary>
Expand Down Expand Up @@ -96,5 +96,5 @@ const emit = defineEmits<{
const tab = useVModel(props, "modelValue", emit)
const showResult = ref(false)
const showResult = ref(true)
</script>
123 changes: 11 additions & 112 deletions packages/hoppscotch-common/src/components/http/test/RunnerConfig.vue
Expand Up @@ -32,9 +32,8 @@
:data="node.data.data.data"
:is-open="true"
:is-selected="node.data.isSelected"
:is-last-item="node.data.isLastItem"
:show-selection="showCheckbox"
folder-type="collection"
folder-type="folder"
/>

<HttpTestRequest
Expand Down Expand Up @@ -130,22 +129,16 @@
</template>

<script setup lang="ts">
import IconHelpCircle from "~icons/lucide/help-circle"
import IconMouseSquare from "~icons/lucide/mouse-pointer-square-dashed"
import IconMousePointer from "~icons/lucide/mouse-pointer-square"
import { ref } from "vue"
import { SmartTreeAdapter } from "@hoppscotch/ui/dist/helpers/treeAdapter"
import { useVModel } from "@vueuse/core"
import { HoppTab } from "~/services/tab"
import { HoppTabDocument } from "~/helpers/rest/document"
import { ref, toRef } from "vue"
import { useI18n } from "~/composables/i18n"
import {
ChildrenResult,
SmartTreeAdapter,
} from "@hoppscotch/ui/dist/helpers/treeAdapter"
import { toRef } from "vue"
import { Ref } from "vue"
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { computed } from "vue"
import { HoppTabDocument } from "~/helpers/rest/document"
import { TestRunnerCollectionsAdapter } from "~/helpers/runner/adapter"
import { HoppTab } from "~/services/tab"
import IconHelpCircle from "~icons/lucide/help-circle"
import IconMousePointer from "~icons/lucide/mouse-pointer-square"
import IconMouseSquare from "~icons/lucide/mouse-pointer-square-dashed"
import { TestRunnerConfig } from "./Runner.vue"
const t = useI18n()
Expand All @@ -164,106 +157,12 @@ const config = useVModel(props, "config", emit)
const showCheckbox = ref(false)
class MyCollectionsAdapter implements SmartTreeAdapter<any> {
constructor(public data: Ref<HoppCollection<HoppRESTRequest>[]>) {}
navigateToFolderWithIndexPath(
collections: HoppCollection<HoppRESTRequest>[],
indexPaths: number[]
) {
if (indexPaths.length === 0) return null
let target = collections[indexPaths.shift() as number]
while (indexPaths.length > 0)
target = target.folders[indexPaths.shift() as number]
return target !== undefined ? target : null
}
getChildren(id: string | null): Ref<ChildrenResult<any>> {
return computed(() => {
if (id === null) {
const data = this.data.value.map((item, index) => ({
id: index.toString(),
data: {
type: "collections",
isLastItem: index === this.data.value.length - 1,
data: {
parentIndex: null,
data: item,
},
},
}))
console.log(data)
return {
status: "loaded",
data: data,
} as ChildrenResult<any>
}
const indexPath = id.split("/").map((x) => parseInt(x))
const item = this.navigateToFolderWithIndexPath(
this.data.value,
indexPath
)
if (item) {
const data = [
...item.folders.map((folder, index) => ({
id: `${id}/${index}`,
data: {
isLastItem:
item.folders && item.folders.length > 1
? index === item.folders.length - 1
: false,
type: "folders",
isSelected: true,
data: {
parentIndex: id,
data: folder,
},
},
})),
...item.requests.map((requests, index) => ({
id: `${id}/${index}`,
data: {
isLastItem:
item.requests && item.requests.length > 1
? index === item.requests.length - 1
: false,
type: "requests",
isSelected: true,
data: {
parentIndex: id,
data: requests,
},
},
})),
]
return {
status: "loaded",
data: data,
} as ChildrenResult<any>
} else {
return {
status: "loaded",
data: [],
}
}
})
}
}
const collection = toRef(
tab.value.document.type === "test-runner"
? [tab.value.document.collection]
: []
)
const collectionAdapter: SmartTreeAdapter<any> = new MyCollectionsAdapter(
collection
)
const collectionAdapter: SmartTreeAdapter<any> =
new TestRunnerCollectionsAdapter(collection)
</script>
114 changes: 7 additions & 107 deletions packages/hoppscotch-common/src/components/http/test/RunnerResult.vue
Expand Up @@ -49,19 +49,13 @@
</template>

<script setup lang="ts">
import { ref } from "vue"
import { SmartTreeAdapter } from "@hoppscotch/ui/dist/helpers/treeAdapter"
import { useVModel } from "@vueuse/core"
import { HoppTab } from "~/services/tab"
import { HoppTabDocument } from "~/helpers/rest/document"
import { ref, toRef } from "vue"
import { useI18n } from "~/composables/i18n"
import {
ChildrenResult,
SmartTreeAdapter,
} from "@hoppscotch/ui/dist/helpers/treeAdapter"
import { toRef } from "vue"
import { Ref } from "vue"
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { computed } from "vue"
import { HoppTabDocument } from "~/helpers/rest/document"
import { TestRunnerCollectionsAdapter } from "~/helpers/runner/adapter"
import { HoppTab } from "~/services/tab"
const t = useI18n()
const props = defineProps<{ modelValue: HoppTab<HoppTabDocument> }>()
Expand All @@ -76,106 +70,12 @@ const selectedTestTab = ref("all_tests")
const showCheckbox = ref(false)
class MyCollectionsAdapter implements SmartTreeAdapter<any> {
constructor(public data: Ref<HoppCollection<HoppRESTRequest>[]>) {}
navigateToFolderWithIndexPath(
collections: HoppCollection<HoppRESTRequest>[],
indexPaths: number[]
) {
if (indexPaths.length === 0) return null
let target = collections[indexPaths.shift() as number]
while (indexPaths.length > 0)
target = target.folders[indexPaths.shift() as number]
return target !== undefined ? target : null
}
getChildren(id: string | null): Ref<ChildrenResult<any>> {
return computed(() => {
if (id === null) {
const data = this.data.value.map((item, index) => ({
id: index.toString(),
data: {
type: "collections",
isLastItem: index === this.data.value.length - 1,
data: {
parentIndex: null,
data: item,
},
},
}))
console.log(data)
return {
status: "loaded",
data: data,
} as ChildrenResult<any>
}
const indexPath = id.split("/").map((x) => parseInt(x))
const item = this.navigateToFolderWithIndexPath(
this.data.value,
indexPath
)
if (item) {
const data = [
...item.folders.map((folder, index) => ({
id: `${id}/${index}`,
data: {
isLastItem:
item.folders && item.folders.length > 1
? index === item.folders.length - 1
: false,
type: "folders",
isSelected: false,
data: {
parentIndex: id,
data: folder,
},
},
})),
...item.requests.map((requests, index) => ({
id: `${id}/${index}`,
data: {
isLastItem:
item.requests && item.requests.length > 1
? index === item.requests.length - 1
: false,
type: "requests",
isSelected: false,
data: {
parentIndex: id,
data: requests,
},
},
})),
]
return {
status: "loaded",
data: data,
} as ChildrenResult<any>
} else {
return {
status: "loaded",
data: [],
}
}
})
}
}
const collection = toRef(
tab.value.document.type === "test-runner"
? [tab.value.document.collection]
: []
)
const collectionAdapter: SmartTreeAdapter<any> = new MyCollectionsAdapter(
collection
)
const collectionAdapter: SmartTreeAdapter<any> =
new TestRunnerCollectionsAdapter(collection)
</script>

0 comments on commit 3f91480

Please sign in to comment.