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(pwa): track online status [LIBS-315] #718

Merged
merged 41 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
15d9a6c
fix: migrate to IDB to store dhis2 base url
KaiVandivier May 7, 2022
19bc59a
refactor: init function
KaiVandivier May 8, 2022
1df3aa2
fix: add complete env to dev SW
KaiVandivier May 8, 2022
c2bac27
refactor: get base url api
KaiVandivier May 19, 2022
efbb9ed
feat(pwa): use SW to track dhis2 server connection (most strategies)
KaiVandivier May 20, 2022
ebf0337
refactor(sw): convert recording mode to strategy & use status plugin
KaiVandivier May 23, 2022
520fffc
refactor: rename online status to dhis2 connection status for clarity
KaiVandivier May 23, 2022
cceb300
fix(deps): use latest app-runtime
KaiVandivier Jun 1, 2022
ebc74ef
chore(pwa-app): add request tester
KaiVandivier Jun 6, 2022
19d7a3f
feat(offline-interface): add subscription to connection status from SW
KaiVandivier Jun 6, 2022
f6f4590
chore(pwa-app): temporarily remove dependency
KaiVandivier Jun 6, 2022
247dfd2
fix: fallback to localStorage for baseUrl to avoid breaking change
KaiVandivier Jun 7, 2022
2239d93
Merge branch 'master' into feat-track-online-status
KaiVandivier Oct 18, 2022
edef23d
chore: format
KaiVandivier Oct 18, 2022
578e224
Merge branch 'master' into feat-track-online-status
KaiVandivier Nov 9, 2022
feb70da
chore: formatting
KaiVandivier Nov 9, 2022
7691af9
chore: add some tools for testing connection status
KaiVandivier Nov 24, 2022
c184c86
fix: exclude pings from cache
KaiVandivier Nov 28, 2022
d62139e
fix: treat 401 as disconnected
KaiVandivier Nov 28, 2022
23cf8a9
fix: don't check auth
KaiVandivier Dec 5, 2022
c056532
Merge branch 'master' into feat-track-online-status
KaiVandivier Dec 5, 2022
e20e8ff
refactor: make reusable getAllClientsInScope fn
KaiVandivier Dec 5, 2022
6bba488
refactor: clean up
KaiVandivier Dec 6, 2022
01977bc
fix: throttle status broadcasts
KaiVandivier Dec 6, 2022
b866018
fix: use shorter isConnected name
KaiVandivier Dec 7, 2022
159a275
chore: rename set-up-service-worker
KaiVandivier Dec 7, 2022
7cf035e
fix: change subscription callback name
KaiVandivier Dec 8, 2022
3aad548
chore: some more dev utils
KaiVandivier Dec 13, 2022
eb1f4f6
chore: satisfy linter
KaiVandivier Dec 14, 2022
9070125
chore: update comments
KaiVandivier Dec 14, 2022
2ab1602
refactor: clarify systemInfo and baseUrl states
KaiVandivier Dec 14, 2022
d62d354
chore: clarify todos
KaiVandivier Dec 21, 2022
c62b38f
chore: update comment
KaiVandivier Dec 27, 2022
5644f0d
fix: wait for offline interface to be ready for connection status
KaiVandivier Feb 6, 2023
a3c13f9
chore: fix typo
KaiVandivier Feb 13, 2023
6039757
chore: update temp test scripts
KaiVandivier Feb 13, 2023
b921993
chore: remove console logs
KaiVandivier Feb 16, 2023
2d89e62
chore: clear up test scripts
KaiVandivier Feb 16, 2023
520e813
fix(sw): use NetworkOnly for new ping endpoint
KaiVandivier Mar 3, 2023
9ee11bd
feat: use connection status from app runtime
KaiVandivier Mar 3, 2023
6751903
Merge branch 'master' into feat-track-online-status
KaiVandivier Mar 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: clarify todos
  • Loading branch information
KaiVandivier committed Dec 21, 2022
commit d62d354efc936b9183087522f437e6bc49856bf0
2 changes: 1 addition & 1 deletion adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const ServerVersionProvider = ({
return
}
// If no URL found in DB, try localStorage
// TODO: deprecate
// (previous adapter versions stored the base URL there)
const baseUrlFromLocalStorage =
window.localStorage.DHIS2_BASE_URL
if (baseUrlFromLocalStorage) {
Expand Down
7 changes: 4 additions & 3 deletions examples/pwa-app/src/components/RequestTester.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useDataEngine } from '@dhis2/app-runtime'
// todo: update import once app-runtime is released
// importing from app-service-offline makes testing locally simpler
// todo: update import to app-runtime once app-runtime PR is merged
// import { useDhis2ConnectionStatus } from '@dhis2/app-service-offline'
import { Box, Button, ButtonStrip, Help } from '@dhis2/ui'
import React from 'react'
Expand All @@ -16,8 +17,8 @@ const query = {
export default function RequestTester() {
const engine = useDataEngine()

// todo: uncomment this and the import to test once the 'temp' scripts in
// pkg.json have been run
// While testing this PR, uncomment this and the import to test once the
// 'temp' scripts in pkg.json have been run:
// const { isConnected, lastConnected } = useDhis2ConnectionStatus()
const [isConnected, lastConnected] = [true, null]

Expand Down
4 changes: 1 addition & 3 deletions pwa/src/lib/base-url-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ function openBaseUrlsDB() {
})
}

/** Deletes the DB */
/** Deletes the DB (probably not needed) */
// function deleteBaseUrlsDB() {
// return deleteDB(BASE_URL_DB)
// }

// todo: maybe this should also send a message to the service worker
// that can be handled by the next requests... but what if no requests happen?
export async function setBaseUrlByAppName({ appName, baseUrl }) {
const db = await openBaseUrlsDB()
return db.put(BASE_URL_STORE, { appName, baseUrl })
Expand Down
4 changes: 2 additions & 2 deletions pwa/src/service-worker/dhis2-connection-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function initDhis2ConnectionStatus() {
// Throttle this a bit to reduce SW/client messaging
const BROADCAST_INTERVAL_MS = 1000
const broadcastDhis2ConnectionStatus = throttle(async (isConnected) => {
// todo: remove
// todo: remove log after testing the PR
console.log('sw: broadcasting update', { newIsConnected: isConnected })

const clients = await getAllClientsInScope()
Expand Down Expand Up @@ -62,7 +62,7 @@ async function isRequestToDhis2Server(request) {
* https://developer.chrome.com/docs/workbox/using-plugins/
*/
export const dhis2ConnectionStatusPlugin = {
// todo: remove console logs
// todo: remove console logs after testing the PR
fetchDidFail: async ({ request, error }) => {
console.log('sw: fetch FAILED', { request, error })

Expand Down