Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: init backend for drag and drop requests on team collections - fixed #2005

liyasthomas76cbd99df8f1
diff --git a/packages/hoppscotch-app/components/collections/teams/Collection.vue b/packages/hoppscotch-app/components/collections/teams/Collection.vue
index 29557b4ec..67256025b 100644
--- a/packages/hoppscotch-app/components/collections/teams/Collection.vue
+++ b/packages/hoppscotch-app/components/collections/teams/Collection.vue
@@ -187,6 +187,8 @@
<script>
import { defineComponent } from "@nuxtjs/composition-api"
+import * as E from "fp-ts/Either"
+import { moveRESTTeamRequest } from "~/helpers/backend/mutations/TeamRequest"
export default defineComponent({
props: {
@@ -258,11 +260,15 @@ export default defineComponent({
expandCollection(collectionID) {
this.$emit("expand-collection", collectionID)
},
- dropEvent({ dataTransfer }) {
+ async dropEvent({ dataTransfer }) {
this.dragging = !this.dragging
const requestIndex = dataTransfer.getData("requestIndex")
- console.log(requestIndex, this.collection.id)
- // moveRESTTeamRequest(`${this.collectionIndex}`, requestIndex)
+ const moveRequestResult = await moveRESTTeamRequest(
+ requestIndex,
+ this.collection.id
+ )()
+ if (E.isLeft(moveRequestResult))
+ this.$toast.error(this.$t("error.something_went_wrong"))
},
removeRequest({ collectionIndex, folderName, requestIndex }) {
this.$emit("remove-request", {
diff --git a/packages/hoppscotch-app/components/collections/teams/Folder.vue b/packages/hoppscotch-app/components/collections/teams/Folder.vue
index 8d5a8d718..57b435369 100644
--- a/packages/hoppscotch-app/components/collections/teams/Folder.vue
+++ b/packages/hoppscotch-app/components/collections/teams/Folder.vue
@@ -166,6 +166,8 @@
<script>
import { defineComponent } from "@nuxtjs/composition-api"
+import * as E from "fp-ts/Either"
+import { moveRESTTeamRequest } from "~/helpers/backend/mutations/TeamRequest"
import * as teamUtils from "~/helpers/teams/utils"
export default defineComponent({
@@ -245,11 +247,15 @@ export default defineComponent({
expandCollection(collectionID) {
this.$emit("expand-collection", collectionID)
},
- dropEvent({ dataTransfer }) {
+ async dropEvent({ dataTransfer }) {
this.dragging = !this.dragging
const requestIndex = dataTransfer.getData("requestIndex")
- console.log(requestIndex, this.folder.id)
- // moveRESTTeamRequest(this.folder.id, requestIndex)
+ const moveRequestResult = await moveRESTTeamRequest(
+ requestIndex,
+ this.folder.id
+ )()
+ if (E.isLeft(moveRequestResult))
+ this.$toast.error(this.$t("error.something_went_wrong"))
},
removeRequest({ collectionIndex, folderName, requestIndex }) {
this.$emit("remove-request", {
diff --git a/packages/hoppscotch-app/components/collections/teams/Request.vue b/packages/hoppscotch-app/components/collections/teams/Request.vue
index cce95e621..0484faec6 100644
--- a/packages/hoppscotch-app/components/collections/teams/Request.vue
+++ b/packages/hoppscotch-app/components/collections/teams/Request.vue
@@ -179,7 +179,6 @@ export default defineComponent({
dragStart({ dataTransfer }) {
this.dragging = !this.dragging
dataTransfer.setData("requestIndex", this.requestIndex)
- console.log(dataTransfer)
},
removeRequest() {
this.$emit("remove-request", {
diff --git a/packages/hoppscotch-app/helpers/backend/gql/mutations/MoveRESTTeamRquest.graphql b/packages/hoppscotch-app/helpers/backend/gql/mutations/MoveRESTTeamRquest.graphql
new file mode 100644
index 000000000..3c0bc3b46
--- /dev/null
+++ b/packages/hoppscotch-app/helpers/backend/gql/mutations/MoveRESTTeamRquest.graphql
@@ -0,0 +1,5 @@
+mutation MoveRESTTeamRequest($requestID: ID!, $collectionID: ID!) {
+ moveRequest(requestID: $requestID, destCollID: $collectionID) {
+ id
+ }
+}
diff --git a/packages/hoppscotch-app/helpers/backend/mutations/TeamRequest.ts b/packages/hoppscotch-app/helpers/backend/mutations/TeamRequest.ts
new file mode 100644
index 000000000..430ecaf55
--- /dev/null
+++ b/packages/hoppscotch-app/helpers/backend/mutations/TeamRequest.ts
@@ -0,0 +1,20 @@
+import { runMutation } from "../GQLClient"
+import {
+ MoveRestTeamRequestDocument,
+ MoveRestTeamRequestMutation,
+ MoveRestTeamRequestMutationVariables,
+} from "../graphql"
+
+type MoveRestTeamRequestErrors =
+ | "team_req/not_found"
+ | "team_req/invalid_target_id"
+
+export const moveRESTTeamRequest = (requestID: string, collectionID: string) =>
+ runMutation<
+ MoveRestTeamRequestMutation,
+ MoveRestTeamRequestMutationVariables,
+ MoveRestTeamRequestErrors
+ >(MoveRestTeamRequestDocument, {
+ requestID,
+ collectionID,
+ })