Skip to content

Commit

Permalink
fix: allow ou without items
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Jan 2, 2024
1 parent ca615cb commit 0c53793
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
59 changes: 33 additions & 26 deletions cypress/integration/layoutValidation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,51 @@ describe('layout validation', () => {
expectTableToBeVisible()
})
})
it(['>=41'], 'validates that type and org unit are required (TE)', () => {
goToStartPage()
it.only(
['>=41'],
'validates that type and org unit are required (TE)',
() => {
goToStartPage()

cy.getBySel('input-tracked-entity').click()
cy.getBySel('input-tracked-entity').click()

clickMenubarUpdateButton()
clickMenubarUpdateButton()

cy.getBySel('error-container').contains(
'No tracked entity type selected'
)
cy.getBySel('error-container').contains(
'No tracked entity type selected'
)

selectTrackedEntityWithType('Person')
selectTrackedEntityWithType('Person')

// remove org unit
clickAddRemoveMainDimension('Registration org. unit')
// remove org unit
clickAddRemoveMainDimension('Registration org. unit')

clickMenubarUpdateButton()
clickMenubarUpdateButton()

// columns is required
cy.getBySel('error-container').contains('Columns is empty')
// columns is required
cy.getBySel('error-container').contains('Columns is empty')

// add something other than org unit to columns
clickAddRemoveMainDimension('Last updated by')
// add something other than org unit to columns
clickAddRemoveMainDimension('Last updated by')

clickMenubarUpdateButton()
clickMenubarUpdateButton()

// org unit dimension is required
cy.getBySel('error-container').contains('No organisation unit selected')
// org unit isn't required
expectTableToBeVisible()

// remove previously added dimension
clickAddRemoveMainDimension('Last updated by')
// remove previously added dimension
clickAddRemoveMainDimension('Last updated by')

// add org unit to columns
clickAddRemoveMainDimension('Registration org. unit')
// add org unit to columns without any items selected
clickAddRemoveMainDimension('Registration org. unit')
// FIXME: uncomment the following lines once https://dhis2.atlassian.net/browse/DHIS2-16381 is fixed
// openOuDimension(DIMENSION_ID_ORGUNIT)
// deselectUserOrgUnit('User organisation unit')
// clickOrgUnitDimensionModalUpdateButton()

clickMenubarUpdateButton()
clickMenubarUpdateButton()

// validation succeeds when all above are provided
expectTableToBeVisible()
})
expectTableToBeVisible()
}
)
})
8 changes: 7 additions & 1 deletion src/components/Layout/ChipBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import i18n from '@dhis2/d2-i18n'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'
import { useSelector } from 'react-redux'
import { OUTPUT_TYPE_TRACKED_ENTITY } from '../../modules/visualization.js'
import { sGetUiInputType } from '../../reducers/ui.js'
import { DimensionIcon } from '../MainSidebar/DimensionItem/DimensionIcon.js'
import styles from './styles/Chip.module.css'

Expand All @@ -17,11 +20,14 @@ const VALUE_TYPE_BOOLEAN_NUM_OPTIONS = 3
// Presentational component used by dnd - do not add redux or dnd functionality

export const ChipBase = ({ dimension, conditionsLength, itemsLength }) => {
const inputType = useSelector(sGetUiInputType)

const { id, name, dimensionType, optionSet, valueType, suffix } = dimension

const getChipSuffix = () => {
if (
(id === DIMENSION_ID_ORGUNIT ||
((inputType !== OUTPUT_TYPE_TRACKED_ENTITY &&
id === DIMENSION_ID_ORGUNIT) ||
dimensionType === DIMENSION_TYPE_PERIOD) &&
!itemsLength
) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/layoutValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const validateLineListLayout = (layout, { dryRun } = {}) => {
// organisation unit
const ouDimension = layoutGetDimension(layout, DIMENSION_ID_ORGUNIT)
if (
layout.outputType !== OUTPUT_TYPE_TRACKED_ENTITY &&
!(ouDimension && dimensionIsValid(ouDimension, { requireItems: true }))
) {
if (dryRun) {
Expand Down

0 comments on commit 0c53793

Please sign in to comment.