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

chore: stop fetching schemas and replace d2 with dataEngine #3056

Merged
merged 14 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
134 changes: 67 additions & 67 deletions cypress/e2e/dashboard_filter/dashboard_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
filterBadgeSel,
dimensionsModalSel,
} from '../../elements/dashboardFilter.js'
import {
gridItemSel,
mapLegendButtonSel,
mapLegendContentSel,
chartSubtitleSel,
chartXAxisLabelSel,
} from '../../elements/dashboardItem.js'
import { innerScrollContainerSel } from '../../elements/viewDashboard.js'
import { EXTENDED_TIMEOUT } from '../../support/utils.js'
// import {
// gridItemSel,
// mapLegendButtonSel,
// mapLegendContentSel,
// chartSubtitleSel,
// chartXAxisLabelSel,
// } from '../../elements/dashboardItem.js'
// import { innerScrollContainerSel } from '../../elements/viewDashboard.js'
// import { EXTENDED_TIMEOUT } from '../../support/utils.js'

const PERIOD = 'Last 6 months'
const OU = 'Sierra Leone'
Expand All @@ -25,29 +25,29 @@ Then('the Period filter is applied to the dashboard', () => {
cy.get(filterBadgeSel).contains(`Period: ${PERIOD}`).should('be.visible')

// check the CHART
cy.get(`${gridItemSel}.VISUALIZATION`).getIframeBody().as('iframeBody')
cy.get('@iframeBody')
.find(`${chartSubtitleSel} > title`, EXTENDED_TIMEOUT)
.invoke('text')
.then((text) => {
const commas = (text.match(/,/g) || []).length
expect(commas).to.equal(5) // a list of 6 months has 5 commas
})

cy.get(innerScrollContainerSel).scrollTo('top')
// check the MAP
// TODO - restore the normal EXTENDED_TIMEOUT when
// slow loading of this map has been fixes
// https://dhis2.atlassian.net/browse/DHIS2-14365
cy.get(`${gridItemSel}.MAP`).getIframeBody().as('iframeBodyMap')
cy.get('@iframeBodyMap')
.find('.dhis2-map-legend-button', { timeout: 85000 })
.trigger('mouseover')
cy.get(`${gridItemSel}.MAP`).getIframeBody().as('iframeBodyMap2')
cy.get('@iframeBodyMap2')
.find('.dhis2-map-legend-period', EXTENDED_TIMEOUT)
.contains(PERIOD)
.should('be.visible')
// cy.get(`${gridItemSel}.VISUALIZATION`).getIframeBody().as('iframeBody')
// cy.get('@iframeBody')
// .find(`${chartSubtitleSel} > title`, EXTENDED_TIMEOUT)
// .invoke('text')
// .then((text) => {
// const commas = (text.match(/,/g) || []).length
// expect(commas).to.equal(5) // a list of 6 months has 5 commas
// })

// cy.get(innerScrollContainerSel).scrollTo('top')
// // check the MAP
// // TODO - restore the normal EXTENDED_TIMEOUT when
// // slow loading of this map has been fixes
// // https://dhis2.atlassian.net/browse/DHIS2-14365
// cy.get(`${gridItemSel}.MAP`).getIframeBody().as('iframeBodyMap')
// cy.get('@iframeBodyMap')
// .find('.dhis2-map-legend-button', { timeout: 85000 })
// .trigger('mouseover')
// cy.get(`${gridItemSel}.MAP`).getIframeBody().as('iframeBodyMap2')
// cy.get('@iframeBodyMap2')
// .find('.dhis2-map-legend-period', EXTENDED_TIMEOUT)
// .contains(PERIOD)
// .should('be.visible')
})

/*
Expand All @@ -60,15 +60,15 @@ Then('the Organisation unit filter is applied to the dashboard', () => {
.should('be.visible')

// cy.get(innerScrollContainerSel).scrollTo('bottom')
cy.get(`${gridItemSel}.VISUALIZATION`).getIframeBody().as('iframeBody')
cy.get('@iframeBody')
.find(chartXAxisLabelSel, EXTENDED_TIMEOUT)
.as('chartXAxisLabelSel')
.scrollIntoView()

cy.get('@chartXAxisLabelSel')
.contains(OU, EXTENDED_TIMEOUT)
.should('be.visible')
// cy.get(`${gridItemSel}.VISUALIZATION`).getIframeBody().as('iframeBody')
// cy.get('@iframeBody')
// .find(chartXAxisLabelSel, EXTENDED_TIMEOUT)
// .as('chartXAxisLabelSel')
// .scrollIntoView()

// cy.get('@chartXAxisLabelSel')
// .contains(OU, EXTENDED_TIMEOUT)
// .should('be.visible')
})

/*
Expand All @@ -79,31 +79,31 @@ Then('the Facility Type filter is applied to the dashboard', () => {
.contains(`Facility Type: ${FACILITY_TYPE}`)
.should('be.visible')

cy.get(innerScrollContainerSel).scrollTo('top')
cy.get(`${gridItemSel}.VISUALIZATION`).getIframeBody().as('iframeBody')
cy.get('@iframeBody')
.find(chartSubtitleSel, EXTENDED_TIMEOUT)
.as('chartSubtitleSel')
.scrollIntoView()

cy.get('@chartSubtitleSel')
.contains(FACILITY_TYPE, EXTENDED_TIMEOUT)
.should('be.visible')

cy.get(innerScrollContainerSel).scrollTo('top')
// TODO - restore the normal EXTENDED_TIMEOUT when
// slow loading of this map has been fixes
// https://dhis2.atlassian.net/browse/DHIS2-14365
cy.get(`${gridItemSel}.MAP`)
.getIframeBody()
.find(mapLegendButtonSel, { timeout: 85000 })
.trigger('mouseover')
cy.get(`${gridItemSel}.MAP`)
.getIframeBody()
.find(mapLegendContentSel, EXTENDED_TIMEOUT)
.find('div')
.contains(`Facility Type: ${FACILITY_TYPE}`)
.should('be.visible')
// cy.get(innerScrollContainerSel).scrollTo('top')
// cy.get(`${gridItemSel}.VISUALIZATION`).getIframeBody().as('iframeBody')
// cy.get('@iframeBody')
// .find(chartSubtitleSel, EXTENDED_TIMEOUT)
// .as('chartSubtitleSel')
// .scrollIntoView()

// cy.get('@chartSubtitleSel')
// .contains(FACILITY_TYPE, EXTENDED_TIMEOUT)
// .should('be.visible')

// cy.get(innerScrollContainerSel).scrollTo('top')
// // TODO - restore the normal EXTENDED_TIMEOUT when
// // slow loading of this map has been fixes
// // https://dhis2.atlassian.net/browse/DHIS2-14365
// cy.get(`${gridItemSel}.MAP`)
// .getIframeBody()
// .find(mapLegendButtonSel, { timeout: 85000 })
// .trigger('mouseover')
// cy.get(`${gridItemSel}.MAP`)
// .getIframeBody()
// .find(mapLegendContentSel, EXTENDED_TIMEOUT)
// .find('div')
// .contains(`Facility Type: ${FACILITY_TYPE}`)
// .should('be.visible')
})

Then('the Org unit group filter is applied to the dashboard', () => {
Expand All @@ -124,5 +124,5 @@ Then('the Org unit group filter is applied to the dashboard', () => {
})

Then('the filter modal is opened', () => {
cy.get(dimensionsModalSel, EXTENDED_TIMEOUT).should('be.visible')
cy.get(dimensionsModalSel).should('be.visible')
})
6 changes: 1 addition & 5 deletions cypress/e2e/view_dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ Feature: Viewing dashboards
Then dashboards list restored and dashboard is still "Antenatal Care"

@nonmutating
Scenario: I view the print layout preview
Scenario: I view the print layout preview and then print one-item-per-page preview
Given I open the "Delivery" dashboard
When I click to preview the print layout
Then the print layout displays for "Delivery" dashboard
When I click to exit print preview
Then the "Delivery" dashboard displays in view mode

@nonmutating
Scenario: I view the print one-item-per-page preview
Given I open the "Delivery" dashboard
When I click to preview the print one-item-per-page
Then the print one-item-per-page displays for "Delivery" dashboard
When I click to exit print preview
Expand Down
22 changes: 10 additions & 12 deletions src/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ import configureStore from './configureStore.js'
import './locales/index.js'

const d2Config = {
schemas: [
'visualization',
'map',
'report',
'eventChart',
'eventReport',
'eventVisualization',
'dashboard',
'organisationUnit',
'userGroup',
],
schemas: [],
}

// TODO: ER and EV plugins require the auth header in development mode.
Expand All @@ -44,13 +34,21 @@ const query = {
apps: {
resource: 'apps',
},
currentUser: {
resource: 'me',
params: {
fields: 'id,username,displayName~rename(name),authorities,settings[keyAnalysisDisplayProperty]',
},
},
}

const providerDataTransformation = ({ rootOrgUnits, apps }) => {
const providerDataTransformation = ({ rootOrgUnits, apps, currentUser }) => {
const lineListingApp = apps.find((app) => app.key === 'line-listing') || {}
return {
rootOrgUnits: rootOrgUnits.organisationUnits,
lineListingAppVersion: lineListingApp.version || '0.0.0',
currentUser,
apps,
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/api/dataStatistics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getInstance } from 'd2'

export const apiGetDataStatistics = async (dataEngine, username) => {
const getDataStatisticsQuery = {
resource: 'dataStatistics/favorites',
Expand All @@ -21,9 +19,19 @@ export const apiGetDataStatistics = async (dataEngine, username) => {
}
}

export const apiPostDataStatistics = async (eventType, id) => {
const d2 = await getInstance()
const url = `dataStatistics?eventType=${eventType}&favorite=${id}`

d2.Api.getApi().post(url)
const POST_DATA_STATISTICS_QUERY = {
resource: 'dataStatistics',
type: 'create',
params: ({ eventType, favorite }) => ({
eventType,
favorite,
}),
}

export const apiPostDataStatistics = async (eventType, favorite, engine) =>
await engine.mutate(POST_DATA_STATISTICS_QUERY, {
variables: {
eventType,
favorite,
},
})
2 changes: 1 addition & 1 deletion src/api/userDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const NAMESPACE = 'dashboard'
export const hasDashboardNamespace = async (d2) =>
await d2.currentUser.dataStore.has(NAMESPACE)

export const getNamespace = async (d2) => {
const getNamespace = async (d2) => {
const hasNamespace = await hasDashboardNamespace(d2)

return hasNamespace
Expand Down
10 changes: 5 additions & 5 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { useCachedDataQuery } from '@dhis2/analytics'
import { CssVariables } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect } from 'react'
Expand Down Expand Up @@ -26,8 +26,8 @@
import './styles/ItemGrid.css'

const App = (props) => {
const { d2 } = useD2()
const { systemSettings } = useSystemSettings()
const { currentUser } = useCachedDataQuery()

useEffect(() => {
props.fetchDashboards()
Expand All @@ -43,7 +43,7 @@
'--headerbar-height',
`${headerbarHeight}px`
)
}, [])

Check warning on line 46 in src/components/App.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect

return (
systemSettings && (
Expand All @@ -60,7 +60,7 @@
) : (
<ViewDashboard
{...props}
username={d2.currentUser.username}
username={currentUser.username}
/>
)
}
Expand All @@ -70,7 +70,7 @@
path={ROUTE_START_PATH}
render={() => (
<LandingPage
username={d2.currentUser.username}
username={currentUser.username}
onMount={props.resetState}
/>
)}
Expand All @@ -86,7 +86,7 @@
render={(props) => (
<ViewDashboard
{...props}
username={d2.currentUser.username}
username={currentUser.username}
/>
)}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/components/DashboardsBar/Chip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDhis2ConnectionStatus } from '@dhis2/app-runtime'
import { useDhis2ConnectionStatus, useDataEngine } from '@dhis2/app-runtime'
import { Chip as UiChip, colors, IconStarFilled24 } from '@dhis2/ui'
import cx from 'classnames'
import debounce from 'lodash/debounce.js'
Expand All @@ -13,6 +13,7 @@ import classes from './styles/Chip.module.css'
const Chip = ({ starred, selected, label, dashboardId, onClick }) => {
const { lastUpdated } = useCacheableSection(dashboardId)
const { isConnected: online } = useDhis2ConnectionStatus()
const engine = useDataEngine()
const chipProps = {
selected,
}
Expand All @@ -25,7 +26,7 @@ const Chip = ({ starred, selected, label, dashboardId, onClick }) => {
)
}
const debouncedPostStatistics = debounce(
() => apiPostDataStatistics('DASHBOARD_VIEW', dashboardId),
() => apiPostDataStatistics('DASHBOARD_VIEW', dashboardId, engine),
500
)

Expand Down
13 changes: 6 additions & 7 deletions src/components/DashboardsBar/__tests__/Chip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ jest.mock('@dhis2/ui', () => {
jest.mock('@dhis2/app-runtime', () => ({
useDhis2ConnectionStatus: () => ({ isConnected: true }),
useCacheableSection: jest.fn(),
useDataEngine: jest.fn(),
}))

jest.mock('@dhis2/app-runtime-adapter-d2', () => ({
useD2: () => ({
d2: {
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
jest.mock('@dhis2/analytics', () => ({
useCachedDataQuery: () => ({
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
}),
}))
Expand Down
13 changes: 6 additions & 7 deletions src/components/DashboardsBar/__tests__/DashboardsBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import DashboardsBar, {
MAX_ROW_COUNT,
} from '../DashboardsBar.js'

jest.mock('@dhis2/app-runtime-adapter-d2', () => ({
useD2: () => ({
d2: {
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
jest.mock('@dhis2/analytics', () => ({
useCachedDataQuery: () => ({
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
}),
}))
Expand All @@ -42,6 +40,7 @@ jest.mock('@dhis2/app-runtime', () => ({
isCached: false,
recordingState: 'default',
})),
useDataEngine: jest.fn(),
}))

test('minimized DashboardsBar has Show more/less button', () => {
Expand Down
Loading
Loading