ResponseBodyRenderer.vue 1.8 KB

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