[PR #3836] refactor: introduce abstractions at the workspace level #4550

Open
opened 2026-03-17 02:04:29 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/3836
Author: @jamesgeorge007
Created: 2/16/2024
Status: 🔄 Open

Base: nextHead: refactor/workspaces


📝 Commits (10+)

  • 4cf801c refactor: initial iterations
  • 36d7379 refactor: iterations
  • 6529223 refactor: compile data in handles
  • d421a06 refactor: finalize API methods
  • dbd4717 refactor: prevent storing entire collection data in the respective handle
  • 0806a3a refactor: unify edit collection API methods and ensure consistent naming convention
  • cb34d13 refactor: consistent return formats
  • 1dc08f0 refactor: save request handle in tabs and remove tabs related logic from personal provider definition
  • b8e29ac refactor: updates based on the provider methods signature changes
  • bbc25af refactor: persist request handle under tab saveContext

📊 Changes

70 files changed (+19430 additions, -938 deletions)

View changed files

📝 packages/hoppscotch-common/locales/en.json (+3 -1)
📝 packages/hoppscotch-common/package.json (+1 -0)
📝 packages/hoppscotch-common/src/components/app/Header.vue (+45 -44)
📝 packages/hoppscotch-common/src/components/collections/Collection.vue (+2 -2)
📝 packages/hoppscotch-common/src/components/collections/ImportExport.vue (+82 -43)
📝 packages/hoppscotch-common/src/components/collections/MyCollections.vue (+11 -11)
📝 packages/hoppscotch-common/src/components/collections/Properties.vue (+13 -4)
📝 packages/hoppscotch-common/src/components/collections/SaveRequest.vue (+244 -231)
📝 packages/hoppscotch-common/src/components/collections/TeamCollections.vue (+11 -11)
📝 packages/hoppscotch-common/src/components/collections/index.vue (+2 -2)
📝 packages/hoppscotch-common/src/components/environments/ImportExport.vue (+73 -31)
📝 packages/hoppscotch-common/src/components/environments/index.vue (+224 -14)
📝 packages/hoppscotch-common/src/components/environments/my/Details.vue (+12 -34)
📝 packages/hoppscotch-common/src/components/environments/my/Environment.vue (+60 -16)
📝 packages/hoppscotch-common/src/components/environments/my/index.vue (+18 -3)
📝 packages/hoppscotch-common/src/components/environments/teams/Details.vue (+11 -0)
📝 packages/hoppscotch-common/src/components/environments/teams/Environment.vue (+7 -0)
📝 packages/hoppscotch-common/src/components/environments/teams/index.vue (+12 -3)
📝 packages/hoppscotch-common/src/components/http/Request.vue (+61 -42)
📝 packages/hoppscotch-common/src/components/http/RequestTab.vue (+22 -3)

...and 50 more files

📄 Description

Description

This PR introduces abstractions at the workspace level and ports the existing implementation to the new architecture. This will be done in phases, and the changes will be merged into the head branch. On a high level, business logic specific to each workspace is being moved from component sources to the respective provider definitions. The newly revamped workspace service acts as an interface for other parts of the codebase to access methods implemented by the various workspace providers. There is a given set of API methods that each provider (personal, teams, file-based) will implement, starting with personal initially.

  • Handles - Reference to an entity, say workspace, collection, requests, etc. It also holds the necessary information about the resource being pointed to. It can be invalidated at any point. Hence, it's a ref to a resource that, in turn, can hold reactive data (A handle itself can be invalidated and needs to be aware of changes happening to the inner members).

    export type HandleRef<T, InvalidateReason = unknown> = Ref<
      { type: "ok"; data: T } | { type: "invalid"; reason: InvalidateReason }
    >
    
  • Views - Compiles information about the underlying representation used to render the UI.

    export type RESTCollectionViewCollection = {
      collectionID: string
    
      name: string
    }
    
    export type RESTCollectionViewRequest = {
      collectionID: string
      requestID: string
    
      request: HoppRESTRequest
    }
    
    export type RESTCollectionViewItem =
      | { type: "collection"; value: RESTCollectionViewCollection }
      | { type: "request"; value: RESTCollectionViewRequest }
    
    export interface RootRESTCollectionView {
      providerID: string
      workspaceID: string
    
      loading: Ref<boolean>
    
      collections: Ref<RESTCollectionViewCollection[]>
    }
    
    export interface RESTCollectionChildrenView {
      providerID: string
      workspaceID: string
      collectionID: string
    
      loading: Ref<boolean>
    
      content: Ref<RESTCollectionViewItem[]>
    }
    

Compiles changes from the following PRs:

Todos

  • Drop New prefixes from the newly added components once replacing all instances with newly added components and removing the old ones.
  • Remove the emitWithFullCollection prop from the CollectionsProperties component after porting all usages.
  • Replace workspace-user-collection with user-collection for the type HoppRESTSaveContext under hoppscotch-common/src/helpers/rest/document.
  • Only keep requestHandle under the tab saveContext and remove the IDs (requestID, workspaceID, etc) at runtime (Future TODO).
  • Remove collectionID from requestHandle since it can be obtained from requestID (Future TODO).

Checks

  • My pull request adheres to the code style of this project
  • All the tests have passed

🔄 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/3836 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 2/16/2024 **Status:** 🔄 Open **Base:** `next` ← **Head:** `refactor/workspaces` --- ### 📝 Commits (10+) - [`4cf801c`](https://github.com/hoppscotch/hoppscotch/commit/4cf801c9c6564644b7a41a1c585e4dd4e69ebe84) refactor: initial iterations - [`36d7379`](https://github.com/hoppscotch/hoppscotch/commit/36d7379cd29c54ee64b7269d913a2965c6b46c20) refactor: iterations - [`6529223`](https://github.com/hoppscotch/hoppscotch/commit/6529223708c99edb25ff054ffab46cd11791f423) refactor: compile data in handles - [`d421a06`](https://github.com/hoppscotch/hoppscotch/commit/d421a063b9e5c3e0a415ae3ceae180044c24ee2e) refactor: finalize API methods - [`dbd4717`](https://github.com/hoppscotch/hoppscotch/commit/dbd4717f04acafb22823e607a75f787b82f97ed9) refactor: prevent storing entire collection data in the respective handle - [`0806a3a`](https://github.com/hoppscotch/hoppscotch/commit/0806a3aa87f9960fc42c223b4fd7eace029667fe) refactor: unify edit collection API methods and ensure consistent naming convention - [`cb34d13`](https://github.com/hoppscotch/hoppscotch/commit/cb34d13c220d3e8db89609bc2ee97ccd0b23b09b) refactor: consistent return formats - [`1dc08f0`](https://github.com/hoppscotch/hoppscotch/commit/1dc08f035a4d0cf1994cdba284f3c48b482aeee4) refactor: save request handle in tabs and remove tabs related logic from personal provider definition - [`b8e29ac`](https://github.com/hoppscotch/hoppscotch/commit/b8e29ac1d6b72fdb0ffd22714b276724b1152609) refactor: updates based on the provider methods signature changes - [`bbc25af`](https://github.com/hoppscotch/hoppscotch/commit/bbc25afe54af942a5ae1246f5d3c8aa222af9ab6) refactor: persist request handle under tab saveContext ### 📊 Changes **70 files changed** (+19430 additions, -938 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/locales/en.json` (+3 -1) 📝 `packages/hoppscotch-common/package.json` (+1 -0) 📝 `packages/hoppscotch-common/src/components/app/Header.vue` (+45 -44) 📝 `packages/hoppscotch-common/src/components/collections/Collection.vue` (+2 -2) 📝 `packages/hoppscotch-common/src/components/collections/ImportExport.vue` (+82 -43) 📝 `packages/hoppscotch-common/src/components/collections/MyCollections.vue` (+11 -11) 📝 `packages/hoppscotch-common/src/components/collections/Properties.vue` (+13 -4) 📝 `packages/hoppscotch-common/src/components/collections/SaveRequest.vue` (+244 -231) 📝 `packages/hoppscotch-common/src/components/collections/TeamCollections.vue` (+11 -11) 📝 `packages/hoppscotch-common/src/components/collections/index.vue` (+2 -2) 📝 `packages/hoppscotch-common/src/components/environments/ImportExport.vue` (+73 -31) 📝 `packages/hoppscotch-common/src/components/environments/index.vue` (+224 -14) 📝 `packages/hoppscotch-common/src/components/environments/my/Details.vue` (+12 -34) 📝 `packages/hoppscotch-common/src/components/environments/my/Environment.vue` (+60 -16) 📝 `packages/hoppscotch-common/src/components/environments/my/index.vue` (+18 -3) 📝 `packages/hoppscotch-common/src/components/environments/teams/Details.vue` (+11 -0) 📝 `packages/hoppscotch-common/src/components/environments/teams/Environment.vue` (+7 -0) 📝 `packages/hoppscotch-common/src/components/environments/teams/index.vue` (+12 -3) 📝 `packages/hoppscotch-common/src/components/http/Request.vue` (+61 -42) 📝 `packages/hoppscotch-common/src/components/http/RequestTab.vue` (+22 -3) _...and 50 more files_ </details> ### 📄 Description ### Description This PR introduces abstractions at the workspace level and ports the existing implementation to the new architecture. This will be done in phases, and the changes will be merged into the head branch. On a high level, business logic specific to each workspace is being moved from component sources to the respective provider definitions. The newly revamped workspace service acts as an interface for other parts of the codebase to access methods implemented by the various workspace providers. There is a given set of API methods that each provider (`personal`, `teams`, `file-based`) will implement, starting with `personal` initially. - Handles - Reference to an entity, say workspace, collection, requests, etc. It also holds the necessary information about the resource being pointed to. It can be invalidated at any point. Hence, it's a `ref` to a resource that, in turn, can hold reactive data (A handle itself can be invalidated and needs to be aware of changes happening to the inner members). ```ts export type HandleRef<T, InvalidateReason = unknown> = Ref< { type: "ok"; data: T } | { type: "invalid"; reason: InvalidateReason } > ``` - Views - Compiles information about the underlying representation used to render the UI. ```ts export type RESTCollectionViewCollection = { collectionID: string name: string } export type RESTCollectionViewRequest = { collectionID: string requestID: string request: HoppRESTRequest } export type RESTCollectionViewItem = | { type: "collection"; value: RESTCollectionViewCollection } | { type: "request"; value: RESTCollectionViewRequest } export interface RootRESTCollectionView { providerID: string workspaceID: string loading: Ref<boolean> collections: Ref<RESTCollectionViewCollection[]> } export interface RESTCollectionChildrenView { providerID: string workspaceID: string collectionID: string loading: Ref<boolean> content: Ref<RESTCollectionViewItem[]> } ``` Compiles changes from the following PRs: - #3859 - #4113 - #4080 ### Todos - Drop `New` prefixes from the newly added components once replacing all instances with newly added components and removing the old ones. - Remove the `emitWithFullCollection` prop from the `CollectionsProperties` component after porting all usages. - Replace `workspace-user-collection` with `user-collection` for the type `HoppRESTSaveContext` under `hoppscotch-common/src/helpers/rest/document`. - Only keep `requestHandle` under the tab `saveContext` and remove the IDs (`requestID`, `workspaceID`, etc) at runtime (Future TODO). - Remove `collectionID` from `requestHandle` since it can be obtained from `requestID` (Future TODO). ### Checks - [ ] My pull request adheres to the code style of this project - [ ] All the tests have passed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4550
No description provided.