Skip to content

Commit

Permalink
Merge branch 'fix/custom-ou-group-filter-crash-v38' of github.com:dhi…
Browse files Browse the repository at this point in the history
…s2/dashboard-app into fix/custom-ou-group-filter-crash-v38
  • Loading branch information
jenniferarnesen committed Sep 13, 2023
2 parents 17c9595 + 0a874ee commit cdeb132
Show file tree
Hide file tree
Showing 30 changed files with 592 additions and 505 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"license": "BSD-3-Clause",
"dependencies": {
"@dhis2/analytics": "^22.0.0",
"@dhis2/analytics": "^26.0.16",
"@dhis2/app-runtime": "^3.9.3",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/d2-i18n": "^1.1.1",
Expand Down Expand Up @@ -69,6 +69,6 @@
}
},
"resolutions": {
"@dhis2/ui": "8.12.4"
"@dhis2/ui": "8.13.0"
}
}
4 changes: 2 additions & 2 deletions src/components/DashboardsBar/Chip.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/DashboardsBar/Content.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/DashboardsBar/__tests__/Chip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Router } from 'react-router-dom'
import Chip from '../Chip'

jest.mock('@dhis2/app-runtime', () => ({
useOnlineStatus: () => ({ online: true }),
useDhis2ConnectionStatus: () => ({ isConnected: true }),
useCacheableSection: jest.fn(),
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const dashboards = {
}

jest.mock('@dhis2/app-runtime', () => ({
useOnlineStatus: () => ({ online: true }),
useDhis2ConnectionStatus: () => ({ isConnected: true }),
useCacheableSection: jest.fn(() => ({
isCached: false,
recordingState: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jest.mock('../../../../SystemSettingsProvider', () => {
})

jest.mock('@dhis2/app-runtime', () => ({
useOnlineStatus: jest.fn(() => ({ offline: true })),
useDhis2ConnectionStatus: jest.fn(() => ({
isConnected: false,
isDisconnected: true,
})),
useConfig: jest.fn(() => ({ baseUrl: 'dhis2' })),
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' })),
}))

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,25 +11,28 @@ import {
import ViewAsMenuItems from '../ViewAsMenuItems'

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 = {
onActiveTypeChanged: jest.fn(),
}

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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Item/VisualizationItem/ItemFooter.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 (
<div className={classes.itemFooter} data-test="dashboarditem-footer">
Expand Down
Original file line number Diff line number Diff line change
@@ -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, useEffect } from 'react'
Expand All @@ -20,7 +20,7 @@ const MapPlugin = ({
itemFilters,
...props
}) => {
const { offline } = useOnlineStatus()
const { isDisconnected: offline } = useDhis2ConnectionStatus()
const [initialized, setInitialized] = useState(false)

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/MenuItemWithTooltip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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'
Expand All @@ -12,7 +12,7 @@ const MenuItemWithTooltip = ({
disabled,
...rest
}) => {
const { offline } = useOnlineStatus()
const { isDisconnected: offline } = useDhis2ConnectionStatus()

const tooltipContent =
disabledWhenOffline && offline
Expand Down
4 changes: 2 additions & 2 deletions src/components/OfflineTooltip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useOnlineStatus } from '@dhis2/app-runtime'
import { useDhis2ConnectionStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { Tooltip as UiTooltip } from '@dhis2/ui'
import cx from 'classnames'
Expand All @@ -7,7 +7,7 @@ import React from 'react'
import classes from './styles/Tooltip.module.css'

const Tooltip = ({ disabledWhenOffline, disabled, content, children }) => {
const { offline } = useOnlineStatus()
const { isDisconnected: offline } = useDhis2ConnectionStatus()

const notAllowed = disabled || (disabledWhenOffline && offline)

Expand Down
5 changes: 4 additions & 1 deletion src/components/__tests__/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { useSystemSettings } from '../SystemSettingsProvider'

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,
}))
Expand Down
8 changes: 6 additions & 2 deletions src/pages/edit/ActionsBar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useOnlineStatus, useDataEngine, useAlert } from '@dhis2/app-runtime'
import {
useDhis2ConnectionStatus,
useDataEngine,
useAlert,
} from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import TranslationDialog from '@dhis2/d2-ui-translation-dialog'
Expand Down Expand Up @@ -44,7 +48,7 @@ const deleteFailedMessage = i18n.t(
const EditBar = ({ dashboard, ...props }) => {
const { d2 } = useD2()
const dataEngine = useDataEngine()
const { online } = useOnlineStatus()
const { isConnected: online } = useDhis2ConnectionStatus()
const [translationDlgIsOpen, setTranslationDlgIsOpen] = useState(false)
const [filterSettingsDlgIsOpen, setFilterSettingsDlgIsOpen] =
useState(false)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/edit/ItemSelector/ItemSearchField.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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'
import React from 'react'
import classes from './styles/ItemSearchField.module.css'

const ItemSearchField = props => {
const { online } = useOnlineStatus()
const { isConnected: online } = useDhis2ConnectionStatus()

const getInput = () => (
<Input
Expand Down
4 changes: 2 additions & 2 deletions src/pages/edit/LayoutModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useOnlineStatus } from '@dhis2/app-runtime'
import { useDhis2ConnectionStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
Modal,
Expand Down Expand Up @@ -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), [])
Expand Down
4 changes: 2 additions & 2 deletions src/pages/edit/TitleBar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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'
Expand Down Expand Up @@ -37,7 +37,7 @@ const EditTitleBar = ({
onChangeDescription,
onSaveLayout,
}) => {
const { offline } = useOnlineStatus()
const { isDisconnected: offline } = useDhis2ConnectionStatus()

const updateTitle = (_, e) => {
onChangeTitle(e.target.value)
Expand Down
5 changes: 4 additions & 1 deletion src/pages/edit/__tests__/ActionsBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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(() => ({})),
}))
Expand Down
2 changes: 1 addition & 1 deletion src/pages/edit/__tests__/FilterSettingsDialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import FilterSettingsDialog from '../FilterSettingsDialog'

jest.mock('@dhis2/app-runtime', () => ({
useOnlineStatus: () => ({ online: true }),
useDhis2ConnectionStatus: () => ({ isConnected: true }),
}))

jest.mock('@dhis2/ui', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/start/StartScreen.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/view/FilterBar/FilterBadge.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -11,7 +11,7 @@ import { sGetSelectedId } from '../../../reducers/selected'
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
Expand Down
Loading

0 comments on commit cdeb132

Please sign in to comment.