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) POC - Offline ready jobs #823

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

icrc-jofrancisco
Copy link
Contributor

@icrc-jofrancisco icrc-jofrancisco commented Nov 23, 2023

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. 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

IN PROGRESS

This Pull request solves a need to improve the experience when the user is offline.

It is intended to create a function for all microfront-ends (if the function exists) that will be executed when it is triggered in the esm-offline-tools-app.

The idea is that this function contains specific logic for each app to fetch data from the server (or specific offline logic) and that it caches these results, allowing all resources to be loaded dynamically.

Main idea implemented/to be implemented so far:

OfflineReady functions are dynamically loaded into the window.installedModules variable, accessible by all apps.

Offline functionality is managed through a toggle in the user menu, facilitated by the esm-offline-tools-app. Activating the toggle prompts a modal with spinner, tracking the execution progress of offlineReady functions across installed apps.

Upon successful completion, a success popup is displayed. In case of failure. The user can trigger function refresh by clicking the provided button.

Note: offline preparation is triggered using the event openmrs:offline-enabled. This event signals subscribed apps to execute the necessary functions.

Screenshots

Related Issue

Other

CC: @ibacher

@ibacher
Copy link
Member

ibacher commented Dec 4, 2023

@icrc-jofrancisco So I've thought about this for a bit and I think the thing to do here is instead of having a defined module callback, let's do this with a custom event. That way we can push the offline handling logic mostly down into apps themselves. Specifically, what I'm thinking is that we dispatch an event from setCurrentOfflineMode() after all the localStorage stuff like this:

window.dispatchEvent(
	new CustomEvent(
		`openmrs:offline-${mode === "on" ? "enabled" : "disabled"}`, 
		getCurrentOfflineMode()
	)
);

Then in each apps startupApp() it can have something like this:

window.addEventListener("openmrs:offline-enabled", ({ detail: offlineMode } : { detail: OfflineModeResult}) => setupOffline(offlineMode));

const offlineMode = getCurrentOfflineMode();
if (offlineMode.active) {
  setupOffline(offlineMode);
}

I like this because it means we don't need to figure out whether an app needs to be informed that offline mode was re-enabled or not, i.e., we can let each app determine how it responds to that event. There's also much less dynamic dispatch code that way.

Make sense?

@brandones
Copy link
Collaborator

@icrc-jofrancisco @ibacher What should we do about this PR?

@ibacher ibacher force-pushed the main branch 2 times, most recently from 8f994a6 to 9cee659 Compare July 22, 2024 18:54
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.

3 participants