diff --git a/components/collections/Add.vue b/components/collections/Add.vue index 3036d7427..e8e98a183 100644 --- a/components/collections/Add.vue +++ b/components/collections/Add.vue @@ -52,7 +52,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -63,6 +66,7 @@ export default { } this.$store.commit("postwoman/addNewCollection", { name: this.$data.name, + flag: "rest", }) this.$emit("hide-modal") this.syncCollections() diff --git a/components/collections/Collection.vue b/components/collections/Collection.vue index 2d43825f1..7baea0377 100644 --- a/components/collections/Collection.vue +++ b/components/collections/Collection.vue @@ -134,7 +134,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -144,6 +147,7 @@ export default { removeCollection() { this.$store.commit("postwoman/removeCollection", { collectionIndex: this.collectionIndex, + flag: "rest", }) this.$toast.error(this.$t("deleted"), { icon: "delete", @@ -156,6 +160,7 @@ export default { const oldFolderIndex = dataTransfer.getData("oldFolderIndex") const oldFolderName = dataTransfer.getData("oldFolderName") const requestIndex = dataTransfer.getData("requestIndex") + const flag = "rest" this.$store.commit("postwoman/moveRequest", { oldCollectionIndex, newCollectionIndex: this.$props.collectionIndex, @@ -164,6 +169,7 @@ export default { oldFolderIndex, oldFolderName, requestIndex, + flag, }) this.syncCollections() }, diff --git a/components/collections/Edit.vue b/components/collections/Edit.vue index 85af8698f..226772113 100644 --- a/components/collections/Edit.vue +++ b/components/collections/Edit.vue @@ -54,7 +54,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -70,6 +73,7 @@ export default { this.$store.commit("postwoman/editCollection", { collection: collectionUpdated, collectionIndex: this.$props.editingCollectionIndex, + flag: "rest", }) this.$emit("hide-modal") this.syncCollections() diff --git a/components/collections/EditFolder.vue b/components/collections/EditFolder.vue index 6593f211a..62196ac8f 100644 --- a/components/collections/EditFolder.vue +++ b/components/collections/EditFolder.vue @@ -55,7 +55,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -65,6 +68,7 @@ export default { folder: { ...this.$props.folder, name: this.$data.name }, folderIndex: this.$props.folderIndex, folderName: this.$props.folder.name, + flag: "rest", }) this.hideModal() this.syncCollections() diff --git a/components/collections/EditRequest.vue b/components/collections/EditRequest.vue index df214695e..cb14d9e41 100644 --- a/components/collections/EditRequest.vue +++ b/components/collections/EditRequest.vue @@ -59,7 +59,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -75,6 +78,7 @@ export default { requestFolderIndex: this.$props.folderIndex, requestNew: requestUpdated, requestIndex: this.$props.requestIndex, + flag: "rest", }) this.hideModal() diff --git a/components/collections/Folder.vue b/components/collections/Folder.vue index d256d0343..b499bf1db 100644 --- a/components/collections/Folder.vue +++ b/components/collections/Folder.vue @@ -133,7 +133,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -145,6 +148,7 @@ export default { collectionIndex: this.$props.collectionIndex, folderName: this.$props.folder.name, folderIndex: this.$props.folderIndex, + flag: "rest", }) this.syncCollections() this.$toast.error(this.$t("deleted"), { @@ -157,6 +161,7 @@ export default { const oldFolderIndex = dataTransfer.getData("oldFolderIndex") const oldFolderName = dataTransfer.getData("oldFolderName") const requestIndex = dataTransfer.getData("requestIndex") + const flag = "rest" this.$store.commit("postwoman/moveRequest", { oldCollectionIndex, @@ -166,6 +171,7 @@ export default { oldFolderIndex, oldFolderName, requestIndex, + flag, }) this.syncCollections() }, diff --git a/components/collections/ImportExport.vue b/components/collections/ImportExport.vue index b0dffa641..dd03394c8 100644 --- a/components/collections/ImportExport.vue +++ b/components/collections/ImportExport.vue @@ -172,7 +172,7 @@ export default { }) .then(({ files }) => { let collections = JSON.parse(Object.values(files)[0].content) - this.$store.commit("postwoman/replaceCollections", collections) + this.$store.commit("postwoman/replaceCollections", { data: collections, flag: "rest" }) this.fileImported() this.syncToFBCollections() }) @@ -203,9 +203,10 @@ export default { } else if (collections.info && collections.info.schema.includes("v2.1.0")) { collections = [this.parsePostmanCollection(collections)] } else { - return this.failedImport() + this.failedImport() + return } - this.$store.commit("postwoman/replaceCollections", collections) + this.$store.commit("postwoman/replaceCollections", { data: collections, flag: "rest" }) this.fileImported() this.syncToFBCollections() } @@ -227,9 +228,10 @@ export default { collections = JSON.parse(content.replaceAll(/{{([a-z]+)}}/gi, "<<$1>>")) collections = [this.parsePostmanCollection(collections)] } else { - return this.failedImport() + this.failedImport() + return } - this.$store.commit("postwoman/importCollections", collections) + this.$store.commit("postwoman/importCollections", { data: collections, flag: "rest" }) this.fileImported() this.syncToFBCollections() } @@ -255,13 +257,19 @@ export default { }) }, syncCollections() { - this.$store.commit("postwoman/replaceCollections", fb.currentCollections) + this.$store.commit("postwoman/replaceCollections", { + data: fb.currentCollections, + flag: "rest", + }) this.fileImported() }, syncToFBCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, diff --git a/components/collections/Request.vue b/components/collections/Request.vue index b3dd4afec..1730039e2 100644 --- a/components/collections/Request.vue +++ b/components/collections/Request.vue @@ -88,7 +88,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -107,6 +110,7 @@ export default { collectionIndex: this.$props.collectionIndex, folderName: this.$props.folderName, requestIndex: this.$props.requestIndex, + flag: "rest", }) this.$toast.error(this.$t("deleted"), { icon: "delete", diff --git a/components/collections/SaveRequest.vue b/components/collections/SaveRequest.vue index 9ca6139b7..c5b20ba71 100644 --- a/components/collections/SaveRequest.vue +++ b/components/collections/SaveRequest.vue @@ -146,7 +146,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, @@ -176,6 +179,7 @@ export default { collectionIndex: this.$data.requestData.collectionIndex, folderName: this.$data.requestData.folderName, requestIndex: this.$data.requestData.requestIndex, + flag: "rest", }) this.hideModal() diff --git a/components/collections/graphql/Add.vue b/components/collections/graphql/Add.vue new file mode 100644 index 000000000..95b744131 --- /dev/null +++ b/components/collections/graphql/Add.vue @@ -0,0 +1,80 @@ + + + diff --git a/components/collections/graphql/AddFolder.vue b/components/collections/graphql/AddFolder.vue new file mode 100644 index 000000000..cb0447587 --- /dev/null +++ b/components/collections/graphql/AddFolder.vue @@ -0,0 +1,65 @@ + + + diff --git a/components/collections/graphql/Collection.vue b/components/collections/graphql/Collection.vue new file mode 100644 index 000000000..25d429f4b --- /dev/null +++ b/components/collections/graphql/Collection.vue @@ -0,0 +1,178 @@ + + + diff --git a/components/collections/graphql/Edit.vue b/components/collections/graphql/Edit.vue new file mode 100644 index 000000000..d1d8ca092 --- /dev/null +++ b/components/collections/graphql/Edit.vue @@ -0,0 +1,86 @@ + + + diff --git a/components/collections/graphql/EditFolder.vue b/components/collections/graphql/EditFolder.vue new file mode 100644 index 000000000..9e4e85acd --- /dev/null +++ b/components/collections/graphql/EditFolder.vue @@ -0,0 +1,81 @@ + + + diff --git a/components/collections/graphql/EditRequest.vue b/components/collections/graphql/EditRequest.vue new file mode 100644 index 000000000..df1a026a5 --- /dev/null +++ b/components/collections/graphql/EditRequest.vue @@ -0,0 +1,92 @@ + + + diff --git a/components/collections/graphql/Folder.vue b/components/collections/graphql/Folder.vue new file mode 100644 index 000000000..02be2982e --- /dev/null +++ b/components/collections/graphql/Folder.vue @@ -0,0 +1,180 @@ + + + diff --git a/components/collections/graphql/ImportExport.vue b/components/collections/graphql/ImportExport.vue new file mode 100644 index 000000000..8df76dcf9 --- /dev/null +++ b/components/collections/graphql/ImportExport.vue @@ -0,0 +1,393 @@ + + + diff --git a/components/collections/graphql/Request.vue b/components/collections/graphql/Request.vue new file mode 100644 index 000000000..fbacaedcd --- /dev/null +++ b/components/collections/graphql/Request.vue @@ -0,0 +1,115 @@ + + + diff --git a/components/collections/graphql/SaveRequest.vue b/components/collections/graphql/SaveRequest.vue new file mode 100644 index 000000000..a867768da --- /dev/null +++ b/components/collections/graphql/SaveRequest.vue @@ -0,0 +1,225 @@ + + + diff --git a/components/collections/graphql/index.vue b/components/collections/graphql/index.vue new file mode 100644 index 000000000..2db4354ba --- /dev/null +++ b/components/collections/graphql/index.vue @@ -0,0 +1,261 @@ + + + + + diff --git a/components/collections/index.vue b/components/collections/index.vue index 1ac6746b4..896b91354 100644 --- a/components/collections/index.vue +++ b/components/collections/index.vue @@ -199,9 +199,11 @@ export default { this.syncCollections() }, onAddFolder({ name, path }) { + const flag = "rest" this.$store.commit("postwoman/addFolder", { name, path, + flag, }) this.displayModalAddFolder(false) @@ -242,7 +244,10 @@ export default { syncCollections() { if (fb.currentUser !== null && fb.currentSettings[0]) { if (fb.currentSettings[0].value) { - fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections))) + fb.writeCollections( + JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)), + "collections" + ) } } }, diff --git a/helpers/__tests__/fb.spec.js b/helpers/__tests__/fb.spec.js index 31ca53c5b..01f689ab6 100644 --- a/helpers/__tests__/fb.spec.js +++ b/helpers/__tests__/fb.spec.js @@ -1108,7 +1108,7 @@ describe("FirebaseInstance", () => { signInUser() - await expect(fb.writeCollections([])).resolves.toBeUndefined() + await expect(fb.writeCollections([], "collections")).resolves.toBeUndefined() }) test("rejects for non-authenticated request", async () => { @@ -1116,7 +1116,7 @@ describe("FirebaseInstance", () => { signOutUser() - await expect(fb.writeCollections([])).rejects.toBeDefined() + await expect(fb.writeCollections([], "collections")).rejects.toBeDefined() }) test("stores data on firestore with proper structure", async () => { @@ -1124,7 +1124,7 @@ describe("FirebaseInstance", () => { signInUser() - await fb.writeCollections([]) + await fb.writeCollections([], "collections") const doc = ( await mocksdk @@ -1152,7 +1152,7 @@ describe("FirebaseInstance", () => { signInUser() - await fb.writeCollections([]) + await fb.writeCollections([], "collections") const doc = ( await mocksdk diff --git a/helpers/fb.js b/helpers/fb.js index fc97ff5b4..3e998a91d 100644 --- a/helpers/fb.js +++ b/helpers/fb.js @@ -35,6 +35,7 @@ export class FirebaseInstance { this.currentHistory = [] this.currentGraphqlHistory = [] this.currentCollections = [] + this.currentGraphqlCollections = [] this.currentEnvironments = [] this.app.auth().onAuthStateChanged((user) => { @@ -133,6 +134,21 @@ export class FirebaseInstance { } }) + this.usersCollection + .doc(this.currentUser.uid) + .collection("collectionsGraphql") + .onSnapshot((collectionsRef) => { + const collections = [] + collectionsRef.forEach((doc) => { + const collection = doc.data() + collection.id = doc.id + collections.push(collection) + }) + if (collections.length > 0) { + this.currentGraphqlCollections = collections[0].collection + } + }) + this.usersCollection .doc(this.currentUser.uid) .collection("environments") @@ -319,7 +335,7 @@ export class FirebaseInstance { } } - async writeCollections(collection) { + async writeCollections(collection, flag) { const cl = { updatedOn: new Date(), author: this.currentUser.uid, @@ -329,11 +345,7 @@ export class FirebaseInstance { } try { - await this.usersCollection - .doc(this.currentUser.uid) - .collection("collections") - .doc("sync") - .set(cl) + await this.usersCollection.doc(this.currentUser.uid).collection(flag).doc("sync").set(cl) } catch (e) { console.error("error updating", cl, e) diff --git a/package-lock.json b/package-lock.json index 17cd1cf31..df9c34d42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "hoppscotch", "version": "2.0.0", "hasInstallScript": true, "dependencies": { @@ -1821,6 +1822,7 @@ "jest-resolve": "^26.6.2", "jest-util": "^26.6.2", "jest-worker": "^26.6.2", + "node-notifier": "^8.0.0", "slash": "^3.0.0", "source-map": "^0.6.0", "string-length": "^4.0.1", @@ -4030,6 +4032,7 @@ "merge-source-map": "^1.1.0", "postcss": "^7.0.14", "postcss-selector-parser": "^6.0.2", + "prettier": "^1.18.2", "source-map": "~0.6.1", "vue-template-es2015-compiler": "^1.9.0" }, @@ -6036,6 +6039,7 @@ "dependencies": { "anymatch": "~3.1.1", "braces": "~3.0.2", + "fsevents": "~2.3.1", "glob-parent": "~5.1.0", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -8796,7 +8800,8 @@ "esprima": "^4.0.1", "estraverse": "^4.2.0", "esutils": "^2.0.2", - "optionator": "^0.8.1" + "optionator": "^0.8.1", + "source-map": "~0.6.1" }, "bin": { "escodegen": "bin/escodegen.js", @@ -12234,6 +12239,7 @@ "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", + "fsevents": "^2.1.2", "graceful-fs": "^4.2.4", "jest-regex-util": "^26.0.0", "jest-serializer": "^26.6.2", @@ -26484,7 +26490,8 @@ "dependencies": { "chokidar": "^3.4.1", "graceful-fs": "^4.1.2", - "neo-async": "^2.5.0" + "neo-async": "^2.5.0", + "watchpack-chokidar2": "^2.0.1" }, "optionalDependencies": { "watchpack-chokidar2": "^2.0.1" diff --git a/pages/graphql.vue b/pages/graphql.vue index f15d28340..1276139f5 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -225,6 +225,14 @@ > photo_filter + -