Folder.vue 7.5 KB

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