refactor(workspaces): provider additions for collections under personal workspace #3859
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're also moving to a new inert handle-based approach (proposed by @AndrewBastin). Previously, reactive handles were sent around everywhere with the provider methods expecting the same. This resulted in issues with the reactivity behavior mostly with the issued handle updates not getting reflected in the issued handles since the reference was coming up differently and the value getting automatically unwrapped at places. In the new approach, while obtaining a handle it's just a plain object and the underlying reactive value can be accessed at a later point in time.
Personal workspaces have dynamic path-based IDs (
0/0
,2/1/0
, etc) based on the position (levels are separated by/
, single digit represents root collections) of a resource (collection/request) in the tree. Previously to keep the association between requests open under tabs and the ones from the tree, every time the resultant IDs were computed manually after the action. Say, a request at a deeply nested collection is moved to a different location, each tab has information persisted about the ID path of the request being open from the tree and necessary updates are made to the above information based on the action computed from the source and destination IDs.With the new handle-based system, since handles are reactive references to a resource, we keep a list of issued handles (creating/selecting a request,) and each tab keeps a request handle reference under
tab.document.saveContext
, and whenever an action requiring updates to the IDs happens, the corresponding handle is found from the compiled list of issued handles and the respective ID (collectionID
,requestID
) is updated accordingly and the updates are streamed to the tabs via the reactive behavior. The same approach is used for toggling the dirty state associated with requests when any parent level collection is deleted or if the request itself is deleted.Closes HFE-437.
Changes
Adds the following methods under the personal workspace provider corresponding to the abovementioned features.
Migrate to the new inert handle-based approach.
Move to handle based updates to keep the association between requests from the collection tree and the one's open under tabs.
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
andNewCollectionsRestRequest
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 tabsaveContext
sincerequestID
accounts for it.initializeDownloadCollection
helper under~/packages/hoppscotch-common/src/helpers/import-export/export
is given an agnosic nameinitializeDownloadFile
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 toinvalid
) and toggles the dirty state in this case.Checks