Skip to content

Commit

Permalink
chore: remove orgUnit, orgUnitGroup, program, programStage schemas (#…
Browse files Browse the repository at this point in the history
…3255)

* chore: remove schemas

* chore: programs was already switched to app-runtime

* chore: pass engine for use by getEventColumns

* chore: try enabling cypress test for event data table

* chore: use event layer with less data so cypress doesnt crash
  • Loading branch information
jenniferarnesen committed Aug 8, 2024
1 parent 17a8150 commit 9bb2645
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 49 deletions.
36 changes: 17 additions & 19 deletions cypress/integration/dataTable.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,23 @@ describe('data table', () => {
cy.getByDataTest('org-unit-profile').should('be.visible')
})

it.skip('opens the data table for an Event layer', () => {
it('opens the data table for an Event layer', () => {
cy.visit('/', EXTENDED_TIMEOUT)

const Layer = new EventLayer()

Layer.openDialog('Events')
.selectProgram('Malaria case registration')
.validateStage('Malaria case registration')
.selectProgram('Inpatient morbidity and mortality')
.validateStage('Inpatient morbidity and mortality')
.selectTab('Period')
.selectPeriodType('Start/end dates')
.typeStartDate(`${CURRENT_YEAR - 1}-01-01`)
.typeEndDate(`${CURRENT_YEAR - 1}-01-15`)
.selectTab('Org Units')
.selectOu('Bo')
.typeEndDate(`${CURRENT_YEAR - 1}-01-03`)
.addToMap()

Layer.validateDialogClosed(true)

Layer.validateCardTitle('Malaria case registration')
Layer.validateCardTitle('Inpatient morbidity and mortality')

cy.getByDataTest('moremenubutton').first().click()

Expand All @@ -166,20 +164,20 @@ describe('data table', () => {
// check number of columns
cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-datatablecellhead')
.should('have.length', 9)
.should('have.length', 10)

cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-datatablecellhead')
.contains('Age in years', { matchCase: false })
.should('be.visible')

// filter by Org unit
const ouName = 'Benduma'
const ouName = 'Moyowa'
cy.getByDataTest('data-table-column-filter-input-Org unit')
.find('input')
.type(ouName)

// check that all the rows have Org unit Yakaji
// check that all the rows have Org unit Moyowa

cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-tablebody')
Expand All @@ -200,26 +198,26 @@ describe('data table', () => {
cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-tablebody')
.findByDataTest('dhis2-uicore-datatablerow')
.should('have.length', 5)
.should('have.length', 3)

// filter by Gender
cy.getByDataTest('data-table-column-filter-input-Gender')
// filter by Mode of Discharge
cy.getByDataTest('data-table-column-filter-input-Mode of Discharge')
.find('input')
.type('Female')
.type('Absconded')

cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-tablebody')
.findByDataTest('dhis2-uicore-datatablerow')
.should('have.length', 4)
.should('have.length', 1)

cy.getByDataTest('data-table-column-filter-input-Gender')
cy.getByDataTest('data-table-column-filter-input-Mode of Discharge')
.find('input')
.clear()

cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-tablebody')
.findByDataTest('dhis2-uicore-datatablerow')
.should('have.length', 5)
.should('have.length', 3)

// filter by Age in years (numeric)
cy.getByDataTest('data-table-column-filter-input-Age in years')
Expand All @@ -230,7 +228,7 @@ describe('data table', () => {
cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-tablebody')
.findByDataTest('dhis2-uicore-datatablerow')
.should('have.length', 3)
.should('have.length', 2)

// Sort by Age in years
cy.get('button[title="Sort by Age in years"]').click()
Expand All @@ -242,7 +240,7 @@ describe('data table', () => {
.first()
.find('td')
.eq(7)
.should('contain', '44')
.should('contain', '32')

cy.getByDataTest('bottom-panel')
.findByDataTest('dhis2-uicore-tablebody')
Expand Down
11 changes: 1 addition & 10 deletions src/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ log.setLevel(
)

const d2Config = {
schemas: [
'dataElement',
'dataSet',
'indicator',
'legendSet',
'organisationUnit',
'organisationUnitGroup',
'program',
'programStage',
],
schemas: ['dataElement', 'dataSet', 'indicator', 'legendSet'],
}

const replaceLegacyUrl = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/layers/download/DataDownloadDialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCachedDataQuery } from '@dhis2/analytics'
import { useDataEngine } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import {
Expand All @@ -18,6 +19,7 @@ import DataDownloadDialogActions from './DataDownloadDialogActions.js'
import styles from './styles/DataDownloadDialog.module.css'

const DataDownloadDialog = ({ layer, onCloseDialog }) => {
const engine = useDataEngine()
const { nameProperty } = useCachedDataQuery()
const formatOptions = getFormatOptions()
const { d2 } = useD2()
Expand Down Expand Up @@ -54,6 +56,7 @@ const DataDownloadDialog = ({ layer, onCloseDialog }) => {
humanReadableKeys: humanReadable,
d2,
nameProperty,
engine,
})
setIsDownloading(false)
onClose()
Expand Down
12 changes: 7 additions & 5 deletions src/components/map/layers/EventLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { getInstance as getD2 } from 'd2'
import React from 'react'
import { EVENT_COLOR, EVENT_RADIUS } from '../../../constants/layers.js'
import { getContrastColor } from '../../../util/colors.js'
import { getAnalyticsRequest } from '../../../util/event.js'
import {
getAnalyticsRequest,
PROGRAM_STAGE_QUERY,
} from '../../../util/event.js'
import { filterData } from '../../../util/filter.js'
import { formatCount } from '../../../util/numbers.js'
import { OPTION_SET_QUERY } from '../../../util/requests.js'
Expand Down Expand Up @@ -90,6 +93,7 @@ class EventLayer extends Layer {
(await getAnalyticsRequest(this.props, {
d2,
nameProperty,
engine,
}))

eventRequest = eventRequest
Expand Down Expand Up @@ -202,10 +206,8 @@ class EventLayer extends Layer {
const displayNameProp =
nameProperty === 'name' ? 'displayName' : 'displayShortName'

const d2 = await getD2()
const data = await d2.models.programStage.get(programStage.id, {
fields: `programStageDataElements[displayInReports,dataElement[id,${displayNameProp}~rename(name),optionSet,valueType]]`,
paging: false,
const { programStage: data } = await engine.query(PROGRAM_STAGE_QUERY, {
variables: { id: programStage.id, nameProperty: displayNameProp },
})

const { programStageDataElements } = data
Expand Down
9 changes: 1 addition & 8 deletions src/components/plugin/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ import LoadingMask from './LoadingMask.js'
import MapContainer from './MapContainer.js'

const d2Config = {
schemas: [
'dataElement',
'dataSet',
'indicator',
'legendSet',
'organisationUnitGroup',
'programStage',
],
schemas: ['dataElement', 'dataSet', 'indicator', 'legendSet'],
}

const query = {
Expand Down
1 change: 1 addition & 0 deletions src/loaders/eventLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const loadEventLayer = async ({
const analyticsRequest = await getAnalyticsRequest(config, {
d2,
nameProperty,
engine,
})
let alert

Expand Down
3 changes: 2 additions & 1 deletion src/util/dataDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const downloadData = async ({
humanReadableKeys,
d2,
nameProperty,
engine,
}) => {
const { name, layer: layerType } = layer
let layerData = layer.data
Expand All @@ -97,7 +98,7 @@ export const downloadData = async ({
const columns = await getEventColumns(layer, {
format,
nameProperty,
d2,
engine,
})
const config = {
...layer,
Expand Down
22 changes: 16 additions & 6 deletions src/util/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import {
import { getOrgUnitsFromRows, getPeriodFromFilters } from './analytics.js'
import { addStyleDataItem, createEventFeatures } from './geojson.js'

export const PROGRAM_STAGE_QUERY = {
programStage: {
resource: 'programStages',
id: ({ id }) => id,
params: ({ nameProperty }) => ({
fields: `programStageDataElements[displayInReports,dataElement[id,code,${nameProperty}~rename(name),optionSet,valueType]]`,
paging: false,
}),
},
}

// Empty filter sometimes returned for saved maps
// Dimension without filter and empty items array returns false
const isValidDimension = ({ dimension, filter, items }) =>
Expand All @@ -15,11 +26,10 @@ const METADATA_FORMAT_NAME = 'name'

export const getEventColumns = async (
layer,
{ format = METADATA_FORMAT_NAME, nameProperty, d2 }
{ format = METADATA_FORMAT_NAME, nameProperty, engine }
) => {
const result = await d2.models.programStage.get(layer.programStage.id, {
fields: `programStageDataElements[displayInReports,dataElement[id,code,${nameProperty}~rename(name),optionSet]]`,
paging: false,
const { programStage: result } = await engine.query(PROGRAM_STAGE_QUERY, {
variables: { id: layer.programStage.id, nameProperty },
})

return result.programStageDataElements
Expand Down Expand Up @@ -48,7 +58,7 @@ export const getAnalyticsRequest = async (
relativePeriodDate,
isExtended,
},
{ d2, nameProperty }
{ d2, nameProperty, engine }
) => {
const orgUnits = getOrgUnitsFromRows(rows)
const period = getPeriodFromFilters(filters)
Expand All @@ -61,7 +71,7 @@ export const getAnalyticsRequest = async (
if (isExtended) {
const displayColumns = await getEventColumns(
{ programStage },
{ d2, nameProperty }
{ engine, nameProperty }
)

displayColumns.forEach((col) => {
Expand Down

0 comments on commit 9bb2645

Please sign in to comment.