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: dhis2 connection status [LIBS-315] #1203

Merged
merged 93 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
614621b
feat: track dhis2 connection status with hook
KaiVandivier May 23, 2022
5ace882
feat(offline): ping server for status periodically
KaiVandivier May 24, 2022
c3714ef
fix: use better endpoint
KaiVandivier Jun 6, 2022
2b6135a
chore: add a comment
KaiVandivier Jun 6, 2022
d901403
fix: file extension
KaiVandivier Jun 6, 2022
144d12d
test(offline): add custom data provider to tests
KaiVandivier Jun 6, 2022
17aafd6
Merge branch 'master' into feat-dhis2-connection-status
KaiVandivier Nov 9, 2022
e1d59e5
fix: fix tests
KaiVandivier Nov 9, 2022
a5b3a27
chore: satisfy types
KaiVandivier Nov 9, 2022
0329746
feat: useProgressiveInterval hook
KaiVandivier Nov 11, 2022
23a258a
feat: use smart intervals in connection status (wip)
KaiVandivier Nov 11, 2022
3d60b30
fix: pinging, back-off, pausing, fn references
KaiVandivier Nov 14, 2022
70b6869
fix: pausing correctly
KaiVandivier Nov 15, 2022
9566408
fix: don't start pinging if window isn't focused
KaiVandivier Nov 18, 2022
b9af561
chore: remove unused eslint ignore
KaiVandivier Nov 18, 2022
a61802b
feat: add 'invokeCallbackImmediately' fn
KaiVandivier Nov 18, 2022
b4d97bd
feat: ping on network status changes
KaiVandivier Nov 18, 2022
88d64c4
fix: enter standby when network changes while blurred
KaiVandivier Nov 21, 2022
435f12c
chore: format
KaiVandivier Nov 21, 2022
ccf6105
fix: only ping when going offline to save resources
KaiVandivier Nov 21, 2022
ecb8961
fix: don't increment delay on immediate cb unless regular timer has e…
KaiVandivier Nov 21, 2022
a1055a9
refactor: smart interval as class
KaiVandivier Nov 22, 2022
7d03d21
fix: use data engine for pings to avoid rerenders; handle fetch errors
KaiVandivier Nov 23, 2022
575db1e
refactor: make class properties private again
KaiVandivier Nov 25, 2022
fb3fe64
feat: handle sw-free conditions; simplify logic
KaiVandivier Nov 28, 2022
40af57d
chore: remove interval hook
KaiVandivier Dec 5, 2022
05b5801
fix: don't check auth
KaiVandivier Dec 5, 2022
ba838db
refactor: use shorter isConnected name
KaiVandivier Dec 7, 2022
2b9019e
feat: add lastConnected value
KaiVandivier Dec 8, 2022
2d73194
fix: await callbacks to reset correct intervals
KaiVandivier Dec 8, 2022
41f17f8
chore: cleanup
KaiVandivier Dec 8, 2022
6cf649b
fix: update subscription callback name
KaiVandivier Dec 8, 2022
2a86c2d
refactor: rename to NetworkStatus
KaiVandivier Dec 13, 2022
81ee476
refactor: rename type to match NetworkStatus
KaiVandivier Dec 13, 2022
d331171
chore: fix import
KaiVandivier Dec 13, 2022
d2e5ffc
chore: other renaming clean-up
KaiVandivier Dec 13, 2022
c63b1a7
chore: bump cli-style version
KaiVandivier Dec 13, 2022
e590d5c
Merge branch 'master' into feat-dhis2-connection-status
KaiVandivier Dec 14, 2022
39c3e4d
refactor: rename method for clarity
KaiVandivier Dec 14, 2022
3a28264
chore: clarify logs
KaiVandivier Dec 14, 2022
beffd46
fix: bump cli-app-scripts version for jest v27
KaiVandivier Dec 24, 2022
b1ca209
refactor: use ping query for easier testing
KaiVandivier Dec 27, 2022
2be05a4
ci: use node 14
KaiVandivier Jan 17, 2023
8bb78cd
fix: accept header on ping requests
KaiVandivier Jan 19, 2023
b9fdbd6
fix: check for err.type instead of err.message
KaiVandivier Jan 19, 2023
62a0e10
chore: add comment to remove clg
KaiVandivier Jan 19, 2023
274f11a
test: fix tests for RestAPILink
KaiVandivier Jan 19, 2023
76e2c21
chore: prep for tests
KaiVandivier Jan 19, 2023
307579f
test: initial test commit (dirty wip)
KaiVandivier Jan 19, 2023
f10365c
refactor: use a `start` method on SmartInterval
KaiVandivier Jan 20, 2023
a90fa13
fix(smart-interval): delay reset after 'partial standby'
KaiVandivier Jan 20, 2023
e96e9c1
refactor: use a function for smartInterval instead of class
KaiVandivier Jan 20, 2023
a2997df
Merge branch 'master' into feat-dhis2-connection-status
KaiVandivier Jan 20, 2023
c9a1ecf
chore: remove comment
KaiVandivier Jan 20, 2023
b1e060b
test: some more testing attempts (dirty)
KaiVandivier Jan 24, 2023
5d76a7e
refactor: don't await callback
KaiVandivier Jan 25, 2023
aeda89b
test(dhis2-connection-status): tweak test for smart interval
HendrikThePendric Jan 25, 2023
80e37ae
test: delays in ping interval
KaiVandivier Feb 1, 2023
ccf7803
refactor: only create smartInterval once
KaiVandivier Feb 1, 2023
94fe75f
test: resetting ping interval
KaiVandivier Feb 1, 2023
b31cc2c
test: standby behavior
KaiVandivier Feb 1, 2023
390a29c
test: offline & refocusing behavior
KaiVandivier Feb 1, 2023
627bf5c
fix: maintain lastConnected when disconnected during startup
KaiVandivier Feb 3, 2023
6225963
test: lastConnected handling
KaiVandivier Feb 3, 2023
ff5dfcd
fix: initialize to correct status based on offline interface
KaiVandivier Feb 6, 2023
9f05cbc
chore: comment updates
KaiVandivier Feb 6, 2023
d0663f3
fix: set lastConnected if not set yet and starting while offline
KaiVandivier Feb 6, 2023
db0edc1
test: initialization conditions
KaiVandivier Feb 6, 2023
0112b4c
chore: remove console log
KaiVandivier Feb 7, 2023
78c5b6f
chore: reorganize tests
KaiVandivier Feb 7, 2023
7771142
test: refactor to generalize to any default values
KaiVandivier Feb 7, 2023
a9bd40b
chore: clean up smartInterval tests
KaiVandivier Feb 7, 2023
0fae4b7
chore: ignore eslint warning
KaiVandivier Feb 7, 2023
03160cc
test: fix test for offlineInterface effects
KaiVandivier Feb 7, 2023
cf81622
test: refactor to improve assertions on `setTimeout` delays
KaiVandivier Feb 7, 2023
559e86f
chore: remove console log
KaiVandivier Feb 7, 2023
d32ef70
fix: clear lastConnected when online
KaiVandivier Feb 9, 2023
04add33
refactor: setting lastConnected on startup
KaiVandivier Feb 9, 2023
573238a
fix: make lastConnected specific to each app
KaiVandivier Feb 9, 2023
852292e
docs: reorganize and update docs
KaiVandivier Feb 10, 2023
47c3644
docs: useDhis2ConnectionStatus
KaiVandivier Feb 10, 2023
ab2abca
refactor: remove unused function
KaiVandivier Feb 13, 2023
b0e38cb
chore: explanatory comments
KaiVandivier Feb 13, 2023
1585c50
docs: clarify importance of useDhis2ConnectionStatus
KaiVandivier Feb 16, 2023
0389e3f
refactor: only use logs when specified in dev env
KaiVandivier Feb 16, 2023
86b61f8
fix: allow logging in production env for netlify previews
KaiVandivier Feb 17, 2023
86f885a
chore: undo changes from old ping endpoint
KaiVandivier Mar 2, 2023
c1675e2
fix: migrate to new ping endpoint
KaiVandivier Mar 2, 2023
532f3ae
chore: remove unused data service from offline service
KaiVandivier Mar 2, 2023
4e36fa9
chore: reorganize connection status dir
KaiVandivier Mar 2, 2023
9f62d6c
fix: don't ping on unsupported server versions
KaiVandivier Mar 2, 2023
de423f5
Merge branch 'master' into feat-dhis2-connection-status
KaiVandivier Mar 2, 2023
e7d6065
fix: choose default timer values
KaiVandivier Mar 2, 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
26 changes: 13 additions & 13 deletions examples/cra/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,26 +1054,26 @@
integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==

"@dhis2/app-runtime@file:../../runtime":
version "3.5.0"
version "3.6.1"
dependencies:
"@dhis2/app-service-alerts" "3.5.0"
"@dhis2/app-service-config" "3.5.0"
"@dhis2/app-service-data" "3.5.0"
"@dhis2/app-service-offline" "3.5.0"
"@dhis2/app-service-alerts" "3.6.1"
"@dhis2/app-service-config" "3.6.1"
"@dhis2/app-service-data" "3.6.1"
"@dhis2/app-service-offline" "3.6.1"

"@dhis2/app-service-alerts@3.5.0", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.5.0"
"@dhis2/app-service-alerts@3.6.1", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.6.1"

"@dhis2/app-service-config@3.5.0", "@dhis2/app-service-config@file:../../services/config":
version "3.5.0"
"@dhis2/app-service-config@3.6.1", "@dhis2/app-service-config@file:../../services/config":
version "3.6.1"

"@dhis2/app-service-data@3.5.0", "@dhis2/app-service-data@file:../../services/data":
version "3.5.0"
"@dhis2/app-service-data@3.6.1", "@dhis2/app-service-data@file:../../services/data":
version "3.6.1"
dependencies:
react-query "^3.13.11"

"@dhis2/app-service-offline@3.5.0", "@dhis2/app-service-offline@file:../../services/offline":
version "3.5.0"
"@dhis2/app-service-offline@3.6.1", "@dhis2/app-service-offline@file:../../services/offline":
version "3.6.1"
dependencies:
lodash "^4.17.21"

Expand Down
1 change: 0 additions & 1 deletion examples/query-playground/src/components/QueryResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import styles from './QueryResults.module.css'
export const QueryResults = ({ result }) => {
return (
<div className={styles.results}>
<style jsx>{styles}</style>
<Editor
value={result}
theme="github"
Expand Down
38 changes: 24 additions & 14 deletions examples/query-playground/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1789,27 +1789,37 @@
dependencies:
moment "^2.24.0"

"@dhis2/app-runtime@*", "@dhis2/app-runtime@^2.2.2", "@dhis2/app-runtime@file:../../runtime":
version "3.5.0"
"@dhis2/app-runtime@*":
version "3.7.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-3.7.0.tgz#be738255ae95aaf597f9f59d1a56566b1a035dae"
integrity sha512-lKHgjaVVnCC5xxThckTVS0EH5mQlrSOdM8bC/7BSz5r9ztgLXJGUgxbnOvVbh95S/zFS9eyDvIls1HGum/MHTQ==
dependencies:
"@dhis2/app-service-alerts" "3.5.0"
"@dhis2/app-service-config" "3.5.0"
"@dhis2/app-service-data" "3.5.0"
"@dhis2/app-service-offline" "3.5.0"
"@dhis2/app-service-alerts" "3.7.0"
"@dhis2/app-service-config" "3.7.0"
"@dhis2/app-service-data" "3.7.0"
"@dhis2/app-service-offline" "3.7.0"

"@dhis2/app-service-alerts@3.5.0", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.5.0"
"@dhis2/app-runtime@^2.2.2", "@dhis2/app-runtime@file:../../runtime":
version "3.6.1"
dependencies:
"@dhis2/app-service-alerts" "3.6.1"
"@dhis2/app-service-config" "3.6.1"
"@dhis2/app-service-data" "3.6.1"
"@dhis2/app-service-offline" "3.6.1"

"@dhis2/app-service-config@3.5.0", "@dhis2/app-service-config@file:../../services/config":
version "3.5.0"
"@dhis2/app-service-alerts@3.6.1", "@dhis2/app-service-alerts@3.7.0", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.6.1"

"@dhis2/app-service-data@3.5.0", "@dhis2/app-service-data@file:../../services/data":
version "3.5.0"
"@dhis2/app-service-config@3.6.1", "@dhis2/app-service-config@3.7.0", "@dhis2/app-service-config@file:../../services/config":
version "3.6.1"

"@dhis2/app-service-data@3.6.1", "@dhis2/app-service-data@3.7.0", "@dhis2/app-service-data@file:../../services/data":
version "3.6.1"
dependencies:
react-query "^3.13.11"

"@dhis2/app-service-offline@3.5.0", "@dhis2/app-service-offline@file:../../services/offline":
version "3.5.0"
"@dhis2/app-service-offline@3.6.1", "@dhis2/app-service-offline@3.7.0", "@dhis2/app-service-offline@file:../../services/offline":
version "3.6.1"
dependencies:
lodash "^4.17.21"

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"devDependencies": {
"@dhis2/cli-app-scripts": "^6.2.0",
"@dhis2/cli-style": "^10.4.1",
"@dhis2/cli-style": "^10.4.3",
"@dhis2/cli-utils-docsite": "^2.0.3",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
Expand Down
1 change: 1 addition & 0 deletions runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { useAlerts, useAlert } from '@dhis2/app-service-alerts'

export {
useOnlineStatus,
useDhis2ConnectionStatus,
useOnlineStatusMessage,
useCacheableSection,
CacheableSection,
Expand Down
2 changes: 1 addition & 1 deletion services/offline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"coverage": "yarn test --coverage"
},
"peerDependencies": {
"@dhis2/app-service-alerts": "3.7.0",
"@dhis2/app-service-data": "3.7.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
Expand Down
46 changes: 28 additions & 18 deletions services/offline/src/__tests__/integration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AlertsProvider } from '@dhis2/app-service-alerts'
import { CustomDataProvider } from '@dhis2/app-service-data'
import { act, fireEvent, render, screen } from '@testing-library/react'
import React from 'react'
import {
Expand Down Expand Up @@ -70,10 +71,15 @@ const TestSingleSection = (props?: any) => {
// Props are spread so they can be overwritten
return (
<AlertsProvider>
<OfflineProvider offlineInterface={mockOfflineInterface} {...props}>
<TestControls id={'1'} {...props} />
<TestSection id={'1'} {...props} />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider
offlineInterface={mockOfflineInterface}
{...props}
>
<TestControls id={'1'} {...props} />
<TestSection id={'1'} {...props} />
</OfflineProvider>
</CustomDataProvider>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OfflineProvider now uses a data provider to use the engine to make a data query to /api/system/ping

The same changes will be repeated in the next few test files

</AlertsProvider>
)
}
Expand Down Expand Up @@ -232,12 +238,14 @@ describe('Coordination between useCacheableSection and CacheableSection', () =>
const TwoTestSections = (props?: any) => (
// Props are spread so they can be overwritten (but only on one section)
<AlertsProvider>
<OfflineProvider offlineInterface={mockOfflineInterface} {...props}>
<TestControls id={'1'} {...props} />
<TestSection id={'1'} {...props} />
<TestControls id={'2'} />
<TestSection id={'2'} />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider offlineInterface={mockOfflineInterface} {...props}>
<TestControls id={'1'} {...props} />
<TestSection id={'1'} {...props} />
<TestControls id={'2'} />
<TestSection id={'2'} />
</OfflineProvider>
</CustomDataProvider>
</AlertsProvider>
)

Expand Down Expand Up @@ -288,14 +296,16 @@ describe('useCacheableSection can be used inside a child of CacheableSection', (
// Props are spread so they can be overwritten
return (
<AlertsProvider>
<OfflineProvider
offlineInterface={mockOfflineInterface}
{...props}
>
<TestSection id={'1'} {...props}>
<TestControls id={'1'} {...props} />
</TestSection>
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider
offlineInterface={mockOfflineInterface}
{...props}
>
<TestSection id={'1'} {...props}>
<TestControls id={'1'} {...props} />
</TestSection>
</OfflineProvider>
</CustomDataProvider>
</AlertsProvider>
)
}
Expand Down
4 changes: 3 additions & 1 deletion services/offline/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export { OfflineProvider } from './lib/offline-provider'
export { CacheableSection, useCacheableSection } from './lib/cacheable-section'
export { useCachedSections } from './lib/cacheable-section-state'
export { useOnlineStatus } from './lib/online-status'
// Use "useOnlineStatus" name for backwards compatibility
export { useNetworkStatus as useOnlineStatus } from './lib/network-status'
export { useOnlineStatusMessage } from './lib/online-status-message'
export { clearSensitiveCaches } from './lib/clear-sensitive-caches'
export { useDhis2ConnectionStatus } from './lib/dhis2-connection-status'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, waitFor } from '@testing-library/react'
import { act, renderHook } from '@testing-library/react-hooks'
import React from 'react'
import { useOnlineStatus } from '../online-status'
import { useNetworkStatus as useOnlineStatus } from '../network-status'

interface CapturedEventListeners {
[index: string]: EventListener
Expand Down
41 changes: 26 additions & 15 deletions services/offline/src/lib/__tests__/offline-provider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CustomDataProvider } from '@dhis2/app-service-data'
import { render, screen, waitFor } from '@testing-library/react'
import React from 'react'
import { mockOfflineInterface } from '../../utils/test-mocks'
Expand Down Expand Up @@ -27,9 +28,11 @@ afterEach(() => {
describe('Testing offline provider', () => {
it('Should render without failing', () => {
render(
<OfflineProvider offlineInterface={mockOfflineInterface}>
<div data-testid="test-div" />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider offlineInterface={mockOfflineInterface}>
<div data-testid="test-div" />
</OfflineProvider>
</CustomDataProvider>
)

expect(screen.getByTestId('test-div')).toBeInTheDocument()
Expand All @@ -54,9 +57,11 @@ describe('Testing offline provider', () => {
}

render(
<OfflineProvider offlineInterface={testOfflineInterface}>
<CachedSections />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider offlineInterface={testOfflineInterface}>
<CachedSections />
</OfflineProvider>
</CustomDataProvider>
)

const { getByTestId } = screen
Expand All @@ -83,19 +88,23 @@ describe('Testing offline provider', () => {
}

render(
<OfflineProvider offlineInterface={mockOfflineInterface}>
<TestConsumer />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider offlineInterface={mockOfflineInterface}>
<TestConsumer />
</OfflineProvider>
</CustomDataProvider>
)

expect(screen.getByTestId('test-div')).toBeInTheDocument()
})

it('Should render without failing when no offlineInterface is provided', () => {
render(
<OfflineProvider>
<div data-testid="test-div" />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider>
<div data-testid="test-div" />
</OfflineProvider>
</CustomDataProvider>
)
expect(screen.getByTestId('test-div')).toBeInTheDocument()
})
Expand All @@ -106,9 +115,11 @@ describe('Testing offline provider', () => {
pwaEnabled: false,
}
render(
<OfflineProvider offlineInterface={testOfflineInterface}>
<div data-testid="test-div" />
</OfflineProvider>
<CustomDataProvider data={{}}>
<OfflineProvider offlineInterface={testOfflineInterface}>
<div data-testid="test-div" />
</OfflineProvider>
</CustomDataProvider>
)

expect(screen.getByTestId('test-div')).toBeInTheDocument()
Expand Down
Loading