Skip to content

Commit

Permalink
fix: stop fetching schemas and replace d2 with dataEngine (#3056)
Browse files Browse the repository at this point in the history
The schemas aren't needed anymore.
Also, replaced d2 with dataEngine:
* post dataStatistics
* getting currentUser
* getting list of installed apps
  • Loading branch information
janhenrikoverland authored Aug 26, 2024
1 parent 9fe6ae5 commit 49428c6
Show file tree
Hide file tree
Showing 28 changed files with 243 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.DHIS2_BOT_GITHUB_TOKEN }}
DEBUG: '*'
DEBUG: '@semantic-release/commit-analyzer'

- name: Publish to AppHub
run: yarn run d2-app-scripts publish
Expand Down
14 changes: 5 additions & 9 deletions cypress/e2e/dashboard_filter.feature
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
Feature: Dashboard filter

Scenario: I add a Period filter
Scenario: I add and remove filters
When I start a new dashboard
And I add items and save
Then the dashboard displays in view mode and visualizations are visible
When I add a "Period" filter
Then the Period filter is applied to the dashboard

Scenario: I add a Organisation unit filter
Given I open an existing dashboard
Then the dashboard displays in view mode and visualizations are visible
When I remove the "Period" filter
Then the filter is removed from the dashboard
When I add a "Organisation unit" filter
Then the Organisation unit filter is applied to the dashboard

Scenario: I add a Facility Type filter
Given I open an existing dashboard
Then the dashboard displays in view mode and visualizations are visible
When I remove the "OrgUnit" filter
Then the filter is removed from the dashboard
When I add a "Facility Type" filter
Then the Facility Type filter is applied to the dashboard

Expand Down
144 changes: 76 additions & 68 deletions cypress/e2e/dashboard_filter/dashboard_filter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Then } from '@badeball/cypress-cucumber-preprocessor'
import { Then, When } from '@badeball/cypress-cucumber-preprocessor'
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,13 @@ 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')
})

When('I remove the {string} filter', () => {
cy.get(filterBadgeSel).find('button').contains('Remove').click()
})

Then('the filter is removed from the dashboard', () => {
cy.get(filterBadgeSel).should('not.exist')
})
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 'react-resizable/css/styles.css'
import './styles/ItemGrid.css'

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

useEffect(() => {
props.fetchDashboards()
Expand Down Expand Up @@ -60,7 +60,7 @@ const App = (props) => {
) : (
<ViewDashboard
{...props}
username={d2.currentUser.username}
username={currentUser.username}
/>
)
}
Expand All @@ -70,7 +70,7 @@ const App = (props) => {
path={ROUTE_START_PATH}
render={() => (
<LandingPage
username={d2.currentUser.username}
username={currentUser.username}
onMount={props.resetState}
/>
)}
Expand All @@ -86,7 +86,7 @@ const App = (props) => {
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
Loading

0 comments on commit 49428c6

Please sign in to comment.