Request.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div class="flex flex-col">
  3. <div class="group flex items-center">
  4. <span
  5. class="flex items-center justify-center w-16 px-2 truncate cursor-pointer"
  6. :class="getRequestLabelColor(request.method)"
  7. @click="!doc ? selectRequest() : {}"
  8. >
  9. <SmartIcon
  10. v-if="isSelected"
  11. class="svg-icons"
  12. :class="{ 'text-green-500': isSelected }"
  13. name="check-circle"
  14. />
  15. <span v-else>
  16. {{ request.method }}
  17. </span>
  18. </span>
  19. <span
  20. class="group-hover:text-secondaryDark flex items-center flex-1 min-w-0 py-2 pr-2 transition cursor-pointer"
  21. @click="!doc ? selectRequest() : {}"
  22. >
  23. <span class="truncate"> {{ request.name }} </span>
  24. <span
  25. v-if="
  26. active &&
  27. active.originLocation === 'team-collection' &&
  28. active.requestID === requestIndex
  29. "
  30. class="rounded-full bg-green-500 flex-shrink-0 h-1.5 mx-3 w-1.5"
  31. ></span>
  32. </span>
  33. <div class="flex">
  34. <ButtonSecondary
  35. v-if="!saveRequest && !doc"
  36. v-tippy="{ theme: 'tooltip' }"
  37. svg="rotate-ccw"
  38. :title="$t('action.restore')"
  39. class="group-hover:inline-flex hidden"
  40. @click.native="!doc ? selectRequest() : {}"
  41. />
  42. <span>
  43. <tippy
  44. v-if="collectionsType.selectedTeam.myRole !== 'VIEWER'"
  45. ref="options"
  46. interactive
  47. trigger="click"
  48. theme="popover"
  49. arrow
  50. >
  51. <template #trigger>
  52. <ButtonSecondary
  53. v-tippy="{ theme: 'tooltip' }"
  54. :title="$t('action.more')"
  55. svg="more-vertical"
  56. />
  57. </template>
  58. <SmartItem
  59. svg="edit"
  60. :label="$t('action.edit')"
  61. @click.native="
  62. $emit('edit-request', {
  63. collectionIndex,
  64. folderIndex,
  65. folderName,
  66. request,
  67. requestIndex,
  68. })
  69. $refs.options.tippy().hide()
  70. "
  71. />
  72. <SmartItem
  73. svg="trash-2"
  74. color="red"
  75. :label="$t('action.delete')"
  76. @click.native="
  77. confirmRemove = true
  78. $refs.options.tippy().hide()
  79. "
  80. />
  81. </tippy>
  82. </span>
  83. </div>
  84. </div>
  85. <SmartConfirmModal
  86. :show="confirmRemove"
  87. :title="$t('confirm.remove_request')"
  88. @hide-modal="confirmRemove = false"
  89. @resolve="removeRequest"
  90. />
  91. </div>
  92. </template>
  93. <script lang="ts">
  94. import { defineComponent } from "@nuxtjs/composition-api"
  95. import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest"
  96. import { useReadonlyStream } from "~/helpers/utils/composables"
  97. import {
  98. restSaveContext$,
  99. setRESTRequest,
  100. setRESTSaveContext,
  101. } from "~/newstore/RESTSession"
  102. export default defineComponent({
  103. props: {
  104. request: { type: Object, default: () => {} },
  105. collectionIndex: { type: Number, default: null },
  106. folderIndex: { type: Number, default: null },
  107. folderName: { type: String, default: null },
  108. // eslint-disable-next-line vue/require-default-prop
  109. requestIndex: [Number, String],
  110. doc: Boolean,
  111. saveRequest: Boolean,
  112. collectionsType: { type: Object, default: () => {} },
  113. picked: { type: Object, default: () => {} },
  114. },
  115. setup() {
  116. const active = useReadonlyStream(restSaveContext$, null)
  117. return {
  118. active,
  119. }
  120. },
  121. data() {
  122. return {
  123. requestMethodLabels: {
  124. get: "text-green-500",
  125. post: "text-yellow-500",
  126. put: "text-blue-500",
  127. delete: "text-red-500",
  128. default: "text-gray-500",
  129. },
  130. confirmRemove: false,
  131. }
  132. },
  133. computed: {
  134. isSelected(): boolean {
  135. return (
  136. this.picked &&
  137. this.picked.pickedType === "teams-request" &&
  138. this.picked.requestID === this.requestIndex
  139. )
  140. },
  141. },
  142. methods: {
  143. selectRequest() {
  144. if (
  145. this.active &&
  146. this.active.originLocation === "team-collection" &&
  147. this.active.requestID === this.requestIndex
  148. ) {
  149. setRESTSaveContext(null)
  150. return
  151. }
  152. if (this.$props.saveRequest)
  153. this.$emit("select", {
  154. picked: {
  155. pickedType: "teams-request",
  156. requestID: this.requestIndex,
  157. },
  158. })
  159. else
  160. setRESTRequest(translateToNewRequest(this.request), {
  161. originLocation: "team-collection",
  162. requestID: this.requestIndex as string,
  163. })
  164. },
  165. removeRequest() {
  166. this.$emit("remove-request", {
  167. collectionIndex: this.$props.collectionIndex,
  168. folderName: this.$props.folderName,
  169. requestIndex: this.$props.requestIndex,
  170. })
  171. },
  172. getRequestLabelColor(method: any) {
  173. return (
  174. (this.requestMethodLabels as any)[method.toLowerCase()] ||
  175. this.requestMethodLabels.default
  176. )
  177. },
  178. },
  179. })
  180. </script>