From 25ebc5853f5d3aaaf64d16fe1789321f32dbed38 Mon Sep 17 00:00:00 2001 From: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com> Date: Tue, 14 Mar 2023 14:14:34 +0100 Subject: [PATCH] fix: local offline handling [DHIS2-12937] (#2230) * fix: migrate to useDhis2ConnectionStatus * chore: update @dhis2/analytics for offline support --------- Co-authored-by: Edoardo Sabadelli --- package.json | 6 +- src/components/DashboardsBar/Chip.js | 4 +- src/components/DashboardsBar/Content.js | 4 +- .../DashboardsBar/__tests__/Chip.spec.js | 2 +- .../__tests__/DashboardsBar.spec.js | 2 +- .../__tests__/ItemContextMenu.offline.spec.js | 5 +- .../__tests__/ItemContextMenu.spec.js | 5 +- .../__tests__/ViewAsMenuItems.spec.js | 33 +++--- .../Item/VisualizationItem/ItemFooter.js | 4 +- .../Visualization/MapPlugin.js | 4 +- src/components/MenuItemWithTooltip.js | 4 +- src/components/__tests__/App.spec.js | 5 +- src/pages/edit/ActionsBar.js | 8 +- .../edit/ItemSelector/ItemSearchField.js | 4 +- src/pages/edit/LayoutModal.js | 4 +- src/pages/edit/TitleBar.js | 4 +- src/pages/edit/__tests__/ActionsBar.spec.js | 5 +- .../__tests__/FilterSettingsDialog.spec.js | 2 +- src/pages/start/StartScreen.js | 4 +- src/pages/view/FilterBar/FilterBadge.js | 4 +- src/pages/view/FilterBar/FilterBar.js | 4 +- .../FilterBar/__tests__/FilterBadge.spec.js | 2 +- src/pages/view/TitleBar/ActionsBar.js | 8 +- src/pages/view/TitleBar/FilterSelector.js | 4 +- .../view/TitleBar/StarDashboardButton.js | 4 +- .../TitleBar/__tests__/FilterSelector.spec.js | 10 +- src/pages/view/ViewDashboard.js | 4 +- .../view/__tests__/ViewDashboard.spec.js | 2 +- yarn.lock | 107 ++++++++++-------- 29 files changed, 146 insertions(+), 112 deletions(-) diff --git a/package.json b/package.json index da7d7e93a..917b807e7 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "private": true, "license": "BSD-3-Clause", "dependencies": { - "@dhis2/analytics": "^24.2.5", - "@dhis2/app-runtime": "^3.7.0", + "@dhis2/analytics": "^24.9.2", + "@dhis2/app-runtime": "^3.9.0", "@dhis2/app-runtime-adapter-d2": "^1.1.0", "@dhis2/d2-i18n": "^1.1.1", "@dhis2/d2-ui-core": "^7.4.1", @@ -51,7 +51,7 @@ "cy:capture": "cypress_dhis2_api_stub_mode=CAPTURE yarn d2-utils-cypress run --appStart 'yarn cypress:start'" }, "devDependencies": { - "@dhis2/cli-app-scripts": "^10.2.3", + "@dhis2/cli-app-scripts": "^10.3.0", "@dhis2/cli-style": "^10.4.1", "@dhis2/cli-utils-cypress": "^7.0.1", "@dhis2/cypress-commands": "^7.0.1", diff --git a/src/components/DashboardsBar/Chip.js b/src/components/DashboardsBar/Chip.js index 564f149b4..e82002f6f 100644 --- a/src/components/DashboardsBar/Chip.js +++ b/src/components/DashboardsBar/Chip.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import { Chip as UiChip, colors, IconStarFilled24 } from '@dhis2/ui' import cx from 'classnames' import debounce from 'lodash/debounce.js' @@ -12,7 +12,7 @@ import classes from './styles/Chip.module.css' const Chip = ({ starred, selected, label, dashboardId, onClick }) => { const { lastUpdated } = useCacheableSection(dashboardId) - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const chipProps = { selected, } diff --git a/src/components/DashboardsBar/Content.js b/src/components/DashboardsBar/Content.js index 466a43916..e95f1a44a 100644 --- a/src/components/DashboardsBar/Content.js +++ b/src/components/DashboardsBar/Content.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Button, ComponentCover, Tooltip, IconAdd24 } from '@dhis2/ui' import cx from 'classnames' @@ -24,7 +24,7 @@ const Content = ({ onSearchClicked, }) => { const [redirectUrl, setRedirectUrl] = useState(null) - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() const onSelectDashboard = () => { const id = getFilteredDashboards(dashboards, filterText)[0]?.id diff --git a/src/components/DashboardsBar/__tests__/Chip.spec.js b/src/components/DashboardsBar/__tests__/Chip.spec.js index 52734ad10..1fd8accc8 100644 --- a/src/components/DashboardsBar/__tests__/Chip.spec.js +++ b/src/components/DashboardsBar/__tests__/Chip.spec.js @@ -29,7 +29,7 @@ jest.mock('@dhis2/ui', () => { /* eslint-enable react/prop-types */ jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: () => ({ online: true }), + useDhis2ConnectionStatus: () => ({ isConnected: true }), useCacheableSection: jest.fn(), })) diff --git a/src/components/DashboardsBar/__tests__/DashboardsBar.spec.js b/src/components/DashboardsBar/__tests__/DashboardsBar.spec.js index 81e24b7aa..f353b58d3 100644 --- a/src/components/DashboardsBar/__tests__/DashboardsBar.spec.js +++ b/src/components/DashboardsBar/__tests__/DashboardsBar.spec.js @@ -37,7 +37,7 @@ const dashboards = { } jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: () => ({ online: true }), + useDhis2ConnectionStatus: () => ({ isConnected: true }), useCacheableSection: jest.fn(() => ({ isCached: false, recordingState: 'default', diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.offline.spec.js b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.offline.spec.js index 0a04057f8..e73d7296b 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.offline.spec.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.offline.spec.js @@ -15,7 +15,10 @@ jest.mock('../../../../SystemSettingsProvider', () => { }) jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ online: false, offline: true })), + useDhis2ConnectionStatus: jest.fn(() => ({ + isConnected: false, + isDisconnected: true, + })), useConfig: jest.fn(() => ({ baseUrl: 'dhis2' })), })) diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.spec.js b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.spec.js index a478d5d24..e86bb7a8a 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.spec.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ItemContextMenu.spec.js @@ -15,7 +15,10 @@ jest.mock('../../../../SystemSettingsProvider', () => { }) jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ online: true, offline: false })), + useDhis2ConnectionStatus: jest.fn(() => ({ + isConnected: true, + isDisconnected: false, + })), useConfig: jest.fn(() => ({ baseUrl: 'dhis2' })), })) diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js index 618971e04..71222c0b0 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import { render } from '@testing-library/react' import React from 'react' import { @@ -11,17 +11,20 @@ import { import ViewAsMenuItems from '../ViewAsMenuItems.js' jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ online: true, offline: false })), + useDhis2ConnectionStatus: jest.fn(() => ({ + isConnected: true, + isDisconnected: false, + })), })) const offline = { - online: false, - offline: true, + isConnected: false, + isDisconnected: true, } const online = { - online: true, - offline: false, + isConnected: true, + isDisconnected: false, } const defaultProps = { @@ -29,7 +32,7 @@ const defaultProps = { } test('renders menu for active type MAP and type CHART', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: CHART, activeType: MAP, @@ -41,7 +44,7 @@ test('renders menu for active type MAP and type CHART', async () => { }) test('renders disabled menu items when offline', () => { - useOnlineStatus.mockImplementation(jest.fn(() => offline)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => offline)) const props = Object.assign({}, defaultProps, { type: CHART, @@ -53,7 +56,7 @@ test('renders disabled menu items when offline', () => { }) test('renders menu for active type CHART and type MAP', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: MAP, activeType: CHART, @@ -68,7 +71,7 @@ test('renders menu for active type CHART and type MAP', async () => { }) test('renders menu for active type MAP and type MAP without Thematic layer', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: MAP, activeType: MAP, @@ -83,7 +86,7 @@ test('renders menu for active type MAP and type MAP without Thematic layer', asy }) test('renders menu for active type MAP and type MAP without Thematic layer when offline', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => offline)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => offline)) const props = Object.assign({}, defaultProps, { type: MAP, activeType: MAP, @@ -98,7 +101,7 @@ test('renders menu for active type MAP and type MAP without Thematic layer when }) test('renders menu for active type REPORT_TABLE and type CHART', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: CHART, activeType: REPORT_TABLE, @@ -111,7 +114,7 @@ test('renders menu for active type REPORT_TABLE and type CHART', async () => { }) test('renders menu for active type CHART and type REPORT_TABLE', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: REPORT_TABLE, activeType: CHART, @@ -124,7 +127,7 @@ test('renders menu for active type CHART and type REPORT_TABLE', async () => { }) test('renders menu for active type EVENT_REPORT and type EVENT_CHART', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: EVENT_CHART, activeType: EVENT_REPORT, @@ -137,7 +140,7 @@ test('renders menu for active type EVENT_REPORT and type EVENT_CHART', async () }) test('renders menu for active type EVENT_CHART and type EVENT_REPORT', async () => { - useOnlineStatus.mockImplementation(jest.fn(() => online)) + useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { type: EVENT_REPORT, activeType: EVENT_CHART, diff --git a/src/components/Item/VisualizationItem/ItemFooter.js b/src/components/Item/VisualizationItem/ItemFooter.js index 956eba90b..fdf50f6d8 100644 --- a/src/components/Item/VisualizationItem/ItemFooter.js +++ b/src/components/Item/VisualizationItem/ItemFooter.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import { useD2 } from '@dhis2/app-runtime-adapter-d2' import i18n from '@dhis2/d2-i18n' import InterpretationsComponent from '@dhis2/d2-ui-interpretations' @@ -10,7 +10,7 @@ import classes from './styles/ItemFooter.module.css' const ItemFooter = (props) => { const { d2 } = useD2() - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() return (
diff --git a/src/components/Item/VisualizationItem/Visualization/MapPlugin.js b/src/components/Item/VisualizationItem/Visualization/MapPlugin.js index 2ece5f85d..a9ba2da4e 100644 --- a/src/components/Item/VisualizationItem/Visualization/MapPlugin.js +++ b/src/components/Item/VisualizationItem/Visualization/MapPlugin.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import PropTypes from 'prop-types' import React from 'react' @@ -8,7 +8,7 @@ import NoVisualizationMessage from './NoVisualizationMessage.js' const mapViewIsEELayer = (mapView) => mapView.layer.includes('earthEngine') const MapPlugin = ({ visualization, style, ...pluginProps }) => { - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() if (offline && visualization.mapViews?.find(mapViewIsEELayer)) { return ( diff --git a/src/components/MenuItemWithTooltip.js b/src/components/MenuItemWithTooltip.js index 51dc8ed91..57d641605 100644 --- a/src/components/MenuItemWithTooltip.js +++ b/src/components/MenuItemWithTooltip.js @@ -1,5 +1,5 @@ import { OfflineTooltip } from '@dhis2/analytics' -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { MenuItem } from '@dhis2/ui' import PropTypes from 'prop-types' @@ -12,7 +12,7 @@ const MenuItemWithTooltip = ({ disabled, ...rest }) => { - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() const tooltipContent = disabledWhenOffline && offline diff --git a/src/components/__tests__/App.spec.js b/src/components/__tests__/App.spec.js index b46409db9..11aeee081 100644 --- a/src/components/__tests__/App.spec.js +++ b/src/components/__tests__/App.spec.js @@ -10,7 +10,10 @@ import { useSystemSettings } from '../SystemSettingsProvider.js' jest.mock('@dhis2/analytics') jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ online: true, offline: false })), + useDhis2ConnectionStatus: jest.fn(() => ({ + isConnected: true, + isDisconnected: false, + })), useDataEngine: jest.fn(() => ({ query: Function.prototype })), useCacheableSection: jest.fn, })) diff --git a/src/pages/edit/ActionsBar.js b/src/pages/edit/ActionsBar.js index f914cdcfe..3abd35d45 100644 --- a/src/pages/edit/ActionsBar.js +++ b/src/pages/edit/ActionsBar.js @@ -1,5 +1,9 @@ import { OfflineTooltip, TranslationDialog } from '@dhis2/analytics' -import { useOnlineStatus, useDataEngine, useAlert } from '@dhis2/app-runtime' +import { + useDhis2ConnectionStatus, + useDataEngine, + useAlert, +} from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Button, ButtonStrip } from '@dhis2/ui' import PropTypes from 'prop-types' @@ -43,7 +47,7 @@ const fieldsToTranslate = ['name', 'description'] const EditBar = ({ dashboard, ...props }) => { const dataEngine = useDataEngine() - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const [translationDlgIsOpen, setTranslationDlgIsOpen] = useState(false) const [filterSettingsDlgIsOpen, setFilterSettingsDlgIsOpen] = useState(false) diff --git a/src/pages/edit/ItemSelector/ItemSearchField.js b/src/pages/edit/ItemSelector/ItemSearchField.js index d0d501583..a8c7ecd1a 100644 --- a/src/pages/edit/ItemSelector/ItemSearchField.js +++ b/src/pages/edit/ItemSelector/ItemSearchField.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Input, Tooltip } from '@dhis2/ui' import PropTypes from 'prop-types' @@ -6,7 +6,7 @@ import React from 'react' import classes from './styles/ItemSearchField.module.css' const ItemSearchField = (props) => { - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const getInput = () => ( // autoComplete not supported in ui@6, remove this form after upgrade diff --git a/src/pages/edit/LayoutModal.js b/src/pages/edit/LayoutModal.js index 27273aa0c..435eca9c3 100644 --- a/src/pages/edit/LayoutModal.js +++ b/src/pages/edit/LayoutModal.js @@ -1,5 +1,5 @@ import { OfflineTooltip } from '@dhis2/analytics' -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Modal, @@ -27,7 +27,7 @@ const getColsSaveValue = (value) => value === '' ? DEFAULT_COLUMNS : parseInt(value, 10) export const LayoutModal = ({ columns, onSaveLayout, onClose }) => { - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() const [cols, setCols] = useState(columns) useEffect(() => setCols(columns), []) diff --git a/src/pages/edit/TitleBar.js b/src/pages/edit/TitleBar.js index d423f6ab4..bb9df0a4a 100644 --- a/src/pages/edit/TitleBar.js +++ b/src/pages/edit/TitleBar.js @@ -1,5 +1,5 @@ import { OfflineTooltip } from '@dhis2/analytics' -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { InputField, TextAreaField, Radio, Button } from '@dhis2/ui' import PropTypes from 'prop-types' @@ -37,7 +37,7 @@ const EditTitleBar = ({ onChangeDescription, onSaveLayout, }) => { - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() const updateTitle = (_, e) => { onChangeTitle(e.target.value) diff --git a/src/pages/edit/__tests__/ActionsBar.spec.js b/src/pages/edit/__tests__/ActionsBar.spec.js index 966031416..c076036fb 100644 --- a/src/pages/edit/__tests__/ActionsBar.spec.js +++ b/src/pages/edit/__tests__/ActionsBar.spec.js @@ -67,7 +67,10 @@ useD2.mockReturnValue({ }) jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ online: true, offline: false })), + useDhis2ConnectionStatus: jest.fn(() => ({ + isConnected: true, + isDisconnected: false, + })), useDataEngine: jest.fn(() => ({ dataEngine: {} })), useAlert: jest.fn(() => ({})), })) diff --git a/src/pages/edit/__tests__/FilterSettingsDialog.spec.js b/src/pages/edit/__tests__/FilterSettingsDialog.spec.js index 01a2990df..4a2318f55 100644 --- a/src/pages/edit/__tests__/FilterSettingsDialog.spec.js +++ b/src/pages/edit/__tests__/FilterSettingsDialog.spec.js @@ -3,7 +3,7 @@ import React from 'react' import FilterSettingsDialog from '../FilterSettingsDialog.js' jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: () => ({ online: true }), + useDhis2ConnectionStatus: () => ({ isConnected: true }), })) /* eslint-disable react/prop-types */ diff --git a/src/pages/start/StartScreen.js b/src/pages/start/StartScreen.js index ce79c4a53..7f3a39e9f 100644 --- a/src/pages/start/StartScreen.js +++ b/src/pages/start/StartScreen.js @@ -1,4 +1,4 @@ -import { useDataEngine, useOnlineStatus } from '@dhis2/app-runtime' +import { useDataEngine, useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' @@ -9,7 +9,7 @@ import styles from './styles/StartScreen.module.css' const StartScreen = ({ username }) => { const [mostViewedDashboards, setMostViewedDashboards] = useState([]) const dataEngine = useDataEngine() - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() useEffect(() => { async function populateMostViewedDashboards(dataEngine) { diff --git a/src/pages/view/FilterBar/FilterBadge.js b/src/pages/view/FilterBar/FilterBadge.js index b6c68ad1e..eec8bec47 100644 --- a/src/pages/view/FilterBar/FilterBadge.js +++ b/src/pages/view/FilterBar/FilterBadge.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Tooltip } from '@dhis2/ui' import cx from 'classnames' @@ -11,7 +11,7 @@ import { sGetSelectedId } from '../../../reducers/selected.js' import classes from './styles/FilterBadge.module.css' const FilterBadge = ({ dashboardId, filter, openFilterModal, onRemove }) => { - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const { isCached } = useCacheableSection(dashboardId) const notAllowed = !isCached && !online diff --git a/src/pages/view/FilterBar/FilterBar.js b/src/pages/view/FilterBar/FilterBar.js index 93ad43325..526918240 100644 --- a/src/pages/view/FilterBar/FilterBar.js +++ b/src/pages/view/FilterBar/FilterBar.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import PropTypes from 'prop-types' import React, { useState } from 'react' @@ -13,7 +13,7 @@ import FilterBadge from './FilterBadge.js' import classes from './styles/FilterBar.module.css' const FilterBar = ({ filters, removeFilter, removeAllFilters }) => { - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const [dialogIsOpen, setDialogIsOpen] = useState(false) const onRemoveFilter = (filterId) => { diff --git a/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js b/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js index 038357acd..dc55c9091 100644 --- a/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js +++ b/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js @@ -20,7 +20,7 @@ jest.mock('@dhis2/app-runtime-adapter-d2', () => ({ })) jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: () => ({ online: true }), + useDhis2ConnectionStatus: () => ({ isConnected: true }), useCacheableSection: jest.fn(() => ({ isCached: false, recordingState: 'default', diff --git a/src/pages/view/TitleBar/ActionsBar.js b/src/pages/view/TitleBar/ActionsBar.js index 44256fd74..24da7ec8b 100644 --- a/src/pages/view/TitleBar/ActionsBar.js +++ b/src/pages/view/TitleBar/ActionsBar.js @@ -1,5 +1,9 @@ import { OfflineTooltip } from '@dhis2/analytics' -import { useDataEngine, useAlert, useOnlineStatus } from '@dhis2/app-runtime' +import { + useDataEngine, + useAlert, + useDhis2ConnectionStatus, +} from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Button, @@ -50,7 +54,7 @@ const ViewActions = ({ useState(false) const [redirectUrl, setRedirectUrl] = useState(null) const dataEngine = useDataEngine() - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() const { lastUpdated, isCached, startRecording, remove } = useCacheableSection(id) diff --git a/src/pages/view/TitleBar/FilterSelector.js b/src/pages/view/TitleBar/FilterSelector.js index 38017815c..cf32d25aa 100644 --- a/src/pages/view/TitleBar/FilterSelector.js +++ b/src/pages/view/TitleBar/FilterSelector.js @@ -1,5 +1,5 @@ import { DimensionsPanel } from '@dhis2/analytics' -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Card, colors, IconFilter24 } from '@dhis2/ui' import isEmpty from 'lodash/isEmpty.js' @@ -20,7 +20,7 @@ import classes from './styles/FilterSelector.module.css' const FilterSelector = (props) => { const [filterDialogIsOpen, setFilterDialogIsOpen] = useState(false) const dimensions = useDimensions(filterDialogIsOpen) - const { offline } = useOnlineStatus() + const { isDisconnected: offline } = useDhis2ConnectionStatus() const toggleFilterDialogIsOpen = () => setFilterDialogIsOpen(!filterDialogIsOpen) diff --git a/src/pages/view/TitleBar/StarDashboardButton.js b/src/pages/view/TitleBar/StarDashboardButton.js index 37fee0872..6e8a3f7f2 100644 --- a/src/pages/view/TitleBar/StarDashboardButton.js +++ b/src/pages/view/TitleBar/StarDashboardButton.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { Tooltip, IconStar24, IconStarFilled24, colors } from '@dhis2/ui' import PropTypes from 'prop-types' @@ -6,7 +6,7 @@ import React from 'react' import classes from './styles/StarDashboardButton.module.css' const StarDashboardButton = ({ starred, onClick }) => { - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const StarIcon = starred ? IconStarFilled24 : IconStar24 diff --git a/src/pages/view/TitleBar/__tests__/FilterSelector.spec.js b/src/pages/view/TitleBar/__tests__/FilterSelector.spec.js index bad4f7380..ded375771 100644 --- a/src/pages/view/TitleBar/__tests__/FilterSelector.spec.js +++ b/src/pages/view/TitleBar/__tests__/FilterSelector.spec.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import { render, screen } from '@testing-library/react' import React from 'react' import { Provider } from 'react-redux' @@ -9,7 +9,7 @@ import FilterSelector from '../FilterSelector.js' const mockStore = configureMockStore() jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ offline: false })), + useDhis2ConnectionStatus: jest.fn(() => ({ isDisconnected: false })), })) /* eslint-disable react/prop-types */ @@ -30,7 +30,9 @@ jest.mock('../../../../modules/useDimensions', () => jest.fn()) useDimensions.mockImplementation(() => ['Moomin', 'Snorkmaiden']) test('is disabled when offline', () => { - useOnlineStatus.mockImplementationOnce(jest.fn(() => ({ offline: true }))) + useDhis2ConnectionStatus.mockImplementationOnce( + jest.fn(() => ({ isDisconnected: true })) + ) const store = { activeModalDimension: {}, itemFilters: {} } @@ -48,7 +50,7 @@ test('is disabled when offline', () => { }) test('is enabled when online', () => { - // useOnlineStatus.mockImplementation(jest.fn(() => ({ offline: false }))) + // useDhis2ConnectionStatus.mockImplementation(jest.fn(() => ({ isDisconnected: false }))) const store = { activeModalDimension: {}, itemFilters: {} } diff --git a/src/pages/view/ViewDashboard.js b/src/pages/view/ViewDashboard.js index fb3308c32..286db9ffb 100644 --- a/src/pages/view/ViewDashboard.js +++ b/src/pages/view/ViewDashboard.js @@ -1,4 +1,4 @@ -import { useOnlineStatus } from '@dhis2/app-runtime' +import { useDhis2ConnectionStatus } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { AlertStack, AlertBar } from '@dhis2/ui' import cx from 'classnames' @@ -34,7 +34,7 @@ const ViewDashboard = (props) => { const [loadingMessage, setLoadingMessage] = useState(null) const [loaded, setLoaded] = useState(false) const [loadFailed, setLoadFailed] = useState(false) - const { online } = useOnlineStatus() + const { isConnected: online } = useDhis2ConnectionStatus() const { isCached } = useCacheableSection(props.requestedId) useEffect(() => { diff --git a/src/pages/view/__tests__/ViewDashboard.spec.js b/src/pages/view/__tests__/ViewDashboard.spec.js index 48b51dfc7..5ac6c8791 100644 --- a/src/pages/view/__tests__/ViewDashboard.spec.js +++ b/src/pages/view/__tests__/ViewDashboard.spec.js @@ -20,7 +20,7 @@ jest.mock('@dhis2/app-runtime-adapter-d2', () => ({ })) jest.mock('@dhis2/app-runtime', () => ({ - useOnlineStatus: jest.fn(() => ({ online: true })), + useDhis2ConnectionStatus: jest.fn(() => ({ isConnected: true })), useCacheableSection: jest.fn(() => ({ isCached: false, recordingState: 'default', diff --git a/yarn.lock b/yarn.lock index 30f1fb0f2..826c0ed0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2152,12 +2152,13 @@ classnames "^2.3.1" prop-types "^15.7.2" -"@dhis2/analytics@^24.0.9", "@dhis2/analytics@^24.2.5": - version "24.2.5" - resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-24.2.5.tgz#85b3b42081cf0a08963d33f213625a11450b183a" - integrity sha512-NKC461JXEpz6+Dkc14QPm1N56YxR3/7qAlV4pu2Tpa1yZqrZpNQBPRsCG3bd0T9BkkbClkCWfr/oH9VA9jUyTQ== +"@dhis2/analytics@^24.0.9", "@dhis2/analytics@^24.9.2": + version "24.9.2" + resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-24.9.2.tgz#279423a63dd10c1c6fd5cf711b0df05c025be799" + integrity sha512-VNbGXOxfpI7ALWIXlwrGh+dqlE9PO3YUolfzKF5euz4z6657thRl69yP3C+FDs6CMDZ7BlIcybmxvSPJYi2stg== dependencies: "@dhis2/d2-ui-rich-text" "^7.4.0" + "@dhis2/multi-calendar-dates" "1.0.0" classnames "^2.3.1" d2-utilizr "^0.2.16" d3-color "^1.2.3" @@ -2167,12 +2168,12 @@ react-beautiful-dnd "^10.1.1" resize-observer-polyfill "^1.5.1" -"@dhis2/app-adapter@10.2.3": - version "10.2.3" - resolved "https://registry.yarnpkg.com/@dhis2/app-adapter/-/app-adapter-10.2.3.tgz#15753bb665be92d1058c36f8f060ff65ddedf5c8" - integrity sha512-Qk73M8yJJ2vWhbO0elAhXJrk/P9gk5jBYSQ/2BNukdJv6QwdNJu6WWRqkE9qCgnE5AR6pXXjv5DkT6lf/4phQg== +"@dhis2/app-adapter@10.3.0": + version "10.3.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-adapter/-/app-adapter-10.3.0.tgz#ba95c4a7ce7644d32edf71021e4a3b41ac44b1e8" + integrity sha512-6qZEja4HagRSc/R+z8N6ACF6pTXxuwCjo/jz+VYkktgHqbYlNiuR6IayzmXnCbomQG/fB61mvOuuG4Q08krN6w== dependencies: - "@dhis2/pwa" "10.2.3" + "@dhis2/pwa" "10.3.0" moment "^2.24.0" "@dhis2/app-runtime-adapter-d2@^1.1.0": @@ -2182,49 +2183,49 @@ dependencies: prop-types "^15.7.2" -"@dhis2/app-runtime@^3.4.4", "@dhis2/app-runtime@^3.6.1", "@dhis2/app-runtime@^3.7.0": - 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== +"@dhis2/app-runtime@^3.4.4", "@dhis2/app-runtime@^3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-3.9.0.tgz#c7e295fd0a68fac976a930bc77105206ded0b61a" + integrity sha512-n0S4pbyvK7FnBQFMONGrhR9YYavBQI+mQLHfCX/vtvOyeoioBUNIinuQlGysuLMEkSVaK5OjV40rvTMzdxF2kQ== dependencies: - "@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.9.0" + "@dhis2/app-service-config" "3.9.0" + "@dhis2/app-service-data" "3.9.0" + "@dhis2/app-service-offline" "3.9.0" -"@dhis2/app-service-alerts@3.7.0": - version "3.7.0" - resolved "https://registry.yarnpkg.com/@dhis2/app-service-alerts/-/app-service-alerts-3.7.0.tgz#fb20a136a9692b00569caeca77a79290e1e229e4" - integrity sha512-oTwO6vzIYrsSrdivCwxSc1EKSFr82CVabZOPX88TYLak+K7Qkxc0+E2BjaFNXXBsWwd1KD7OHgIZyQ23vcGsZg== +"@dhis2/app-service-alerts@3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-service-alerts/-/app-service-alerts-3.9.0.tgz#48d3805676e75ee58104fea4f76cfa779335444e" + integrity sha512-z2eZxm/pxrmFbisbK7/qJKtif2CNWJjaaAH5rfrs5OIajlHy3rO37vSaTQHWv+xWvZFQrs2Op2InxzG0qh5ncA== -"@dhis2/app-service-config@3.7.0": - version "3.7.0" - resolved "https://registry.yarnpkg.com/@dhis2/app-service-config/-/app-service-config-3.7.0.tgz#70ce37cb014dab4d7245665040def7eaa560cb28" - integrity sha512-fpfkarEOnQhHrSYdbZyQXkEDhcXUUO8NEWTAgajWTBNLMmli0iUGYr+t3e664mlrAcmq9Y8lPHGyHMTVtlrbrA== +"@dhis2/app-service-config@3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-service-config/-/app-service-config-3.9.0.tgz#8dc59d8de246f54057c0c685d5f94b4cbade6f73" + integrity sha512-OuRn2mJGrQQ8QIC+oIVYYpclB4LErRK2wtsuy/cXLfRbeUti1qWIh110rgd1hnTx+BgRCs5s3NWdIQxS4hYGIQ== -"@dhis2/app-service-data@3.7.0": - version "3.7.0" - resolved "https://registry.yarnpkg.com/@dhis2/app-service-data/-/app-service-data-3.7.0.tgz#96def75f959f34d4fcf5e001525b0b6a9a66b817" - integrity sha512-+3Tc2IEqB+P8EpSV6bbhDrzdgsmN/2kz6kag1I/4WDoQ9FbwdabxR/YyrL7E04SSFFs/85vl/nIkP0LPtT5nyQ== +"@dhis2/app-service-data@3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-service-data/-/app-service-data-3.9.0.tgz#37f528b5f7f589cbab8dcc7f997c1668bc6566a9" + integrity sha512-/FJgJhL6YGtIVNX5oaNmavkGmimrVHQsS8ueeUO4FvTjYXGlnnN3IuxypQcy/x4yiUyigbPgFJRnbC1J2af2fg== dependencies: react-query "^3.13.11" -"@dhis2/app-service-offline@3.7.0": - version "3.7.0" - resolved "https://registry.yarnpkg.com/@dhis2/app-service-offline/-/app-service-offline-3.7.0.tgz#913c49958842de642c35f723458057cf98d9fc1d" - integrity sha512-01igBw/Fwdg1lAJBNuioXnYbHm045XIN+CqXrqIDBzreeQcKg45oeWiETtkkaELRjECFqblHZoJVwEp5dxN4RA== +"@dhis2/app-service-offline@3.9.0": + version "3.9.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-service-offline/-/app-service-offline-3.9.0.tgz#fe4f4a91a1da77554965f6a5fe6f6951d4c467f4" + integrity sha512-0q5zl0vw+a47Ab2qgu6hsZY5ybnH/ea43Vkk4aXYdgcf57xB8ck9DkIcNbc2e1+k9FhvimipxsgTZSbEA/8hJA== dependencies: lodash "^4.17.21" -"@dhis2/app-shell@10.2.3": - version "10.2.3" - resolved "https://registry.yarnpkg.com/@dhis2/app-shell/-/app-shell-10.2.3.tgz#b2b9907b8c3fa22de26ba739ccfcdd85929c0345" - integrity sha512-hvFOFz6YtGLGYyHrcGxYAz9XdT19EH//dIBnqhCQIBv/d7q5uqQ8yue3XaUq1wOi2JQKsVH3mhRjruetlBkdAg== +"@dhis2/app-shell@10.3.0": + version "10.3.0" + resolved "https://registry.yarnpkg.com/@dhis2/app-shell/-/app-shell-10.3.0.tgz#67351afe3dbb83a1ba5778ce722c64f6d3c4f9c6" + integrity sha512-wkl2j8JaWe2M1Gwnp3Kz1lTyiSix4bMEPKBtqLwOMVIJ3b5hy7RpASBSlrvj11MdCCcIW9Crn0UfpMa842mHyA== dependencies: - "@dhis2/app-adapter" "10.2.3" - "@dhis2/app-runtime" "^3.6.1" + "@dhis2/app-adapter" "10.3.0" + "@dhis2/app-runtime" "^3.9.0" "@dhis2/d2-i18n" "^1.1.1" - "@dhis2/pwa" "10.2.3" + "@dhis2/pwa" "10.3.0" "@dhis2/ui" "^8.6.2" classnames "^2.2.6" moment "^2.29.1" @@ -2237,10 +2238,10 @@ typeface-roboto "^0.0.75" typescript "^3.6.3" -"@dhis2/cli-app-scripts@^10.2.3": - version "10.2.3" - resolved "https://registry.yarnpkg.com/@dhis2/cli-app-scripts/-/cli-app-scripts-10.2.3.tgz#be4a91cfddaa7ffc7c65404433b21f9b0b254cce" - integrity sha512-jjNAjJlUJVhThyjWb6hl2gOYba6i+Rqxbehsk85feeTSgwQQtDW7klX0Xi9X/I60xA8gyDnU6xJRZqE3y+rsFw== +"@dhis2/cli-app-scripts@^10.3.0": + version "10.3.0" + resolved "https://registry.yarnpkg.com/@dhis2/cli-app-scripts/-/cli-app-scripts-10.3.0.tgz#f544b2e2fe25e1a63d58734c9c1fba11684e0e75" + integrity sha512-zka66VUN8jrEymNDcaFnbTp4C7doDMUDSake4TmK6AUKNy/NiHNtuGgvCc2dqaECxTjh+CgcC+T6r4FdT7P78g== dependencies: "@babel/core" "^7.6.2" "@babel/plugin-proposal-class-properties" "^7.8.3" @@ -2249,7 +2250,7 @@ "@babel/preset-env" "^7.14.7" "@babel/preset-react" "^7.0.0" "@babel/preset-typescript" "^7.6.0" - "@dhis2/app-shell" "10.2.3" + "@dhis2/app-shell" "10.3.0" "@dhis2/cli-helpers-engine" "^3.2.0" "@jest/core" "^27.0.6" "@pmmmwh/react-refresh-webpack-plugin" "^0.5.4" @@ -2444,6 +2445,14 @@ lodash-es "^4.17.21" prop-types "^15" +"@dhis2/multi-calendar-dates@1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@dhis2/multi-calendar-dates/-/multi-calendar-dates-1.0.0.tgz#bf7f49aecdffa9781837a5d60d56a094b74ab4df" + integrity sha512-IB9a+feuS6yE4lpZj/eZ9uBmpYI7Hxitl2Op0JjoRL4tP+p6uw4ns9cjoSdUeIU9sOAxVZV7oQqSyIw+9P6YjQ== + dependencies: + "@js-temporal/polyfill" "^0.4.2" + classnames "^2.3.2" + "@dhis2/multi-calendar-dates@1.0.0-alpha.18": version "1.0.0-alpha.18" resolved "https://registry.yarnpkg.com/@dhis2/multi-calendar-dates/-/multi-calendar-dates-1.0.0-alpha.18.tgz#341176f1ffb0a4663dd5b882e587403d6dc7fbda" @@ -2457,10 +2466,10 @@ resolved "https://registry.yarnpkg.com/@dhis2/prop-types/-/prop-types-3.1.2.tgz#65b8ad2da8cd2f72bc8b951049a6c9d1b97af3e9" integrity sha512-eM0jjLOWvtXWqSFp5YC4DHFpkP8Y1D2eUwGV7MBWjni+o27oesVan+oT7WHeOeLdlAd4acRJrnaaAyB4Ck1wGQ== -"@dhis2/pwa@10.2.3": - version "10.2.3" - resolved "https://registry.yarnpkg.com/@dhis2/pwa/-/pwa-10.2.3.tgz#679ddad035053ed216398cd8f27c6f21eecb287d" - integrity sha512-0ylXklRLnDEJr+7EJ8lzTbRntxiRWN+Rdu8C0w+8TgXQD6Axx0hHfjt6EW6hwtVEEZckakKVw867aQCf5HwDsg== +"@dhis2/pwa@10.3.0": + version "10.3.0" + resolved "https://registry.yarnpkg.com/@dhis2/pwa/-/pwa-10.3.0.tgz#c033415761f1db1ed5e1794a6813ba45d062bf76" + integrity sha512-40Tj5xag94IIrQw8mGUjCueTyG7Xe/vOXz1gsR9Nm9/8RyMJ2hjd7C/D6Gy4WJHFTI0qippnSjBopsyL+lt4Og== dependencies: idb "^6.0.0" workbox-core "^6.1.5"