Folder.vue 7.1 KB

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