Properties.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <HoppSmartModal
  3. v-if="show"
  4. dialog
  5. :title="t('collection.properties')"
  6. :full-width-body="true"
  7. @close="hideModal"
  8. >
  9. <template #body>
  10. <HoppSmartTabs
  11. v-model="selectedOptionTab"
  12. styles="sticky overflow-x-auto flex-shrink-0 bg-primary top-0 z-10 !-py-4"
  13. render-inactive-tabs
  14. >
  15. <HoppSmartTab :id="'headers'" :label="`${t('tab.headers')}`">
  16. <HttpHeaders
  17. v-model="editableCollection"
  18. :is-collection-property="true"
  19. @change-tab="changeOptionTab"
  20. />
  21. <AppBanner
  22. :banner="{
  23. type: 'info',
  24. alternateText: 'This is an alternate text',
  25. }"
  26. class="sticky bottom-0 z-10"
  27. >
  28. <span>
  29. {{ t("helpers.collection_properties_header") }}
  30. <a href="hopp.sh" target="_blank" class="underline">{{
  31. t("action.learn_more")
  32. }}</a>
  33. </span>
  34. </AppBanner>
  35. </HoppSmartTab>
  36. <HoppSmartTab
  37. :id="'authorization'"
  38. :label="`${t('tab.authorization')}`"
  39. >
  40. <HttpAuthorization
  41. v-model="editableCollection.auth"
  42. :is-collection-property="true"
  43. :is-root-collection="editingProperties?.isRootCollection"
  44. :inherited-properties="editingProperties?.inheritedProperties"
  45. />
  46. <AppBanner
  47. :banner="{
  48. type: 'info',
  49. alternateText: 'This is an alternate text',
  50. }"
  51. >
  52. <span>
  53. {{ t("helpers.collection_properties_authorization") }}
  54. <a href="hopp.sh" target="_blank" class="underline">{{
  55. t("action.learn_more")
  56. }}</a>
  57. </span>
  58. </AppBanner>
  59. </HoppSmartTab>
  60. </HoppSmartTabs>
  61. </template>
  62. <template #footer>
  63. <span class="flex space-x-2">
  64. <HoppButtonPrimary
  65. :label="t('action.save')"
  66. :loading="loadingState"
  67. outline
  68. @click="saveEditedCollection"
  69. />
  70. <HoppButtonSecondary
  71. :label="t('action.cancel')"
  72. outline
  73. filled
  74. @click="hideModal"
  75. />
  76. </span>
  77. </template>
  78. </HoppSmartModal>
  79. </template>
  80. <script setup lang="ts">
  81. import { watch, ref } from "vue"
  82. import { useI18n } from "@composables/i18n"
  83. import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
  84. import { RESTOptionTabs } from "../http/RequestOptions.vue"
  85. import { TeamCollection } from "~/helpers/teams/TeamCollection"
  86. import { clone } from "lodash-es"
  87. import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
  88. const t = useI18n()
  89. type EditingProperties = {
  90. collection: HoppCollection<HoppRESTRequest> | TeamCollection | null
  91. isRootCollection: boolean
  92. path: string
  93. inheritedProperties: HoppInheritedProperty | undefined
  94. }
  95. const props = withDefaults(
  96. defineProps<{
  97. show: boolean
  98. loadingState: boolean
  99. editingProperties: EditingProperties | null
  100. }>(),
  101. {
  102. show: false,
  103. loadingState: false,
  104. editingProperties: null,
  105. }
  106. )
  107. const emit = defineEmits<{
  108. (e: "set-collection-properties", newCollection: any): void
  109. (e: "hide-modal"): void
  110. }>()
  111. const editableCollection = ref({
  112. body: {
  113. contentType: null,
  114. body: null,
  115. },
  116. headers: [],
  117. auth: {
  118. authType: "inherit",
  119. authActive: false,
  120. },
  121. }) as any
  122. const selectedOptionTab = ref("headers")
  123. const changeOptionTab = (tab: RESTOptionTabs) => {
  124. selectedOptionTab.value = tab
  125. }
  126. watch(
  127. () => props.show,
  128. (show) => {
  129. if (show && props.editingProperties?.collection) {
  130. editableCollection.value.auth = clone(
  131. props.editingProperties.collection.auth
  132. )
  133. editableCollection.value.headers = clone(
  134. props.editingProperties.collection.headers
  135. )
  136. } else {
  137. editableCollection.value = {
  138. body: {
  139. contentType: null,
  140. body: null,
  141. },
  142. headers: [],
  143. auth: {
  144. authType: "inherit",
  145. authActive: false,
  146. },
  147. }
  148. }
  149. }
  150. )
  151. const saveEditedCollection = () => {
  152. if (!props.editingProperties) return
  153. const finalCollection = clone(editableCollection.value)
  154. delete finalCollection.body
  155. const collection = {
  156. path: props.editingProperties.path,
  157. collection: {
  158. ...props.editingProperties.collection,
  159. ...finalCollection,
  160. },
  161. isRootCollection: props.editingProperties.isRootCollection,
  162. }
  163. emit("set-collection-properties", collection)
  164. }
  165. const hideModal = () => {
  166. emit("hide-modal")
  167. }
  168. </script>