ResponseBodyRenderer.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. >
  10. <component :is="lens.renderer" :response="response" />
  11. </SmartTab>
  12. <SmartTab
  13. v-if="headerLength"
  14. id="headers"
  15. :label="$t('response.headers')"
  16. :info="headerLength.toString()"
  17. >
  18. <LensesHeadersRenderer :headers="response.headers" />
  19. </SmartTab>
  20. <SmartTab id="results" :label="$t('test.results')">
  21. <HttpTestResult />
  22. </SmartTab>
  23. </SmartTabs>
  24. </template>
  25. <script>
  26. import { defineComponent } from "@nuxtjs/composition-api"
  27. import { getSuitableLenses, getLensRenderers } from "~/helpers/lenses/lenses"
  28. export default defineComponent({
  29. components: {
  30. // Lens Renderers
  31. ...getLensRenderers(),
  32. },
  33. props: {
  34. response: { type: Object, default: () => {} },
  35. },
  36. computed: {
  37. headerLength() {
  38. if (!this.response || !this.response.headers) return 0
  39. return Object.keys(this.response.headers).length
  40. },
  41. validLenses() {
  42. if (!this.response) return []
  43. return getSuitableLenses(this.response)
  44. },
  45. },
  46. })
  47. </script>