-
Notifications
You must be signed in to change notification settings - Fork 182
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
(feat) Create a global app history utility #877
Conversation
… directly from esm-config
@@ -0,0 +1,35 @@ | |||
/** @module @category Breadcrumb */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-pasted from esm-breadcrumbs
Size Change: -655 kB (-19%) 👏 Total Size: 2.84 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @brandones! A couple of really minor points, but this looks great!
export * from './types'; | ||
|
||
import { registerBreadcrumb as rb, registerBreadcrumbs as rbs, getBreadcrumbs as gb } from './db'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I'd be fine with just dropping esm-breadcrumbs altogether. Anything not in the framework that depends directly on the sub-components is, in my view, relying on implementation details. We've pretty freely moved functions around before when it made sense to and I don't think this should be different (even the app shell loads these from the framework).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that philosophy. Will clean this up.
initializeHistory(); | ||
|
||
window.addEventListener('single-spa:routing-event', (evt) => { | ||
const history = getHistory(); | ||
if (history[history.length - 1] !== window.location.href) { | ||
addToHistory(window.location.href); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to migrate this into the startup sequence in the app-shell? I kind of like the clarity of having a single piece of code that tells us everything being done at startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that's a nice idea, will do.
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
I got into this in order to solve https://openmrs.atlassian.net/browse/O3-1594 . The trouble is that there is at present no good way for the close button to know where to go back to.
document.referrer
is often not what we want,window.location.back()
will go back to the previous dashboard within the patient chart, and hacks involving localStorage are unpleasant.This creates a global app history that is preserved across the session. This way, the close button can look backwards through the history in order to determine where it should send the user back to. This will also allow us to make the breadcrumb actually correctly reflect where the user came from—right now the top level breadcrumb in the chart is always "home."
I created a new library to house this, called
esm-navigation
, which I think can serve as a more natural home for some things. I moved the navigation utilities out ofesm-config
(kind of a strange place for them) and into this new library, along with the whole ofesm-breadcrumbs
.@openmrs/esm-breadcrumbs
is now deprecated. We should delete it in the next core major version.I tried really hard to deprecate direct imports of
navigate
,interpolateString
, andinterpolateUrl
from esm-config. Unfortunately it made things with tests and mocks and types very complex, and I wasn't able to get the whole thing working. So I've simply removed these fromesm-config
. This is a breaking change for anyone who was doingimport { navigate } from '@openmrs/esm-config'
(or likewise with the other functions). I doubt anyone was doing that though, which is why I have not attached the BREAKING label.Only vaguely related,
navigate
is now a little bit smarter and will do a SPA navigation if possible even if the caller has included the origin in the URL. Previously,navigate({ to: 'https://dev3.openmrs.org/openmrs/spa/home' })
would do alocation.assign
.Screenshots
Will include screenshots in the patient chart PR.
Related Issue
Related to https://openmrs.atlassian.net/browse/O3-1594
Other