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: remove fetching of schemas and use the data engine instead for api requests #3197

Merged
merged 25 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d7c7e0c
chore: start cleanup
jenniferarnesen Apr 25, 2024
4c4a675
chore: remove externalMapLayer schema and use dataEngine instead
jenniferarnesen Apr 29, 2024
53282a5
chore: remove schemas already not in use
jenniferarnesen Apr 29, 2024
2153ab3
chore: refactor to get rid of organisationUnitLevels schema
jenniferarnesen Apr 29, 2024
8aec7e7
chore: remove organisationUnitGroupSet schema
jenniferarnesen May 6, 2024
5815e1f
chore: remove d2 from GroupStyle
jenniferarnesen May 7, 2024
42dde41
chore: remove optionSet schema
jenniferarnesen May 7, 2024
af49909
chore: cleanup AppWrapper for clarity
jenniferarnesen May 7, 2024
e45527c
chore: add cypress tests and fix error destructuring undefined
jenniferarnesen May 15, 2024
9b8353b
chore: orgunitlevels must come before orgunitgroups
jenniferarnesen May 16, 2024
6e6c436
chore: add cypress test covering dataElementGroup
jenniferarnesen May 16, 2024
59e334e
Merge branch 'dev' into chore/remove-unneeded-schemas
jenniferarnesen Jun 4, 2024
a3a0a20
Merge branch 'dev' into chore/remove-unneeded-schemas
jenniferarnesen Jun 14, 2024
7879773
Merge branch 'chore/remove-unneeded-schemas' of github.com:dhis2/maps…
jenniferarnesen Jun 14, 2024
c02fb3b
chore: use all caps for query objects
jenniferarnesen Jun 14, 2024
ec06f78
chore: add TODO for later
jenniferarnesen Jun 14, 2024
0265328
chore: use correct prop name
jenniferarnesen Jun 14, 2024
46a51e4
chore: maps already converted to app-runtime
jenniferarnesen Jun 18, 2024
17a8150
Merge branch 'master' into chore/remove-unneeded-schemas
jenniferarnesen Aug 2, 2024
9bb2645
chore: remove orgUnit, orgUnitGroup, program, programStage schemas (#…
jenniferarnesen Aug 8, 2024
72c8d1f
chore: remove dataElement, dataSet, indicator, legendSet schemas (#3254)
jenniferarnesen Aug 8, 2024
f57ec1a
chore: add currentUser to cached data query
jenniferarnesen Aug 9, 2024
a9e883a
Merge branch 'master' into chore/remove-unneeded-schemas
jenniferarnesen Aug 16, 2024
1fa6f71
Merge branch 'chore/remove-unneeded-schemas' of github.com:dhis2/maps…
jenniferarnesen Aug 16, 2024
66a2e5b
chore: debugging
jenniferarnesen Aug 16, 2024
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
2 changes: 1 addition & 1 deletion cypress/fixtures/externalMapLayersWithGeojson.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
"name": "Polygon only geojson"
}
]
}
}
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
22 changes: 22 additions & 0 deletions cypress/integration/layers/eventlayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,26 @@ context('Event Layers', () => {
Layer.validateCardTitle('Inpatient morbidity and mortality')
Layer.validateCardItems(['Event'])
})

it('adds an event layer and applies style for boolean data element', () => {
Layer.openDialog('Events')
.selectProgram('E2E program')
.validateStage('Stage 1 - Repeatable')
.selectTab('Style')

cy.getByDataTest('style-by-data-element-select').click()

cy.getByDataTest('dhis2-uicore-singleselectoption')
.contains('E2E - Yes/no')
.click()

cy.getByDataTest('dhis2-uicore-modalactions')
.contains('Add layer')
.click()

Layer.validateDialogClosed(true)

Layer.validateCardTitle('Stage 1 - Repeatable')
Layer.validateCardItems(['Yes', 'No', 'Not set'])
})
})
24 changes: 22 additions & 2 deletions cypress/integration/layers/facilitylayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,30 @@ context('Facility Layers', () => {
.addToMap()

Layer.validateDialogClosed(true)
Layer.validateCardTitle('Facilities')
Layer.validateCardItems(['Facility'])
})

// TODO: use visual snapshot testing to check the rendering of the map
it('adds a facilities layer and changes the style', () => {
Layer.openDialog('Facilities')
.selectTab('Organisation Units')
.selectOu('Bo')
.selectOuLevel('Facility')
.selectTab('Style')

cy.getByDataTest('orgunitgroupsetselect-content').click()
cy.getByDataTest('dhis2-uicore-select-menu-menuwrapper')
.contains('Facility Type')
.click()

cy.getByDataTest('group-set-style').should('be.visible')
cy.getByDataTest('group-set-style').children().should('have.length', 5)

cy.getByDataTest('dhis2-uicore-modalactions')
.contains('Add layer')
.click()

Layer.validateCardTitle('Facilities')
Layer.validateCardItems(['Facility'])
Layer.validateCardItems(['CHC', 'CHP', 'Clinic', 'Hospital', 'MCHP'])
})
})
24 changes: 23 additions & 1 deletion cypress/integration/layers/orgunitlayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ context('Org Unit Layers', () => {
cy.contains('No organisation units are selected').should('be.visible')
})

it('adds a org unit layer', () => {
it('adds an org unit layer', () => {
Layer.openDialog('Org units')
.selectOu('Sierra Leone')
.selectOuLevel('District')
Expand All @@ -30,4 +30,26 @@ context('Org Unit Layers', () => {
Layer.validateCardTitle('Organisation units')
Layer.validateCardItems(['District'])
})

it('adds an org unit layer and changes the style', () => {
Layer.openDialog('Org units')
.selectOu('Sierra Leone')
.selectOuLevel('District')
.selectTab('Style')

cy.getByDataTest('orgunitgroupsetselect-content').click()
cy.getByDataTest('dhis2-uicore-select-menu-menuwrapper')
.contains('Facility Type')
.click()

cy.getByDataTest('group-set-style').should('be.visible')
cy.getByDataTest('group-set-style').children().should('have.length', 5)

cy.getByDataTest('dhis2-uicore-modalactions')
.contains('Add layer')
.click()

Layer.validateCardTitle('Organisation units')
Layer.validateCardItems(['CHC', 'CHP', 'Clinic', 'Hospital', 'MCHP'])
})
})
27 changes: 18 additions & 9 deletions cypress/integration/layers/thematiclayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ context('Thematic Layers', () => {
Layer.validateDialogClosed(true)

Layer.validateCardTitle(INDICATOR_NAME)
// TODO: test this in a way that is not dependent on the date
// Layer.validateCardItems([
// '80.9 - 83.04 (1)',
// '83.04 - 85.18 (0)',
// '85.18 - 87.32 (0)',
// '87.32 - 89.46 (0)',
// '89.46 - 91.6 (1)',
// ]);

getMaps().should('have.length', 1)
})

Expand Down Expand Up @@ -138,4 +129,22 @@ context('Thematic Layers', () => {
{ name: VIEW_PROFILE },
])
})

it('adds a thematic layer for data element', () => {
const DE_NAME = 'ANC 1st visit'
Layer.openDialog('Thematic')
.selectItemType('Data element')
.selectDataElementGroup('ANC')
.selectDataElement(DE_NAME)
.addToMap()

Layer.validateDialogClosed(true)

Layer.validateCardTitle(DE_NAME)
cy.getByDataTest(`card-ANC1stvisit`)
.findByDataTest('layerlegend-item')
.should('have.length', 5)

getMaps().should('have.length', 1)
})
})
9 changes: 9 additions & 0 deletions cypress/integration/routes.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ describe('Routes', () => {
const Layer = new ThematicLayer()
Layer.validateCardTitle('ANC 1 Coverage')
cy.get('canvas.maplibregl-canvas').should('be.visible')

cy.getByDataTest(`card-ANC1Coverage`)
.findByDataTest('layerlegend-item')
.should('have.length', 7)

cy.getByDataTest(`card-ANC1Coverage`)
.findByDataTest('layerlegend-item')
.first()
.contains('Low 0 - 30')
})

it('loads with map id (legacy) and interpretationid lowercase', () => {
Expand Down
19 changes: 1 addition & 18 deletions src/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@ log.setLevel(
)

const d2Config = {
schemas: [
'dataElement',
'dataElementGroup',
'dataSet',
'externalMapLayer',
'indicator',
'indicatorGroup',
'legendSet',
'map',
'optionSet',
'organisationUnit',
'organisationUnitGroup',
'organisationUnitGroupSet',
'organisationUnitLevel',
'program',
'programStage',
'userGroup',
],
schemas: [],
}

const replaceLegacyUrl = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/OrgUnitsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ORG_UNITS_QUERY = {
roots: {
resource: 'organisationUnits',
params: () => ({
fields: ['id', 'displayName~rename(name)', 'path'],
fields: ['id', 'displayName~rename(name)', 'path'], // TODO organisationUnits has shortName
userDataViewFallback: true,
}),
},
Expand Down
1 change: 1 addition & 0 deletions src/components/dataItem/StyleByDataItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const StyleByDataItem = ({ program, programStage, error }) => {
value={styleDataItem ? styleDataItem.id : null}
items={dataItems}
onChange={onChange}
dataTest="style-by-data-element-select"
/>
{styleDataItem && (
<DataItemStyle key="style" dataItem={styleDataItem} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/groupSet/GroupSetSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const GroupSetSelect = ({
error?.message || (!value && errorText ? errorText : null)
}
className={className}
data-test="orgunitgroupsetselect"
dataTest="orgunitgroupsetselect"
/>
)
}
Expand Down
19 changes: 6 additions & 13 deletions src/components/groupSet/GroupSetStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import { Help } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState, useEffect } from 'react'
import { STYLE_TYPE_COLOR } from '../../constants/layers.js'
import { parseGroupSet } from '../../util/orgUnits.js'
import {
ORG_UNITS_GROUP_SET_QUERY,
parseGroupSet,
} from '../../util/orgUnits.js'
import GroupStyle from './GroupStyle.js'
import styles from './styles/GroupSetStyle.module.css'

const GROUP_SETS_QUERY = {
groupSets: {
resource: 'organisationUnitGroupSets',
id: ({ id }) => id,
params: {
fields: ['organisationUnitGroups[id,name,color,symbol]'],
},
},
}

const GroupSetStyle = ({ defaultStyleType = STYLE_TYPE_COLOR, groupSet }) => {
const [groups, setGroups] = useState([])
const { error: err, refetch } = useDataQuery(GROUP_SETS_QUERY, {
const { error: err, refetch } = useDataQuery(ORG_UNITS_GROUP_SET_QUERY, {
lazy: true,
onComplete: ({ groupSets }) => {
const groupsWithColors = parseGroupSet({
Expand All @@ -45,7 +38,7 @@ const GroupSetStyle = ({ defaultStyleType = STYLE_TYPE_COLOR, groupSet }) => {
}

return (
<div className={styles.groupSetStyle}>
<div data-test="group-set-style" className={styles.groupSetStyle}>
{groups?.map((group) => (
<GroupStyle
key={group.id}
Expand Down
15 changes: 4 additions & 11 deletions src/components/groupSet/GroupStyle.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { getInstance as getD2 } from 'd2'
import { useConfig } from '@dhis2/app-runtime'
import PropTypes from 'prop-types'
import React, { useState, useEffect } from 'react'
import React from 'react'
import styles from './styles/GroupStyle.module.css'

const GroupStyle = ({ name, color, symbol, styleType }) => {
const [imagePath, setImagePath] = useState()
const { baseUrl } = useConfig()
const imagePath = `${baseUrl}/images/orgunitgroup/`
const useColor = styleType !== 'SYMBOL'

useEffect(() => {
getD2().then((d2) =>
setImagePath(
`${d2.system.systemInfo.contextPath}/images/orgunitgroup/`
)
)
}, [])

return (
<div className={styles.item}>
{useColor ? (
Expand Down
Loading
Loading