Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(workspaces): provider additions for collections under personal workspace #3859

Draft
wants to merge 48 commits into
base: refactor/workspaces
Choose a base branch
from

Conversation

jamesgeorge007
Copy link
Member

@jamesgeorge007 jamesgeorge007 commented Feb 26, 2024

Description

This PR ports the existing implementation for import/export, move/reorder, and search corresponding to collections under personal workspace to the provider-based new architecture. It also adds support for searching collections at any depth.

Closes HFE-437.

Changes

  • Adds the following methods under the personal workspace provider corresponding to the features mentioned above.

    // Views
    getRESTSearchResultsView(
      workspaceHandle: HandleRef<Workspace>,
      searchQuery: Ref<string>
    ): Promise<E.Either<never, HandleRef<RESTSearchResultsView>>>
    getRESTCollectionJSONView(
      workspaceHandle: HandleRef<Workspace>
    ): Promise<E.Either<never, HandleRef<RESTCollectionJSONView>>>
    
    importRESTCollections(
      workspaceHandle: HandleRef<Workspace>,
      collections: HoppCollection[]
    ): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
    exportRESTCollections(
      workspaceHandle: HandleRef<Workspace>,
      collections: HoppCollection[]
    ): Promise<E.Either<unknown, void>>
    exportRESTCollection(
      collectionHandle: HandleRef<WorkspaceCollection>,
      collection: HoppCollection
    ): Promise<E.Either<unknown, void>>
    
    reorderRESTCollection(
      collectionHandle: HandleRef<WorkspaceCollection>,
      destinationCollectionID: string | null
    ): Promise<E.Either<unknown, void>>
    moveRESTCollection(
      collectionHandle: HandleRef<WorkspaceCollection>,
      destinationCollectionID: string | null
    ): Promise<E.Either<unknown, void>>
    reorderRESTRequest(
      requestHandle: HandleRef<WorkspaceRequest>,
      destinationCollectionID: string,
      destinationRequestID: string | null
    ): Promise<E.Either<unknown, void>>
    moveRESTRequest(
      requestHandle: HandleRef<WorkspaceRequest>,
      destinationCollectionID: string
    ): Promise<E.Either<unknown, void>>
  • Additions to the NewCollectionsRest component accounting for the ported features mentioned above. The business logic associated with updates to the store for each action resides in the provider definition for each workspace invoked from the component level via the new workspace service implementation.

  • Move the markup and associated logic wrt showing the active workspace and search from the parent level NewCollections component to `NewCollectionsRest.

  • Port the collection/request move/reorder logic (markup, events, handlers, etc) into the NewCollectionsRestCollection and NewCollectionsRestRequest components.

  • Introduce a new tree adapter to render the tree with search results. This was required since the existing adapter for rendering the default collection tree operates based on the supplied workspace handle. While, for search, is to be based on the initial data provided to be filtered based on.

  • The getChildren method to be implemented by the tree adapter now takes an additional argument signifying the type of the incoming node (collection/request). This acts as a safeguard to prevent errors with operations specific to a collection node.

  • Remove collectionID from information persisted under the REST tab saveContext since requestID accounts for it.

  • initializeDownloadCollection helper under ~/packages/hoppscotch-common/src/helpers/import-export/export is given an agnosic name initializeDownloadFile since it gets consumed in different contexts. The definition is updated to point to the platform definition to ensure the underlying platform defines the behavior.

  • New helper functions under ~/packages/hoppscotch-common/src/services/new-workspace/helpers.ts to abstract common logic consumed in the provider method definitions.

  • Formalise a system for creating a persistable handle reference that can be loaded back again - Persist request handles at runtime, write only the unique IDs (provider, workspace & request IDs) required to restore the handle to localStorage. Load the request handle back via the IDs at runtime.

  • Introduce writable handles to signify updates to other handle references when an action is performed. For instance, a request from the collection tree is deleted and at the same time the handle issued is updated thereby the request handle persisted under tab saveContext is aware of the update (handle type is set to invalid) and toggles the dirty state in this case.

Checks

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

Collection ID can be inferred from request ID by removing last index from the path.
…ewRequest` type

Collection ID serves the purpose.
Ensure the entire collection tree is rendered if the search query matches a collection name.
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch from 54706e3 to 845db07 Compare February 27, 2024 17:35
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch 3 times, most recently from 3c0af78 to ee1e98e Compare April 24, 2024 11:16
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch from 09c1221 to 9136d13 Compare May 1, 2024 13:15
Mark the tab (saved request under a collection) as not dirty if the request contents are reset to the value since previous save.
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch from 9136d13 to 4b49ecf Compare May 1, 2024 13:19
- Filter out duplicate issued handle entries.
- Move from `getAffectedIndexes` helper function to a custom implementation for updating affected request indices.
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch 7 times, most recently from cabe27e to e1e3fb1 Compare May 7, 2024 07:56
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch from e1e3fb1 to bc976af Compare May 7, 2024 14:26
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch from b714b01 to f086a96 Compare May 9, 2024 08:04
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch 5 times, most recently from 2e3d9ff to 5875eed Compare May 10, 2024 05:35
@jamesgeorge007 jamesgeorge007 force-pushed the refactor/workspaces-collection-provider-additions branch from 5875eed to 4926b7d Compare May 10, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants