[PR #4211] [MERGED] feat: duplicate REST/GraphQL collections #4703

Closed
opened 2026-03-17 02:12:56 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/4211
Author: @jamesgeorge007
Created: 7/24/2024
Status: Merged
Merged: 7/29/2024
Merged by: @jamesgeorge007

Base: nextHead: feat/duplicate-collection-ui


📝 Commits (10+)

  • 80d50e2 feat: duplicate REST/GraphQL collections
  • c6d2811 fix: prevent duplicate collection entry from userCollectionCreated GQL subscription
  • b53da4d fix: ensure context menu is dismissed only after the action in team workspace
  • 36bf4bb fix: prevent missing children during collection creation
  • 27da1d7 fix: consistent export format for bulk collection export under teams
  • f582e95 fix: prevent stringifying collection level properties twice at the API level
  • e93c9b5 fix: syncing duplicate collections under personal workspace in SH
  • 6fa11cd refactor: leverage helpers
  • c4fb4f0 fix: bulk export for collections under cloud team workspace
  • e311d34 chore: disable Duplicate collection action under personal workspace in SH

📊 Changes

26 files changed (+726 additions, -97 deletions)

View changed files

📝 packages/hoppscotch-backend/src/team-collection/team-collection.service.ts (+11 -3)
📝 packages/hoppscotch-backend/src/user-collection/user-collection.service.ts (+11 -3)
📝 packages/hoppscotch-backend/src/utils.ts (+25 -6)
📝 packages/hoppscotch-common/locales/en.json (+2 -1)
📝 packages/hoppscotch-common/src/components/collections/Collection.vue (+48 -3)
📝 packages/hoppscotch-common/src/components/collections/ImportExport.vue (+6 -22)
📝 packages/hoppscotch-common/src/components/collections/MyCollections.vue (+21 -0)
📝 packages/hoppscotch-common/src/components/collections/Request.vue (+7 -8)
📝 packages/hoppscotch-common/src/components/collections/TeamCollections.vue (+28 -2)
📝 packages/hoppscotch-common/src/components/collections/graphql/Collection.vue (+62 -11)
📝 packages/hoppscotch-common/src/components/collections/graphql/Folder.vue (+58 -13)
📝 packages/hoppscotch-common/src/components/collections/graphql/index.vue (+10 -0)
📝 packages/hoppscotch-common/src/components/collections/index.vue (+39 -5)
packages/hoppscotch-common/src/helpers/backend/gql/mutations/DuplicateTeamCollection.graphql (+3 -0)
📝 packages/hoppscotch-common/src/helpers/backend/helpers.ts (+99 -6)
📝 packages/hoppscotch-common/src/helpers/backend/mutations/TeamCollection.ts (+12 -0)
📝 packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts (+2 -2)
📝 packages/hoppscotch-common/src/newstore/collections.ts (+123 -8)
📝 packages/hoppscotch-common/src/platform/index.ts (+6 -0)
📝 packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts (+2 -1)

...and 6 more files

📄 Description

What's changed

This PR includes the UI changes adding the ability to duplicate REST/GraphQL collections. The context menu for collections (root/child) from the tree will include a new option labelled Duplicate collection. This will result in a new collection entry within the same hierarchy, effectively cloning the children and retaining the collection level authorization/header properties. Additionally, while the context menu is open, the duplication action can be initiated by pressing the d key.

The duplication action is disabled under personal workspace in SH for now due to a known issue with syncing and will be revisited in a later iteration.

Closes HFE-491 HFE-545 HFE-547 #2475.

The BE changes were implemented in #4207.

Apart from that, the following issues are patched:

  • The userCollectionCreated and teamCollectionCreated GQL subscriptions fired after collection create actions (import, create, duplicate) sent collection-level properties (authorization/headers) applying stringification via JSON.stringify() multiple times which led to an exception since FE expects it to be parsed via JSON.parse() in one pass.
  • Bulk export of REST collections from a team workspace results in the export format not confirming to HoppCollection. Attempting to export collections existing with authorization/headers set and importing them will result in the respective collection properties not getting populated. This is because the export format doesn't conform to the internal data structure HoppCollection and while importing it fails to parse and goes ahead with the defaults. This also led to the CLI rejecting bulk collection exports from a team workspace - HFE-545
  • There was an issue specific to team workspaces on cloud, where requests were lost while importing except for the last level. This also extends to the case where child collections/requests are being created for a collection in the non-expanded state having pre-existing children and expanding will reveal only the above additions. There was a change in behaviour in the teamCollectionAdded GQL subscription on cloud compared to SH where it was fired post-collection create actions. Child collections at all levels get populated under the imported collection or while creating child collections they get synced straightaway via the subscription. This has been patched at the tree level ensuring collection entries received via GQL subscriptions for a parent collection that is not expanded yet doesn't get populated - HFE-547.
  • GraphQL collections properties modal can now be opened via the p keypress while the context menu is open.

Preview

https://github.com/user-attachments/assets/2536c93d-d5b0-4170-846d-fb95286767f7

Changes

  • Relevant changes under ~/packages/hoppscotch-backend/*, resolving the issue mentioned above where the collection level properties are stringified multiple times while communicating to FE. A new utility function transformCollectionData() under ~/src/utils.ts is added for the purpose.
  • Relevant i18n string additions.
  • Addition of the duplicate action under collection (REST/GQL) nodes in the tree. Similar to the export action in team workspaces where the loading state is toggled back after the GQL mutation, accounting for the same with duplicate action.
  • Previously, bulk export of collections resulted in a format not conforming to HoppCollection and hence a re-import resulting in the collection level properties (authorization/headers) missing and the CLI rejecting it (An issue mentioned as patched above). On this front, the getTeamCollectionJSON() helper function under ~/packages/hoppscotch-common/src/helpers/backend/helpers.ts has been updated to parse the JSON string, transform each entry and return a stringified representation. Also, the case where there are no collections to export is handled at source and returned as a left case.
  • Add DuplicateUserCollection & DuplicateTeamCollection GQL documents and respective updates integrating the same.
  • Updates to prop names indicating request loading actions for the relevant components from duplicateLoading to duplicateRequestLoading since there's a new duplicateCollectionLoading prop variant coming in.
  • REST/GQL duplicateCollection dispatcher function additions under newstore/collection.ts along with duplicateRESTCollection & duplicateGQLCollection helper functions that are exposed for consumption in the outside world.
  • A new temporary platform feature flag duplicateCollectionDisabledInPersonalWorkspace is added. The naming convention is slightly different propEnabled to prevent the need for updates at the central platform level config.
  • Relevant business logic to support syncing with collection duplication action under personal workspace in SH.

Note to reviewers

  • The business logic about syncing in the personal workspace is kept despite the action being disabled under SH since it will be required while revisiting. Any changes scoped under ~/packages/hoppscotch-selfhost-web/* can be ignored for now.
  • Platform definitions under selfhost-desktop will be added alongside revisiting the syncing issue under personal workspace in SH.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/4211 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 7/24/2024 **Status:** ✅ Merged **Merged:** 7/29/2024 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `feat/duplicate-collection-ui` --- ### 📝 Commits (10+) - [`80d50e2`](https://github.com/hoppscotch/hoppscotch/commit/80d50e294106e31972656a8f4d2362efecc9ede2) feat: duplicate REST/GraphQL collections - [`c6d2811`](https://github.com/hoppscotch/hoppscotch/commit/c6d28118362a516dd6193f519a0ef72a44de5c88) fix: prevent duplicate collection entry from `userCollectionCreated` GQL subscription - [`b53da4d`](https://github.com/hoppscotch/hoppscotch/commit/b53da4d0810522714501b95c43d5e4126ffbd200) fix: ensure context menu is dismissed only after the action in team workspace - [`36bf4bb`](https://github.com/hoppscotch/hoppscotch/commit/36bf4bb5b72098ffd7f3de20f89c2c9e51210e0d) fix: prevent missing children during collection creation - [`27da1d7`](https://github.com/hoppscotch/hoppscotch/commit/27da1d7ec4e98f6db21edbd23b08392682dfed99) fix: consistent export format for bulk collection export under teams - [`f582e95`](https://github.com/hoppscotch/hoppscotch/commit/f582e95371e93ff2000da8f191b896216c467a37) fix: prevent stringifying collection level properties twice at the API level - [`e93c9b5`](https://github.com/hoppscotch/hoppscotch/commit/e93c9b56191890ca5daf5a3fc9de0cde82a9ea2b) fix: syncing duplicate collections under personal workspace in SH - [`6fa11cd`](https://github.com/hoppscotch/hoppscotch/commit/6fa11cde7166ca2fb9cd40d14ed91c60e9cb4bed) refactor: leverage helpers - [`c4fb4f0`](https://github.com/hoppscotch/hoppscotch/commit/c4fb4f0baacaba5021c3c32d658425998ed159cc) fix: bulk export for collections under cloud team workspace - [`e311d34`](https://github.com/hoppscotch/hoppscotch/commit/e311d34a01a1c715f4912da4b0bace299cb6ea70) chore: disable `Duplicate collection` action under personal workspace in SH ### 📊 Changes **26 files changed** (+726 additions, -97 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-backend/src/team-collection/team-collection.service.ts` (+11 -3) 📝 `packages/hoppscotch-backend/src/user-collection/user-collection.service.ts` (+11 -3) 📝 `packages/hoppscotch-backend/src/utils.ts` (+25 -6) 📝 `packages/hoppscotch-common/locales/en.json` (+2 -1) 📝 `packages/hoppscotch-common/src/components/collections/Collection.vue` (+48 -3) 📝 `packages/hoppscotch-common/src/components/collections/ImportExport.vue` (+6 -22) 📝 `packages/hoppscotch-common/src/components/collections/MyCollections.vue` (+21 -0) 📝 `packages/hoppscotch-common/src/components/collections/Request.vue` (+7 -8) 📝 `packages/hoppscotch-common/src/components/collections/TeamCollections.vue` (+28 -2) 📝 `packages/hoppscotch-common/src/components/collections/graphql/Collection.vue` (+62 -11) 📝 `packages/hoppscotch-common/src/components/collections/graphql/Folder.vue` (+58 -13) 📝 `packages/hoppscotch-common/src/components/collections/graphql/index.vue` (+10 -0) 📝 `packages/hoppscotch-common/src/components/collections/index.vue` (+39 -5) ➕ `packages/hoppscotch-common/src/helpers/backend/gql/mutations/DuplicateTeamCollection.graphql` (+3 -0) 📝 `packages/hoppscotch-common/src/helpers/backend/helpers.ts` (+99 -6) 📝 `packages/hoppscotch-common/src/helpers/backend/mutations/TeamCollection.ts` (+12 -0) 📝 `packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts` (+2 -2) 📝 `packages/hoppscotch-common/src/newstore/collections.ts` (+123 -8) 📝 `packages/hoppscotch-common/src/platform/index.ts` (+6 -0) 📝 `packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts` (+2 -1) _...and 6 more files_ </details> ### 📄 Description ### What's changed This PR includes the UI changes adding the ability to duplicate REST/GraphQL collections. The context menu for collections (root/child) from the tree will include a new option labelled `Duplicate collection`. This will result in a new collection entry within the same hierarchy, effectively cloning the children and retaining the collection level authorization/header properties. Additionally, while the context menu is open, the duplication action can be initiated by pressing the `d` key. > The duplication action is disabled under personal workspace in SH for now due to a known issue with syncing and will be revisited in a later iteration. Closes HFE-491 HFE-545 HFE-547 #2475. > The BE changes were implemented in #4207. Apart from that, the following issues are patched: - The `userCollectionCreated` and `teamCollectionCreated` GQL subscriptions fired after collection create actions (import, create, duplicate) sent collection-level properties (authorization/headers) applying stringification via `JSON.stringify()` multiple times which led to an exception since FE expects it to be parsed via `JSON.parse()` in one pass. - Bulk export of REST collections from a team workspace results in the export format not confirming to `HoppCollection`. Attempting to export collections existing with authorization/headers set and importing them will result in the respective collection properties not getting populated. This is because the export format doesn't conform to the internal data structure `HoppCollection` and while importing it fails to parse and goes ahead with the defaults. This also led to the CLI rejecting bulk collection exports from a team workspace - [HFE-545](https://linear.app/hoppscotch/issue/HFE-545/bulk-export-of-collections-from-a-team-workspace-and-re-import-doesnt) - There was an issue specific to team workspaces on cloud, where requests were lost while importing except for the last level. This also extends to the case where child collections/requests are being created for a collection in the non-expanded state having pre-existing children and expanding will reveal only the above additions. There was a change in behaviour in the `teamCollectionAdded` GQL subscription on cloud compared to SH where it was fired post-collection create actions. Child collections at all levels get populated under the imported collection or while creating child collections they get synced straightaway via the subscription. This has been patched at the tree level ensuring collection entries received via GQL subscriptions for a parent collection that is not expanded yet doesn't get populated - [HFE-547](https://linear.app/hoppscotch/issue/HFE-547/bulk-export-of-collections-from-a-team-workspace-and-re-import-doesnt). - GraphQL collections properties modal can now be opened via the `p` keypress while the context menu is open. ### Preview https://github.com/user-attachments/assets/2536c93d-d5b0-4170-846d-fb95286767f7 ### Changes - Relevant changes under `~/packages/hoppscotch-backend/*`, resolving the issue mentioned above where the collection level properties are stringified multiple times while communicating to FE. A new utility function `transformCollectionData()` under `~/src/utils.ts` is added for the purpose. - Relevant `i18n` string additions. - Addition of the duplicate action under collection (REST/GQL) nodes in the tree. Similar to the export action in team workspaces where the loading state is toggled back after the GQL mutation, accounting for the same with duplicate action. - Previously, bulk export of collections resulted in a format not conforming to `HoppCollection` and hence a re-import resulting in the collection level properties (authorization/headers) missing and the CLI rejecting it (An issue mentioned as patched above). On this front, the `getTeamCollectionJSON()` helper function under `~/packages/hoppscotch-common/src/helpers/backend/helpers.ts` has been updated to parse the JSON string, transform each entry and return a stringified representation. Also, the case where there are no collections to export is handled at source and returned as a `left` case. - Add `DuplicateUserCollection` & `DuplicateTeamCollection` GQL documents and respective updates integrating the same. - Updates to prop names indicating request loading actions for the relevant components from `duplicateLoading` to `duplicateRequestLoading` since there's a new `duplicateCollectionLoading` prop variant coming in. - REST/GQL `duplicateCollection` dispatcher function additions under `newstore/collection.ts` along with `duplicateRESTCollection` & `duplicateGQLCollection` helper functions that are exposed for consumption in the outside world. - A new temporary platform feature flag `duplicateCollectionDisabledInPersonalWorkspace` is added. The naming convention is slightly different `propEnabled` to prevent the need for updates at the `central` platform level config. - Relevant business logic to support syncing with collection duplication action under personal workspace in SH. ### Note to reviewers - The business logic about syncing in the personal workspace is kept despite the action being disabled under SH since it will be required while revisiting. Any changes scoped under `~/packages/hoppscotch-selfhost-web/*` can be ignored for now. - Platform definitions under `selfhost-desktop` will be added alongside revisiting the syncing issue under personal workspace in SH. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:12:56 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#4703
No description provided.