Folder.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="flex flex-col" :class="[{ 'bg-primaryLight': dragging }]">
  3. <div
  4. class="flex items-stretch group"
  5. @dragover.prevent
  6. @drop.prevent="dropEvent"
  7. @dragover="dragging = true"
  8. @drop="dragging = false"
  9. @dragleave="dragging = false"
  10. @dragend="dragging = false"
  11. @contextmenu.prevent="$refs.options.tippy().show()"
  12. >
  13. <span
  14. class="cursor-pointer flex px-4 items-center justify-center"
  15. @click="toggleShowChildren()"
  16. >
  17. <SmartIcon
  18. class="svg-icons"
  19. :class="{ 'text-green-500': isSelected }"
  20. :name="getCollectionIcon"
  21. />
  22. </span>
  23. <span
  24. class="cursor-pointer flex flex-1 min-w-0 py-2 pr-2 transition group-hover:text-secondaryDark"
  25. @click="toggleShowChildren()"
  26. >
  27. <span class="truncate">
  28. {{ folder.name ? folder.name : folder.title }}
  29. </span>
  30. </span>
  31. <div class="flex">
  32. <ButtonSecondary
  33. v-tippy="{ theme: 'tooltip' }"
  34. svg="folder-plus"
  35. :title="$t('folder.new')"
  36. class="hidden group-hover:inline-flex"
  37. @click.native="$emit('add-folder', { folder, path: folderPath })"
  38. />
  39. <span>
  40. <tippy
  41. ref="options"
  42. interactive
  43. trigger="click"
  44. theme="popover"
  45. arrow
  46. >
  47. <template #trigger>
  48. <ButtonSecondary
  49. v-tippy="{ theme: 'tooltip' }"
  50. :title="$t('action.more')"
  51. svg="more-vertical"
  52. />
  53. </template>
  54. <SmartItem
  55. svg="folder-plus"
  56. :label="`${$t('folder.new')}`"
  57. @click.native="
  58. () => {
  59. $emit('add-folder', { folder, path: folderPath })
  60. $refs.options.tippy().hide()
  61. }
  62. "
  63. />
  64. <SmartItem
  65. svg="edit"
  66. :label="`${$t('action.edit')}`"
  67. @click.native="
  68. () => {
  69. $emit('edit-folder', { folder, folderPath })
  70. $refs.options.tippy().hide()
  71. }
  72. "
  73. />
  74. <SmartItem
  75. svg="trash-2"
  76. color="red"
  77. :label="`${$t('action.delete')}`"
  78. @click.native="
  79. () => {
  80. confirmRemove = true
  81. $refs.options.tippy().hide()
  82. }
  83. "
  84. />
  85. </tippy>
  86. </span>
  87. </div>
  88. </div>
  89. <div v-if="showChildren || isFiltered" class="flex">
  90. <div
  91. class="bg-dividerLight cursor-nsResize flex ml-5.5 transform transition w-1 hover:bg-dividerDark hover:scale-x-125"
  92. @click="toggleShowChildren()"
  93. ></div>
  94. <div class="flex flex-col flex-1 truncate">
  95. <CollectionsGraphqlFolder
  96. v-for="(subFolder, subFolderIndex) in folder.folders"
  97. :key="`subFolder-${String(subFolderIndex)}`"
  98. :picked="picked"
  99. :saving-mode="savingMode"
  100. :folder="subFolder"
  101. :folder-index="subFolderIndex"
  102. :folder-path="`${folderPath}/${String(subFolderIndex)}`"
  103. :collection-index="collectionIndex"
  104. :doc="doc"
  105. :is-filtered="isFiltered"
  106. @add-folder="$emit('add-folder', $event)"
  107. @edit-folder="$emit('edit-folder', $event)"
  108. @edit-request="$emit('edit-request', $event)"
  109. @duplicate-request="$emit('duplicate-request', $event)"
  110. @select="$emit('select', $event)"
  111. />
  112. <CollectionsGraphqlRequest
  113. v-for="(request, index) in folder.requests"
  114. :key="`request-${String(index)}`"
  115. :picked="picked"
  116. :saving-mode="savingMode"
  117. :request="request"
  118. :collection-index="collectionIndex"
  119. :folder-index="folderIndex"
  120. :folder-path="folderPath"
  121. :folder-name="folder.name"
  122. :request-index="index"
  123. :doc="doc"
  124. @edit-request="$emit('edit-request', $event)"
  125. @duplicate-request="$emit('duplicate-request', $event)"
  126. @select="$emit('select', $event)"
  127. />
  128. <div
  129. v-if="
  130. folder.folders &&
  131. folder.folders.length === 0 &&
  132. folder.requests &&
  133. folder.requests.length === 0
  134. "
  135. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  136. >
  137. <img
  138. :src="`/images/states/${$colorMode.value}/pack.svg`"
  139. loading="lazy"
  140. class="flex-col object-contain object-center h-16 mb-4 w-16 inline-flex"
  141. :alt="$t('empty.folder')"
  142. />
  143. <span class="text-center">
  144. {{ $t("empty.folder") }}
  145. </span>
  146. </div>
  147. </div>
  148. </div>
  149. <SmartConfirmModal
  150. :show="confirmRemove"
  151. :title="`${$t('confirm.remove_folder')}`"
  152. @hide-modal="confirmRemove = false"
  153. @resolve="removeFolder"
  154. />
  155. </div>
  156. </template>
  157. <script lang="ts">
  158. import { defineComponent } from "@nuxtjs/composition-api"
  159. import { removeGraphqlFolder, moveGraphqlRequest } from "~/newstore/collections"
  160. export default defineComponent({
  161. name: "Folder",
  162. props: {
  163. picked: { type: Object, default: null },
  164. // Whether the request is in a selectable mode (activates 'select' event)
  165. savingMode: { type: Boolean, default: false },
  166. folder: { type: Object, default: () => {} },
  167. folderIndex: { type: Number, default: null },
  168. collectionIndex: { type: Number, default: null },
  169. folderPath: { type: String, default: null },
  170. doc: Boolean,
  171. isFiltered: Boolean,
  172. },
  173. data() {
  174. return {
  175. showChildren: false,
  176. dragging: false,
  177. confirmRemove: false,
  178. }
  179. },
  180. computed: {
  181. isSelected(): boolean {
  182. return (
  183. this.picked &&
  184. this.picked.pickedType === "gql-my-folder" &&
  185. this.picked.folderPath === this.folderPath
  186. )
  187. },
  188. getCollectionIcon() {
  189. if (this.isSelected) return "check-circle"
  190. else if (!this.showChildren && !this.isFiltered) return "folder"
  191. else if (this.showChildren || this.isFiltered) return "folder-open"
  192. else return "folder"
  193. },
  194. },
  195. methods: {
  196. pick() {
  197. this.$emit("select", {
  198. picked: {
  199. pickedType: "gql-my-folder",
  200. folderPath: this.folderPath,
  201. },
  202. })
  203. },
  204. toggleShowChildren() {
  205. if (this.savingMode) {
  206. this.pick()
  207. }
  208. this.showChildren = !this.showChildren
  209. },
  210. removeFolder() {
  211. // Cancel pick if the picked folder is deleted
  212. if (
  213. this.picked &&
  214. this.picked.pickedType === "gql-my-folder" &&
  215. this.picked.folderPath === this.folderPath
  216. ) {
  217. this.$emit("select", { picked: null })
  218. }
  219. removeGraphqlFolder(this.folderPath)
  220. this.$toast.success(`${this.$t("state.deleted")}`)
  221. },
  222. dropEvent({ dataTransfer }: any) {
  223. this.dragging = !this.dragging
  224. const folderPath = dataTransfer.getData("folderPath")
  225. const requestIndex = dataTransfer.getData("requestIndex")
  226. moveGraphqlRequest(folderPath, requestIndex, this.folderPath)
  227. },
  228. },
  229. })
  230. </script>