diff --git a/packages/hoppscotch-app/components/collections/AddRequest.vue b/packages/hoppscotch-app/components/collections/AddRequest.vue new file mode 100644 index 000000000..7efbea9f2 --- /dev/null +++ b/packages/hoppscotch-app/components/collections/AddRequest.vue @@ -0,0 +1,92 @@ + + + diff --git a/packages/hoppscotch-app/components/collections/graphql/AddFolder.vue b/packages/hoppscotch-app/components/collections/graphql/AddFolder.vue index a392b9a06..4785b0a05 100644 --- a/packages/hoppscotch-app/components/collections/graphql/AddFolder.vue +++ b/packages/hoppscotch-app/components/collections/graphql/AddFolder.vue @@ -50,12 +50,16 @@ export default defineComponent({ }, methods: { addFolder() { - // TODO: Blocking when name is null ? + if (!this.name) { + this.$toast.error(`${this.$t("folder.name_length_insufficient")}`) + return + } this.$emit("add-folder", { name: this.name, path: this.folderPath || `${this.collectionIndex}`, }) + this.hideModal() }, hideModal() { diff --git a/packages/hoppscotch-app/components/collections/graphql/AddRequest.vue b/packages/hoppscotch-app/components/collections/graphql/AddRequest.vue new file mode 100644 index 000000000..7bb4e908e --- /dev/null +++ b/packages/hoppscotch-app/components/collections/graphql/AddRequest.vue @@ -0,0 +1,87 @@ + + + diff --git a/packages/hoppscotch-app/components/collections/graphql/Collection.vue b/packages/hoppscotch-app/components/collections/graphql/Collection.vue index 293b68241..1a00ffd10 100644 --- a/packages/hoppscotch-app/components/collections/graphql/Collection.vue +++ b/packages/hoppscotch-app/components/collections/graphql/Collection.vue @@ -61,11 +61,26 @@ class="flex flex-col focus:outline-none" tabindex="0" role="menu" + @keyup.r="requestAction.$el.click()" @keyup.n="folderAction.$el.click()" @keyup.e="edit.$el.click()" @keyup.delete="deleteAction.$el.click()" @keyup.escape="options.tippy().hide()" > + (null), options: ref(null), + requestAction: ref(null), folderAction: ref(null), edit: ref(null), deleteAction: ref(null), diff --git a/packages/hoppscotch-app/components/collections/graphql/Folder.vue b/packages/hoppscotch-app/components/collections/graphql/Folder.vue index d52355c06..f5bf2a531 100644 --- a/packages/hoppscotch-app/components/collections/graphql/Folder.vue +++ b/packages/hoppscotch-app/components/collections/graphql/Folder.vue @@ -57,11 +57,24 @@ class="flex flex-col focus:outline-none" tabindex="0" role="menu" + @keyup.r="requestAction.$el.click()" @keyup.n="folderAction.$el.click()" @keyup.e="edit.$el.click()" @keyup.delete="deleteAction.$el.click()" @keyup.escape="options.tippy().hide()" > + (null), options: ref(null), + requestAction: ref(null), folderAction: ref(null), edit: ref(null), deleteAction: ref(null), diff --git a/packages/hoppscotch-app/components/collections/graphql/index.vue b/packages/hoppscotch-app/components/collections/graphql/index.vue index 367185e18..3c0849b68 100644 --- a/packages/hoppscotch-app/components/collections/graphql/index.vue +++ b/packages/hoppscotch-app/components/collections/graphql/index.vue @@ -49,6 +49,7 @@ :is-filtered="filterText.length > 0" :saving-mode="savingMode" @edit-collection="editCollection(collection, index)" + @add-request="addRequest($event)" @add-folder="addFolder($event)" @edit-folder="editFolder($event)" @edit-request="editRequest($event)" @@ -96,6 +97,12 @@ :editing-collection-name="editingCollection ? editingCollection.name : ''" @hide-modal="displayModalEdit(false)" /> + + { if (E.isLeft(result)) { this.$toast.error(this.$t("error.something_went_wrong")) - console.error(e) + console.error(result.left.error) } else { this.$toast.success(this.$t("state.deleted")) } @@ -651,13 +668,68 @@ export default defineComponent({ })().then((result) => { if (E.isLeft(result)) { this.$toast.error(this.$t("error.something_went_wrong")) - console.error(e) + console.error(result.left.error) } else { this.$toast.success(this.$t("state.deleted")) } }) } }, + 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 = { diff --git a/packages/hoppscotch-app/components/collections/my/Collection.vue b/packages/hoppscotch-app/components/collections/my/Collection.vue index af10a719f..ed03fc190 100644 --- a/packages/hoppscotch-app/components/collections/my/Collection.vue +++ b/packages/hoppscotch-app/components/collections/my/Collection.vue @@ -79,12 +79,27 @@ class="flex flex-col focus:outline-none" tabindex="0" role="menu" + @keyup.r="requestAction.$el.click()" @keyup.n="folderAction.$el.click()" @keyup.e="edit.$el.click()" @keyup.delete="deleteAction.$el.click()" @keyup.x="exportAction.$el.click()" @keyup.escape="options.tippy().hide()" > + (null), options: ref(null), + requestAction: ref(null), folderAction: ref(null), edit: ref(null), deleteAction: ref(null), diff --git a/packages/hoppscotch-app/components/collections/my/Folder.vue b/packages/hoppscotch-app/components/collections/my/Folder.vue index cfed4310c..1632f8fd3 100644 --- a/packages/hoppscotch-app/components/collections/my/Folder.vue +++ b/packages/hoppscotch-app/components/collections/my/Folder.vue @@ -57,12 +57,25 @@ class="flex flex-col focus:outline-none" tabindex="0" role="menu" + @keyup.r="requestAction.$el.click()" @keyup.n="folderAction.$el.click()" @keyup.e="edit.$el.click()" @keyup.delete="deleteAction.$el.click()" @keyup.x="exportAction.$el.click()" @keyup.escape="options.tippy().hide()" > + (null), options: ref(null), + requestAction: ref(null), folderAction: ref(null), edit: ref(null), deleteAction: ref(null), diff --git a/packages/hoppscotch-app/components/collections/teams/Collection.vue b/packages/hoppscotch-app/components/collections/teams/Collection.vue index d347ac581..644bd7f78 100644 --- a/packages/hoppscotch-app/components/collections/teams/Collection.vue +++ b/packages/hoppscotch-app/components/collections/teams/Collection.vue @@ -80,12 +80,28 @@ class="flex flex-col focus:outline-none" tabindex="0" role="menu" + @keyup.r="requestAction.$el.click()" @keyup.n="folderAction.$el.click()" @keyup.e="edit.$el.click()" @keyup.delete="deleteAction.$el.click()" @keyup.x="exportAction.$el.click()" @keyup.escape="options.tippy().hide()" > + (null), options: ref(null), + requestAction: ref(null), folderAction: ref(null), edit: ref(null), deleteAction: ref(null), diff --git a/packages/hoppscotch-app/components/collections/teams/Folder.vue b/packages/hoppscotch-app/components/collections/teams/Folder.vue index 843bc7004..f68272582 100644 --- a/packages/hoppscotch-app/components/collections/teams/Folder.vue +++ b/packages/hoppscotch-app/components/collections/teams/Folder.vue @@ -59,12 +59,25 @@ class="flex flex-col focus:outline-none" tabindex="0" role="menu" + @keyup.r="requestAction.$el.click()" @keyup.n="folderAction.$el.click()" @keyup.e="edit.$el.click()" @keyup.delete="deleteAction.$el.click()" @keyup.x="exportAction.$el.click()" @keyup.escape="options.tippy().hide()" > + (null), options: ref(null), + requestAction: ref(null), folderAction: ref(null), edit: ref(null), deleteAction: ref(null), diff --git a/packages/hoppscotch-app/locales/en.json b/packages/hoppscotch-app/locales/en.json index 7c8c31e37..58319455e 100644 --- a/packages/hoppscotch-app/locales/en.json +++ b/packages/hoppscotch-app/locales/en.json @@ -337,6 +337,7 @@ "invalid_name": "Please provide a name for the request", "method": "Method", "name": "Request name", + "new": "New Request", "parameter_list": "Query Parameters", "parameters": "Parameters", "path": "Path",