Request.vue 5.2 KB

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