unisonweb / codebase-ui

Unison Codebase UI
https://share.unison-lang.org
MIT License
46 stars 7 forks source link

Drive perspective changes off of Route changes #282

Closed hojberg closed 2 years ago

hojberg commented 2 years ago

Overview

Instead of changing perspectives directly and fetching details before changing the URL; first change the URL and then change the Perspective. Ensure that we don't fetch the Perspective when changing URLs to the same Perspective with a different definition and ensure we correctly dedupe WorkspaceItems when we change Perspective.

Fixes: https://github.com/unisonweb/codebase-ui/issues/195

Implementation notes

To support this add a bunch of helper functions:

With regards to deduping WorkspaceItems, this is needed because when we change Perspective with any open defintions, we migrate the WorkspaceItems to be indexed by Hash instead of FQN, and then when the user subsequently uses the back button to the previous URL that was FQN based, we want to avoid re-fetching and duplicating the same item (their Reference are technically different in that one is Hash based and one is FQN based for the same WorkspaceItem). So as soon as we get the data back from the server and can see that it includes the Hash of an already fetched definition, we dedupe.