ResponseBodyRenderer.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <SmartTabs
  3. v-if="response"
  4. v-model="selectedLensTab"
  5. styles="sticky z-10 bg-primary top-lowerPrimaryStickyFold"
  6. >
  7. <SmartTab
  8. v-for="(lens, index) in validLenses"
  9. :id="lens.renderer"
  10. :key="`lens-${index}`"
  11. :label="$t(lens.lensName)"
  12. class="flex flex-col flex-1 w-full h-full"
  13. >
  14. <component :is="lens.renderer" :response="response" />
  15. </SmartTab>
  16. <SmartTab
  17. v-if="headerLength"
  18. id="headers"
  19. :label="$t('response.headers')"
  20. :info="`${headerLength}`"
  21. class="flex flex-col flex-1"
  22. >
  23. <LensesHeadersRenderer :headers="response.headers" />
  24. </SmartTab>
  25. <SmartTab
  26. id="results"
  27. :label="$t('test.results')"
  28. :indicator="
  29. testResults &&
  30. (testResults.expectResults.length ||
  31. testResults.tests.length ||
  32. testResults.envDiff.selected.additions.length ||
  33. testResults.envDiff.selected.updations.length ||
  34. testResults.envDiff.global.updations.length)
  35. ? true
  36. : false
  37. "
  38. class="flex flex-col flex-1"
  39. >
  40. <HttpTestResult />
  41. </SmartTab>
  42. </SmartTabs>
  43. </template>
  44. <script>
  45. import { defineComponent } from "@nuxtjs/composition-api"
  46. import { getSuitableLenses, getLensRenderers } from "~/helpers/lenses/lenses"
  47. import { useReadonlyStream } from "~/helpers/utils/composables"
  48. import { restTestResults$ } from "~/newstore/RESTSession"
  49. export default defineComponent({
  50. components: {
  51. // Lens Renderers
  52. ...getLensRenderers(),
  53. },
  54. props: {
  55. response: { type: Object, default: () => {} },
  56. },
  57. setup() {
  58. const testResults = useReadonlyStream(restTestResults$, null)
  59. return {
  60. testResults,
  61. }
  62. },
  63. data() {
  64. return {
  65. selectedLensTab: "",
  66. }
  67. },
  68. computed: {
  69. headerLength() {
  70. if (!this.response || !this.response.headers) return 0
  71. return Object.keys(this.response.headers).length
  72. },
  73. validLenses() {
  74. if (!this.response) return []
  75. return getSuitableLenses(this.response)
  76. },
  77. },
  78. watch: {
  79. validLenses: {
  80. handler(newValue) {
  81. if (newValue.length === 0) return
  82. this.selectedLensTab = newValue[0].renderer
  83. },
  84. immediate: true,
  85. },
  86. },
  87. })
  88. </script>