123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- <template>
- <div :class="{ 'rounded border border-divider': saveRequest }">
- <div
- class="sticky z-10 flex flex-col border-b rounded-t divide-y divide-dividerLight bg-primary border-dividerLight"
- :style="saveRequest ? 'top: calc(-1 * var(--font-size-body))' : 'top: 0'"
- >
- <div v-if="!saveRequest" class="flex flex-col">
- <input
- v-model="filterText"
- type="search"
- autocomplete="off"
- :placeholder="$t('action.search')"
- class="py-2 pl-4 pr-2 bg-transparent"
- :disabled="collectionsType.type == 'team-collections'"
- />
- </div>
- <CollectionsChooseType
- :collections-type="collectionsType"
- :show="showTeamCollections"
- :doc="doc"
- @update-collection-type="updateCollectionType"
- @update-selected-team="updateSelectedTeam"
- />
- <div class="flex justify-between flex-1">
- <ButtonSecondary
- v-if="
- collectionsType.type == 'team-collections' &&
- (collectionsType.selectedTeam == undefined ||
- collectionsType.selectedTeam.myRole == 'VIEWER')
- "
- v-tippy="{ theme: 'tooltip' }"
- disabled
- class="!rounded-none"
- svg="plus"
- :title="$t('team.no_access')"
- :label="$t('action.new')"
- />
- <ButtonSecondary
- v-else
- svg="plus"
- :label="$t('action.new')"
- class="!rounded-none"
- @click.native="displayModalAdd(true)"
- />
- <span class="flex">
- <ButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- to="https://docs.hoppscotch.io/features/collections"
- blank
- :title="$t('app.wiki')"
- svg="help-circle"
- />
- <ButtonSecondary
- v-if="!saveRequest"
- v-tippy="{ theme: 'tooltip' }"
- :disabled="
- collectionsType.type == 'team-collections' &&
- collectionsType.selectedTeam == undefined
- "
- svg="archive"
- :title="$t('modal.import_export')"
- @click.native="displayModalImportExport(true)"
- />
- </span>
- </div>
- </div>
- <div class="flex flex-col flex-1">
- <component
- :is="
- collectionsType.type == 'my-collections'
- ? 'CollectionsMyCollection'
- : 'CollectionsTeamsCollection'
- "
- v-for="(collection, index) in filteredCollections"
- :key="`collection-${index}`"
- :collection-index="index"
- :collection="collection"
- :doc="doc"
- :is-filtered="filterText.length > 0"
- :selected="selected.some((coll) => coll == collection)"
- :save-request="saveRequest"
- :collections-type="collectionsType"
- :picked="picked"
- :loading-collection-i-ds="loadingCollectionIDs"
- @edit-collection="editCollection(collection, index)"
- @add-request="addRequest($event)"
- @add-folder="addFolder($event)"
- @edit-folder="editFolder($event)"
- @edit-request="editRequest($event)"
- @duplicate-request="duplicateRequest($event)"
- @update-team-collections="updateTeamCollections"
- @select-collection="$emit('use-collection', collection)"
- @unselect-collection="$emit('remove-collection', collection)"
- @select="$emit('select', $event)"
- @expand-collection="expandCollection"
- @remove-collection="removeCollection"
- @remove-request="removeRequest"
- @remove-folder="removeFolder"
- />
- </div>
- <div
- v-if="loadingCollectionIDs.includes('root')"
- class="flex flex-col items-center justify-center p-4"
- >
- <SmartSpinner class="my-4" />
- <span class="text-secondaryLight">{{ $t("state.loading") }}</span>
- </div>
- <div
- v-else-if="filteredCollections.length === 0 && filterText.length === 0"
- class="flex flex-col items-center justify-center p-4 text-secondaryLight"
- >
- <img
- :src="`/images/states/${$colorMode.value}/pack.svg`"
- loading="lazy"
- class="inline-flex flex-col object-contain object-center w-16 h-16 my-4"
- :alt="$t('empty.collections')"
- />
- <span class="pb-4 text-center">
- {{ $t("empty.collections") }}
- </span>
- <ButtonSecondary
- v-if="
- collectionsType.type == 'team-collections' &&
- (collectionsType.selectedTeam == undefined ||
- collectionsType.selectedTeam.myRole == 'VIEWER')
- "
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('team.no_access')"
- :label="$t('add.new')"
- class="mb-4"
- filled
- />
- <ButtonSecondary
- v-else
- :label="$t('add.new')"
- filled
- class="mb-4"
- @click.native="displayModalAdd(true)"
- />
- </div>
- <div
- v-if="filterText.length !== 0 && filteredCollections.length === 0"
- class="flex flex-col items-center justify-center p-4 text-secondaryLight"
- >
- <i class="pb-2 opacity-75 material-icons">manage_search</i>
- <span class="my-2 text-center">
- {{ $t("state.nothing_found") }} "{{ filterText }}"
- </span>
- </div>
- <CollectionsAdd
- :show="showModalAdd"
- :loading-state="modalLoadingState"
- @submit="addNewRootCollection"
- @hide-modal="displayModalAdd(false)"
- />
- <CollectionsEdit
- :show="showModalEdit"
- :editing-collection-name="
- editingCollection
- ? editingCollection.name || editingCollection.title
- : ''
- "
- :loading-state="modalLoadingState"
- @hide-modal="displayModalEdit(false)"
- @submit="updateEditingCollection"
- />
- <CollectionsAddRequest
- :show="showModalAddRequest"
- :folder="editingFolder"
- :folder-path="editingFolderPath"
- :loading-state="modalLoadingState"
- @add-request="onAddRequest($event)"
- @hide-modal="displayModalAddRequest(false)"
- />
- <CollectionsAddFolder
- :show="showModalAddFolder"
- :folder="editingFolder"
- :folder-path="editingFolderPath"
- :loading-state="modalLoadingState"
- @add-folder="onAddFolder($event)"
- @hide-modal="displayModalAddFolder(false)"
- />
- <CollectionsEditFolder
- :show="showModalEditFolder"
- :editing-folder-name="
- editingFolder ? editingFolder.name || editingFolder.title : ''
- "
- :loading-state="modalLoadingState"
- @submit="updateEditingFolder"
- @hide-modal="displayModalEditFolder(false)"
- />
- <CollectionsEditRequest
- :show="showModalEditRequest"
- :editing-request-name="editingRequest ? editingRequest.name : ''"
- :loading-state="modalLoadingState"
- @submit="updateEditingRequest"
- @hide-modal="displayModalEditRequest(false)"
- />
- <CollectionsImportExport
- :show="showModalImportExport"
- :collections-type="collectionsType"
- @hide-modal="displayModalImportExport(false)"
- @update-team-collections="updateTeamCollections"
- />
- <SmartConfirmModal
- :show="showConfirmModal"
- :title="confirmModalTitle"
- :loading-state="modalLoadingState"
- @hide-modal="showConfirmModal = false"
- @resolve="resolveConfirmModal"
- />
- </div>
- </template>
- <script>
- import cloneDeep from "lodash/cloneDeep"
- import { defineComponent } from "@nuxtjs/composition-api"
- import { makeCollection } from "@hoppscotch/data"
- import * as E from "fp-ts/Either"
- import CollectionsMyCollection from "./my/Collection.vue"
- import CollectionsTeamsCollection from "./teams/Collection.vue"
- import { currentUser$ } from "~/helpers/fb/auth"
- import TeamCollectionAdapter from "~/helpers/teams/TeamCollectionAdapter"
- import {
- restCollections$,
- addRESTCollection,
- editRESTCollection,
- addRESTFolder,
- removeRESTCollection,
- removeRESTFolder,
- editRESTFolder,
- removeRESTRequest,
- editRESTRequest,
- saveRESTRequestAs,
- } from "~/newstore/collections"
- import {
- setRESTRequest,
- getRESTRequest,
- getRESTSaveContext,
- } from "~/newstore/RESTSession"
- import {
- useReadonlyStream,
- useStreamSubscriber,
- } from "~/helpers/utils/composables"
- import { runMutation } from "~/helpers/backend/GQLClient"
- import {
- CreateChildCollectionDocument,
- CreateNewRootCollectionDocument,
- CreateRequestInCollectionDocument,
- DeleteCollectionDocument,
- DeleteRequestDocument,
- RenameCollectionDocument,
- UpdateRequestDocument,
- } from "~/helpers/backend/graphql"
- export default defineComponent({
- components: {
- CollectionsMyCollection,
- CollectionsTeamsCollection,
- },
- props: {
- doc: Boolean,
- selected: { type: Array, default: () => [] },
- saveRequest: Boolean,
- picked: { type: Object, default: () => {} },
- },
- setup() {
- const { subscribeToStream } = useStreamSubscriber()
- return {
- subscribeTo: subscribeToStream,
- collections: useReadonlyStream(restCollections$, []),
- currentUser: useReadonlyStream(currentUser$, null),
- }
- },
- data() {
- return {
- showModalAdd: false,
- showModalEdit: false,
- showModalImportExport: false,
- showModalAddRequest: false,
- showModalAddFolder: false,
- showModalEditFolder: false,
- showModalEditRequest: false,
- showConfirmModal: false,
- modalLoadingState: false,
- editingCollection: undefined,
- editingCollectionIndex: undefined,
- editingCollectionID: undefined,
- editingFolder: undefined,
- editingFolderName: undefined,
- editingFolderIndex: undefined,
- editingFolderPath: undefined,
- editingRequest: undefined,
- editingRequestIndex: undefined,
- confirmModalTitle: undefined,
- filterText: "",
- collectionsType: {
- type: "my-collections",
- selectedTeam: undefined,
- },
- teamCollectionAdapter: new TeamCollectionAdapter(null),
- teamCollectionsNew: [],
- loadingCollectionIDs: [],
- }
- },
- computed: {
- showTeamCollections() {
- if (this.currentUser == null) {
- return false
- }
- return true
- },
- filteredCollections() {
- const collections =
- this.collectionsType.type === "my-collections"
- ? this.collections
- : this.teamCollectionsNew
- if (!this.filterText) {
- return collections
- }
- if (this.collectionsType.type === "team-collections") {
- return []
- }
- const filterText = this.filterText.toLowerCase()
- const filteredCollections = []
- for (const collection of collections) {
- const filteredRequests = []
- const filteredFolders = []
- for (const request of collection.requests) {
- if (request.name.toLowerCase().includes(filterText))
- filteredRequests.push(request)
- }
- for (const folder of this.collectionsType.type === "team-collections"
- ? collection.children
- : collection.folders) {
- const filteredFolderRequests = []
- for (const request of folder.requests) {
- if (request.name.toLowerCase().includes(filterText))
- filteredFolderRequests.push(request)
- }
- if (filteredFolderRequests.length > 0) {
- const filteredFolder = Object.assign({}, folder)
- filteredFolder.requests = filteredFolderRequests
- filteredFolders.push(filteredFolder)
- }
- }
- if (
- filteredRequests.length + filteredFolders.length > 0 ||
- collection.name.toLowerCase().includes(filterText)
- ) {
- const filteredCollection = Object.assign({}, collection)
- filteredCollection.requests = filteredRequests
- filteredCollection.folders = filteredFolders
- filteredCollections.push(filteredCollection)
- }
- }
- return filteredCollections
- },
- },
- watch: {
- "collectionsType.type": function emitstuff() {
- this.$emit("update-collection", this.$data.collectionsType.type)
- },
- "collectionsType.selectedTeam"(value) {
- if (value?.id) this.teamCollectionAdapter.changeTeamID(value.id)
- },
- currentUser(newValue) {
- if (!newValue) this.updateCollectionType("my-collections")
- },
- },
- mounted() {
- this.subscribeTo(this.teamCollectionAdapter.collections$, (colls) => {
- this.teamCollectionsNew = cloneDeep(colls)
- })
- this.subscribeTo(
- this.teamCollectionAdapter.loadingCollections$,
- (collectionsIDs) => {
- this.loadingCollectionIDs = collectionsIDs
- }
- )
- },
- methods: {
- updateTeamCollections() {
- // TODO: Remove this at some point
- },
- updateSelectedTeam(newSelectedTeam) {
- this.collectionsType.selectedTeam = newSelectedTeam
- this.$emit("update-coll-type", this.collectionsType)
- },
- updateCollectionType(newCollectionType) {
- this.collectionsType.type = newCollectionType
- this.$emit("update-coll-type", this.collectionsType)
- },
- // Intented to be called by the CollectionAdd modal submit event
- addNewRootCollection(name) {
- if (this.collectionsType.type === "my-collections") {
- addRESTCollection(
- makeCollection({
- name,
- folders: [],
- requests: [],
- })
- )
- this.displayModalAdd(false)
- } else if (
- this.collectionsType.type === "team-collections" &&
- this.collectionsType.selectedTeam.myRole !== "VIEWER"
- ) {
- this.modalLoadingState = true
- runMutation(CreateNewRootCollectionDocument, {
- title: name,
- teamID: this.collectionsType.selectedTeam.id,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- if (result.left.error === "team_coll/short_title")
- this.$toast.error(this.$t("collection.name_length_insufficient"))
- else this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("collection.created"))
- this.displayModalAdd(false)
- }
- })
- }
- },
- // Intented to be called by CollectionEdit modal submit event
- updateEditingCollection(newName) {
- if (!newName) {
- this.$toast.error(this.$t("collection.invalid_name"))
- return
- }
- if (this.collectionsType.type === "my-collections") {
- const collectionUpdated = {
- ...this.editingCollection,
- name: newName,
- }
- editRESTCollection(this.editingCollectionIndex, collectionUpdated)
- this.displayModalEdit(false)
- } else if (
- this.collectionsType.type === "team-collections" &&
- this.collectionsType.selectedTeam.myRole !== "VIEWER"
- ) {
- this.modalLoadingState = true
- runMutation(RenameCollectionDocument, {
- collectionID: this.editingCollection.id,
- newTitle: newName,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("collection.renamed"))
- this.displayModalEdit(false)
- }
- })
- }
- },
- // Intended to be called by CollectionEditFolder modal submit event
- updateEditingFolder(name) {
- if (this.collectionsType.type === "my-collections") {
- editRESTFolder(this.editingFolderPath, { ...this.editingFolder, name })
- this.displayModalEditFolder(false)
- } else if (
- this.collectionsType.type === "team-collections" &&
- this.collectionsType.selectedTeam.myRole !== "VIEWER"
- ) {
- this.modalLoadingState = true
- runMutation(RenameCollectionDocument, {
- collectionID: this.editingFolder.id,
- newTitle: name,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- if (result.left.error === "team_coll/short_title")
- this.$toast.error(this.$t("folder.name_length_insufficient"))
- else this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("folder.renamed"))
- this.displayModalEditFolder(false)
- }
- })
- }
- },
- // Intented to by called by CollectionsEditRequest modal submit event
- updateEditingRequest(requestUpdateData) {
- const saveCtx = getRESTSaveContext()
- const requestUpdated = {
- ...this.editingRequest,
- name: requestUpdateData.name || this.editingRequest.name,
- }
- if (this.collectionsType.type === "my-collections") {
- // Update REST Session with the updated state
- if (
- saveCtx &&
- saveCtx.originLocation === "user-collection" &&
- saveCtx.requestIndex === this.editingRequestIndex &&
- saveCtx.folderPath === this.editingFolderPath
- ) {
- setRESTRequest({
- ...getRESTRequest(),
- name: requestUpdateData.name,
- })
- }
- editRESTRequest(
- this.editingFolderPath,
- this.editingRequestIndex,
- requestUpdated
- )
- this.displayModalEditRequest(false)
- } else if (
- this.collectionsType.type === "team-collections" &&
- this.collectionsType.selectedTeam.myRole !== "VIEWER"
- ) {
- this.modalLoadingState = true
- const requestName = requestUpdateData.name || this.editingRequest.name
- // Update REST Session with the updated state
- if (
- saveCtx &&
- saveCtx.originLocation === "team-collection" &&
- saveCtx.requestID === this.editingRequestIndex
- ) {
- setRESTRequest({
- ...getRESTRequest(),
- name: requestUpdateData.name,
- })
- }
- runMutation(UpdateRequestDocument, {
- data: {
- request: JSON.stringify(requestUpdated),
- title: requestName,
- },
- requestID: this.editingRequestIndex,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("request.renamed"))
- this.$emit("update-team-collections")
- this.displayModalEditRequest(false)
- }
- })
- }
- },
- displayModalAdd(shouldDisplay) {
- this.showModalAdd = shouldDisplay
- },
- displayModalEdit(shouldDisplay) {
- this.showModalEdit = shouldDisplay
- if (!shouldDisplay) this.resetSelectedData()
- },
- displayModalImportExport(shouldDisplay) {
- this.showModalImportExport = shouldDisplay
- },
- displayModalAddRequest(shouldDisplay) {
- this.showModalAddRequest = shouldDisplay
- if (!shouldDisplay) this.resetSelectedData()
- },
- displayModalAddFolder(shouldDisplay) {
- this.showModalAddFolder = shouldDisplay
- if (!shouldDisplay) this.resetSelectedData()
- },
- displayModalEditFolder(shouldDisplay) {
- this.showModalEditFolder = shouldDisplay
- if (!shouldDisplay) this.resetSelectedData()
- },
- displayModalEditRequest(shouldDisplay) {
- this.showModalEditRequest = shouldDisplay
- if (!shouldDisplay) this.resetSelectedData()
- },
- displayConfirmModal(shouldDisplay) {
- this.showConfirmModal = shouldDisplay
- if (!shouldDisplay) this.resetSelectedData()
- },
- editCollection(collection, collectionIndex) {
- this.$data.editingCollection = collection
- this.$data.editingCollectionIndex = collectionIndex
- this.displayModalEdit(true)
- },
- onAddFolder({ name, folder, path }) {
- if (this.collectionsType.type === "my-collections") {
- addRESTFolder(name, path)
- this.displayModalAddFolder(false)
- } else if (
- this.collectionsType.type === "team-collections" &&
- this.collectionsType.selectedTeam.myRole !== "VIEWER"
- ) {
- this.modalLoadingState = true
- runMutation(CreateChildCollectionDocument, {
- childTitle: name,
- collectionID: folder.id,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- if (result.left.error === "team_coll/short_title")
- this.$toast.error(this.$t("folder.name_length_insufficient"))
- else this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("folder.created"))
- this.displayModalAddFolder(false)
- this.$emit("update-team-collections")
- }
- })
- }
- },
- addFolder(payload) {
- const { folder, path } = payload
- this.$data.editingFolder = folder
- this.$data.editingFolderPath = path
- this.displayModalAddFolder(true)
- },
- editFolder(payload) {
- const { collectionIndex, folder, folderIndex, folderPath } = payload
- this.$data.editingCollectionIndex = collectionIndex
- this.$data.editingFolder = folder
- this.$data.editingFolderIndex = folderIndex
- this.$data.editingFolderPath = folderPath
- this.$data.collectionsType = this.collectionsType
- this.displayModalEditFolder(true)
- },
- editRequest(payload) {
- const {
- collectionIndex,
- folderIndex,
- folderName,
- request,
- requestIndex,
- folderPath,
- } = payload
- this.$data.editingCollectionIndex = collectionIndex
- this.$data.editingFolderIndex = folderIndex
- this.$data.editingFolderName = folderName
- this.$data.editingRequest = request
- this.$data.editingRequestIndex = requestIndex
- this.editingFolderPath = folderPath
- this.$emit("select-request", requestIndex)
- this.displayModalEditRequest(true)
- },
- resetSelectedData() {
- this.$data.editingCollection = undefined
- this.$data.editingCollectionIndex = undefined
- this.$data.editingCollectionID = undefined
- this.$data.editingFolder = undefined
- this.$data.editingFolderPath = undefined
- this.$data.editingFolderIndex = undefined
- this.$data.editingRequest = undefined
- this.$data.editingRequestIndex = undefined
- this.$data.confirmModalTitle = undefined
- },
- expandCollection(collectionID) {
- this.teamCollectionAdapter.expandCollection(collectionID)
- },
- removeCollection({ collectionIndex, collectionID }) {
- this.$data.editingCollectionIndex = collectionIndex
- this.$data.editingCollectionID = collectionID
- this.confirmModalTitle = `${this.$t("confirm.remove_collection")}`
- this.displayConfirmModal(true)
- },
- onRemoveCollection() {
- const collectionIndex = this.$data.editingCollectionIndex
- const collectionID = this.$data.editingCollectionID
- if (this.collectionsType.type === "my-collections") {
- // Cancel pick if picked collection is deleted
- if (
- this.picked &&
- this.picked.pickedType === "my-collection" &&
- this.picked.collectionIndex === collectionIndex
- ) {
- this.$emit("select", { picked: null })
- }
- removeRESTCollection(collectionIndex)
- this.$toast.success(this.$t("state.deleted"))
- this.displayConfirmModal(false)
- } else if (this.collectionsType.type === "team-collections") {
- this.modalLoadingState = true
- // Cancel pick if picked collection is deleted
- if (
- this.picked &&
- this.picked.pickedType === "teams-collection" &&
- this.picked.collectionID === collectionID
- ) {
- this.$emit("select", { picked: null })
- }
- if (this.collectionsType.selectedTeam.myRole !== "VIEWER") {
- runMutation(DeleteCollectionDocument, {
- collectionID,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("state.deleted"))
- this.displayConfirmModal(false)
- }
- })
- }
- }
- },
- removeFolder({ collectionID, folder, folderPath }) {
- this.$data.editingCollectionID = collectionID
- this.$data.editingFolder = folder
- this.$data.editingFolderPath = folderPath
- this.confirmModalTitle = `${this.$t("confirm.remove_folder")}`
- this.displayConfirmModal(true)
- },
- onRemoveFolder() {
- const folder = this.$data.editingFolder
- const folderPath = this.$data.editingFolderPath
- if (this.collectionsType.type === "my-collections") {
- // Cancel pick if picked folder was deleted
- if (
- this.picked &&
- this.picked.pickedType === "my-folder" &&
- this.picked.folderPath === folderPath
- ) {
- this.$emit("select", { picked: null })
- }
- removeRESTFolder(folderPath)
- this.$toast.success(this.$t("state.deleted"))
- this.displayConfirmModal(false)
- } else if (this.collectionsType.type === "team-collections") {
- this.modalLoadingState = true
- // Cancel pick if picked collection folder was deleted
- if (
- this.picked &&
- this.picked.pickedType === "teams-folder" &&
- this.picked.folderID === folder.id
- ) {
- this.$emit("select", { picked: null })
- }
- if (this.collectionsType.selectedTeam.myRole !== "VIEWER") {
- runMutation(DeleteCollectionDocument, {
- collectionID: folder.id,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- this.$toast.error(`${this.$t("error.something_went_wrong")}`)
- console.error(result.left.error)
- } else {
- this.$toast.success(`${this.$t("state.deleted")}`)
- this.displayConfirmModal(false)
- this.updateTeamCollections()
- }
- })
- }
- }
- },
- removeRequest({ requestIndex, folderPath }) {
- this.$data.editingRequestIndex = requestIndex
- this.$data.editingFolderPath = folderPath
- this.confirmModalTitle = `${this.$t("confirm.remove_request")}`
- this.displayConfirmModal(true)
- },
- onRemoveRequest() {
- const requestIndex = this.$data.editingRequestIndex
- const folderPath = this.$data.editingFolderPath
- if (this.collectionsType.type === "my-collections") {
- // Cancel pick if the picked item is being deleted
- if (
- this.picked &&
- this.picked.pickedType === "my-request" &&
- this.picked.folderPath === folderPath &&
- this.picked.requestIndex === requestIndex
- ) {
- this.$emit("select", { picked: null })
- }
- removeRESTRequest(folderPath, requestIndex)
- this.$toast.success(this.$t("state.deleted"))
- this.displayConfirmModal(false)
- } else if (this.collectionsType.type === "team-collections") {
- this.modalLoadingState = true
- // Cancel pick if the picked item is being deleted
- if (
- this.picked &&
- this.picked.pickedType === "teams-request" &&
- this.picked.requestID === requestIndex
- ) {
- this.$emit("select", { picked: null })
- }
- runMutation(DeleteRequestDocument, {
- requestID: requestIndex,
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- this.$toast.success(this.$t("state.deleted"))
- this.displayConfirmModal(false)
- }
- })
- }
- },
- addRequest(payload) {
- // TODO: check if the request being worked on
- // is being overwritten (selected or not)
- const { folder, path } = payload
- this.$data.editingFolder = folder
- this.$data.editingFolderPath = path
- this.displayModalAddRequest(true)
- },
- onAddRequest({ name, folder, path }) {
- const newRequest = {
- ...cloneDeep(getRESTRequest()),
- name,
- }
- if (this.collectionsType.type === "my-collections") {
- const insertionIndex = saveRESTRequestAs(path, newRequest)
- // point to it
- setRESTRequest(newRequest, {
- originLocation: "user-collection",
- folderPath: path,
- requestIndex: insertionIndex,
- })
- this.displayModalAddRequest(false)
- } else if (
- this.collectionsType.type === "team-collections" &&
- this.collectionsType.selectedTeam.myRole !== "VIEWER"
- ) {
- this.modalLoadingState = true
- runMutation(CreateRequestInCollectionDocument, {
- collectionID: folder.id,
- data: {
- request: JSON.stringify(newRequest),
- teamID: this.collectionsType.selectedTeam.id,
- title: name,
- },
- })().then((result) => {
- this.modalLoadingState = false
- if (E.isLeft(result)) {
- this.$toast.error(this.$t("error.something_went_wrong"))
- console.error(result.left.error)
- } else {
- const { createRequestInCollection } = result.right
- // point to it
- setRESTRequest(newRequest, {
- originLocation: "team-collection",
- requestID: createRequestInCollection.id,
- collectionID: createRequestInCollection.collection.id,
- teamID: createRequestInCollection.collection.team.id,
- })
- this.displayModalAddRequest(false)
- }
- })
- }
- },
- duplicateRequest({ folderPath, request, collectionID }) {
- if (this.collectionsType.type === "team-collections") {
- const newReq = {
- ...cloneDeep(request),
- name: `${request.name} - ${this.$t("action.duplicate")}`,
- }
- // Error handling ?
- runMutation(CreateRequestInCollectionDocument, {
- collectionID,
- data: {
- request: JSON.stringify(newReq),
- teamID: this.collectionsType.selectedTeam.id,
- title: `${request.name} - ${this.$t("action.duplicate")}`,
- },
- })()
- } else if (this.collectionsType.type === "my-collections") {
- saveRESTRequestAs(folderPath, {
- ...cloneDeep(request),
- name: `${request.name} - ${this.$t("action.duplicate")}`,
- })
- }
- },
- resolveConfirmModal(title) {
- if (title === `${this.$t("confirm.remove_collection")}`)
- this.onRemoveCollection()
- else if (title === `${this.$t("confirm.remove_request")}`)
- this.onRemoveRequest()
- else if (title === `${this.$t("confirm.remove_folder")}`)
- this.onRemoveFolder()
- else {
- console.error(
- `Confirm modal title ${title} is not handled by the component`
- )
- this.$toast.error(this.$t("error.something_went_wrong"))
- this.displayConfirmModal(false)
- }
- },
- },
- })
- // request inside folder is not being deleted, you dumb fuck
- </script>
|