From 0c53793eba9ce148210ec0b26e0ab3f3ba006247 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Tue, 2 Jan 2024 10:42:17 +0000 Subject: [PATCH] fix: allow ou without items --- cypress/integration/layoutValidation.cy.js | 59 ++++++++++++---------- src/components/Layout/ChipBase.js | 8 ++- src/modules/layoutValidation.js | 1 + 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/cypress/integration/layoutValidation.cy.js b/cypress/integration/layoutValidation.cy.js index 2dc90dd68..48e852f6c 100644 --- a/cypress/integration/layoutValidation.cy.js +++ b/cypress/integration/layoutValidation.cy.js @@ -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() + } + ) }) diff --git a/src/components/Layout/ChipBase.js b/src/components/Layout/ChipBase.js index d23e0ebab..29e8ffee6 100644 --- a/src/components/Layout/ChipBase.js +++ b/src/components/Layout/ChipBase.js @@ -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' @@ -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 ) { diff --git a/src/modules/layoutValidation.js b/src/modules/layoutValidation.js index 1cb446d18..80d4bfd45 100644 --- a/src/modules/layoutValidation.js +++ b/src/modules/layoutValidation.js @@ -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) {