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

(feat) Create a global app history utility #877

Merged
merged 12 commits into from
Jan 11, 2024
Merged

(feat) Create a global app history utility #877

merged 12 commits into from
Jan 11, 2024

Conversation

brandones
Copy link
Collaborator

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. Ensure your PR title includes a conventional commit label (such as feat, fix, or chore, among others). See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

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 of esm-config (kind of a strange place for them) and into this new library, along with the whole of esm-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, and interpolateUrl 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 from esm-config. This is a breaking change for anyone who was doing import { 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 a location.assign.

Screenshots

Will include screenshots in the patient chart PR.

Related Issue

Related to https://openmrs.atlassian.net/browse/O3-1594

Other

.eslintrc Show resolved Hide resolved
@@ -0,0 +1,35 @@
/** @module @category Breadcrumb */
Copy link
Collaborator Author

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

Copy link
Contributor

github-actions bot commented Jan 9, 2024

Size Change: -655 kB (-19%) 👏

Total Size: 2.84 MB

Filename Size Change
packages/apps/esm-devtools-app/dist/889.js 121 kB +12.7 kB (+12%) ⚠️
packages/apps/esm-implementer-tools-app/dist/889.js 121 kB +12.7 kB (+12%) ⚠️
packages/apps/esm-login-app/dist/889.js 121 kB +12.7 kB (+12%) ⚠️
packages/apps/esm-offline-tools-app/dist/889.js 121 kB +12.7 kB (+12%) ⚠️
packages/apps/esm-primary-navigation-app/dist/889.js 121 kB +12.7 kB (+12%) ⚠️
packages/framework/esm-framework/dist/openmrs-esm-framework.js 390 kB -382 kB (-49%) 🎉
packages/shell/esm-app-shell/dist/openmrs.bd65ff6ca798fc55.js 0 B -334 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
packages/apps/esm-devtools-app/dist/630.js 2.69 kB 0 B
packages/apps/esm-devtools-app/dist/729.js 6.79 kB 0 B
packages/apps/esm-devtools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-devtools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-devtools-app/dist/875.js 9.76 kB 0 B
packages/apps/esm-devtools-app/dist/961.js 25.3 kB 0 B
packages/apps/esm-devtools-app/dist/988.js 328 B 0 B
packages/apps/esm-devtools-app/dist/main.js 3.14 kB 0 B
packages/apps/esm-devtools-app/dist/openmrs-esm-devtools-app.js 3.18 kB 0 B
packages/apps/esm-implementer-tools-app/dist/319.js 633 B 0 B
packages/apps/esm-implementer-tools-app/dist/426.js 1.66 kB 0 B
packages/apps/esm-implementer-tools-app/dist/460.js 735 B 0 B
packages/apps/esm-implementer-tools-app/dist/56.js 3.07 kB 0 B
packages/apps/esm-implementer-tools-app/dist/560.js 9.6 kB 0 B
packages/apps/esm-implementer-tools-app/dist/574.js 560 B 0 B
packages/apps/esm-implementer-tools-app/dist/587.js 2.92 kB 0 B
packages/apps/esm-implementer-tools-app/dist/620.js 126 kB 0 B
packages/apps/esm-implementer-tools-app/dist/625.js 562 B 0 B
packages/apps/esm-implementer-tools-app/dist/651.js 6.86 kB 0 B
packages/apps/esm-implementer-tools-app/dist/727.js 33 kB 0 B
packages/apps/esm-implementer-tools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-implementer-tools-app/dist/738.js 6.79 kB 0 B
packages/apps/esm-implementer-tools-app/dist/757.js 560 B 0 B
packages/apps/esm-implementer-tools-app/dist/767.js 10.4 kB 0 B
packages/apps/esm-implementer-tools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-implementer-tools-app/dist/807.js 559 B 0 B
packages/apps/esm-implementer-tools-app/dist/833.js 681 B 0 B
packages/apps/esm-implementer-tools-app/dist/913.js 61.2 kB 0 B
packages/apps/esm-implementer-tools-app/dist/main.js 73.3 kB 0 B
packages/apps/esm-implementer-tools-app/dist/openmrs-esm-implementer-tools-app.js 3.3 kB 0 B
packages/apps/esm-login-app/dist/111.js 1.22 kB 0 B
packages/apps/esm-login-app/dist/126.js 2.5 kB 0 B
packages/apps/esm-login-app/dist/173.js 1.22 kB 0 B
packages/apps/esm-login-app/dist/224.js 256 B 0 B
packages/apps/esm-login-app/dist/236.js 272 B 0 B
packages/apps/esm-login-app/dist/240.js 364 B 0 B
packages/apps/esm-login-app/dist/272.js 264 B 0 B
packages/apps/esm-login-app/dist/319.js 692 B 0 B
packages/apps/esm-login-app/dist/336.js 234 B 0 B
packages/apps/esm-login-app/dist/363.js 30.1 kB +19 B (0%)
packages/apps/esm-login-app/dist/460.js 782 B 0 B
packages/apps/esm-login-app/dist/539.js 298 B 0 B
packages/apps/esm-login-app/dist/56.js 3.06 kB 0 B
packages/apps/esm-login-app/dist/574.js 609 B 0 B
packages/apps/esm-login-app/dist/625.js 600 B 0 B
packages/apps/esm-login-app/dist/627.js 257 B 0 B
packages/apps/esm-login-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-login-app/dist/644.js 305 B 0 B
packages/apps/esm-login-app/dist/673.js 284 B 0 B
packages/apps/esm-login-app/dist/729.js 6.78 kB 0 B
packages/apps/esm-login-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-login-app/dist/757.js 698 B 0 B
packages/apps/esm-login-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-login-app/dist/807.js 961 B 0 B
packages/apps/esm-login-app/dist/833.js 727 B 0 B
packages/apps/esm-login-app/dist/836.js 22.5 kB 0 B
packages/apps/esm-login-app/dist/main.js 56.6 kB +78 B (0%)
packages/apps/esm-login-app/dist/openmrs-esm-login-app.js 3.37 kB +47 B (+1%)
packages/apps/esm-offline-tools-app/dist/319.js 1.14 kB 0 B
packages/apps/esm-offline-tools-app/dist/430.js 55.4 kB 0 B
packages/apps/esm-offline-tools-app/dist/460.js 1.32 kB 0 B
packages/apps/esm-offline-tools-app/dist/56.js 3.07 kB 0 B
packages/apps/esm-offline-tools-app/dist/574.js 1.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/625.js 1.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-offline-tools-app/dist/729.js 6.79 kB 0 B
packages/apps/esm-offline-tools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-offline-tools-app/dist/757.js 1.2 kB 0 B
packages/apps/esm-offline-tools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-offline-tools-app/dist/807.js 1.1 kB 0 B
packages/apps/esm-offline-tools-app/dist/833.js 1.22 kB 0 B
packages/apps/esm-offline-tools-app/dist/922.js 81.2 kB 0 B
packages/apps/esm-offline-tools-app/dist/main.js 136 kB 0 B
packages/apps/esm-offline-tools-app/dist/openmrs-esm-offline-tools-app.js 3.29 kB 0 B
packages/apps/esm-primary-navigation-app/dist/319.js 218 B 0 B
packages/apps/esm-primary-navigation-app/dist/34.js 21.1 kB 0 B
packages/apps/esm-primary-navigation-app/dist/460.js 240 B 0 B
packages/apps/esm-primary-navigation-app/dist/574.js 205 B 0 B
packages/apps/esm-primary-navigation-app/dist/625.js 207 B 0 B
packages/apps/esm-primary-navigation-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-primary-navigation-app/dist/729.js 6.79 kB 0 B
packages/apps/esm-primary-navigation-app/dist/735.js 2.64 kB 0 B
packages/apps/esm-primary-navigation-app/dist/757.js 217 B 0 B
packages/apps/esm-primary-navigation-app/dist/762.js 7.29 kB 0 B
packages/apps/esm-primary-navigation-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-primary-navigation-app/dist/807.js 274 B 0 B
packages/apps/esm-primary-navigation-app/dist/833.js 237 B 0 B
packages/apps/esm-primary-navigation-app/dist/958.js 22.1 kB 0 B
packages/apps/esm-primary-navigation-app/dist/main.js 44.7 kB 0 B
packages/apps/esm-primary-navigation-app/dist/openmrs-esm-primary-navigation-app.js 3.23 kB 0 B
packages/framework/esm-api/dist/openmrs-esm-api.js 16.1 kB +6 kB (+60%) 🆘
packages/framework/esm-breadcrumbs/dist/openmrs-esm-breadcrumbs.js 0 B -2.66 kB (removed) 🏆
packages/framework/esm-config/dist/openmrs-esm-module-config.js 7.62 kB -251 B (-3%)
packages/framework/esm-dynamic-loading/dist/openmrs-esm-dynamic-loading.js 2.12 kB 0 B
packages/framework/esm-error-handling/dist/openmrs-esm-error-handling.js 894 B 0 B
packages/framework/esm-extensions/dist/openmrs-esm-extensions.js 8.05 kB 0 B
packages/framework/esm-feature-flags/dist/openmrs-esm-feature-flags.js 1.67 kB 0 B
packages/framework/esm-framework/dist/455.openmrs-esm-framework.js 4.57 kB 0 B
packages/framework/esm-framework/dist/530.openmrs-esm-framework.js 2.92 kB 0 B
packages/framework/esm-framework/dist/645.openmrs-esm-framework.js 9.31 kB 0 B
packages/framework/esm-framework/dist/655.openmrs-esm-framework.js 6.83 kB 0 B
packages/framework/esm-framework/dist/710.openmrs-esm-framework.js 6.48 kB 0 B
packages/framework/esm-framework/dist/735.openmrs-esm-framework.js 2.66 kB 0 B
packages/framework/esm-framework/dist/788.openmrs-esm-framework.js 42.9 kB 0 B
packages/framework/esm-globals/dist/openmrs-esm-globals.js 756 B 0 B
packages/framework/esm-navigation/dist/openmrs-esm-navigation.js 9.24 kB 0 B
packages/framework/esm-offline/dist/openmrs-esm-offline.js 34.4 kB 0 B
packages/framework/esm-react-utils/dist/openmrs-esm-react-utils.js 15.5 kB +15 B (0%)
packages/framework/esm-routes/dist/openmrs-esm-utils.js 1.46 kB 0 B
packages/framework/esm-state/dist/openmrs-esm-state.js 888 B 0 B
packages/framework/esm-styleguide/dist/openmrs-esm-styleguide.js 19 kB -242 B (-1%)
packages/framework/esm-utils/dist/openmrs-esm-utils.js 11.2 kB 0 B
packages/shell/esm-app-shell/dist/08a99d285a4ddb28.js 0 B -6.45 kB (removed) 🏆
packages/shell/esm-app-shell/dist/1348b3a910102b7f.js 1.58 kB 0 B
packages/shell/esm-app-shell/dist/af34d1307807a2df.js 6.46 kB 0 B
packages/shell/esm-app-shell/dist/b66a463116735f62.js 3.81 kB 0 B
packages/shell/esm-app-shell/dist/openmrs.539a8c68f4378cc9.js 334 kB 0 B
packages/shell/esm-app-shell/dist/service-worker.js 60.5 kB 0 B
packages/tooling/openmrs/dist/cli.js 2.85 kB 0 B
packages/tooling/openmrs/dist/commands/assemble.js 2.4 kB 0 B
packages/tooling/openmrs/dist/commands/build.js 1.34 kB 0 B
packages/tooling/openmrs/dist/commands/debug.js 545 B 0 B
packages/tooling/openmrs/dist/commands/develop.js 2.59 kB 0 B
packages/tooling/openmrs/dist/commands/index.js 438 B 0 B
packages/tooling/openmrs/dist/commands/start.js 851 B 0 B
packages/tooling/openmrs/dist/index.js 517 B 0 B
packages/tooling/openmrs/dist/runner.js 637 B 0 B
packages/tooling/openmrs/dist/utils/config.js 728 B 0 B
packages/tooling/openmrs/dist/utils/debugger.js 576 B 0 B
packages/tooling/openmrs/dist/utils/dependencies.js 648 B 0 B
packages/tooling/openmrs/dist/utils/helpers.js 395 B 0 B
packages/tooling/openmrs/dist/utils/importmap.js 3.07 kB 0 B
packages/tooling/openmrs/dist/utils/index.js 444 B 0 B
packages/tooling/openmrs/dist/utils/logger.js 368 B 0 B
packages/tooling/openmrs/dist/utils/npmConfig.js 830 B 0 B
packages/tooling/openmrs/dist/utils/untar.js 722 B 0 B
packages/tooling/openmrs/dist/utils/variables.js 192 B 0 B
packages/tooling/openmrs/dist/utils/webpack.js 278 B 0 B
packages/tooling/webpack-config/dist/index.js 3.58 kB 0 B

compressed-size-action

Copy link
Member

@ibacher ibacher left a 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';
Copy link
Member

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).

Copy link
Collaborator Author

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.

Comment on lines 25 to 32
initializeHistory();

window.addEventListener('single-spa:routing-event', (evt) => {
const history = getHistory();
if (history[history.length - 1] !== window.location.href) {
addToHistory(window.location.href);
}
});
Copy link
Member

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.

Copy link
Collaborator Author

@brandones brandones Jan 10, 2024

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.

packages/framework/esm-navigation/src/history/history.ts Outdated Show resolved Hide resolved
packages/framework/esm-navigation/src/history/history.ts Outdated Show resolved Hide resolved
.eslintrc Show resolved Hide resolved
@ibacher ibacher merged commit 18368f5 into main Jan 11, 2024
9 checks passed
@ibacher ibacher deleted the history-navigation branch January 11, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants