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

feat: [DHIS2-16125] hide program stage under certain circumstances #3735

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Feature: Hidden program stage

Scenario: The user cannot add an event in a hidden program stage
Given you add an enrollment event that will result in a rule effect to hide a program stage
Then the New Postpartum care visit event button is disabled in the stages and events widget
Then the Postpartum care visit stage should not be displayed in the Stages and Events widget
And the Postpartum care visit button is disabled in the enrollmentEventNew page
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ Given('you add an enrollment event that will result in a rule effect to hide a p
cy.contains('[data-test="dhis2-uicore-button"]', 'Save without completing').click();
});

Then('the New Postpartum care visit event button is disabled in the stages and events widget', () => {
cy.contains('[data-test="create-new-button"]', 'New Postpartum care visit event')
.should('be.disabled');
Then('the Postpartum care visit stage should not be displayed in the Stages and Events widget', () => {
cy.get('[data-test="stages-and-events-widget"]').should('not.contain', 'Postpartum care visit');
});

Then('the Postpartum care visit button is disabled in the enrollmentEventNew page', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cx from 'classnames';
import i18n from '@dhis2/d2-i18n';
import { withStyles } from '@material-ui/core';
import { spacersNum, colors, IconAdd16, Button } from '@dhis2/ui';
import { ConditionalTooltip } from 'capture-core/components/Tooltips/ConditionalTooltip';
import { StageOverview } from './StageOverview';
import type { Props } from './stage.types';
import { Widget } from '../../../Widget';
Expand All @@ -24,14 +23,20 @@ const styles = {
alignItems: 'center',
},
};
const hideProgramStage = (ruleEffects, stageId) => (
const rulesEffectHideProgramStage = (ruleEffects, stageId) => (
Boolean(ruleEffects?.find(ruleEffect => ruleEffect.type === 'HIDEPROGRAMSTAGE' && ruleEffect.id === stageId))
);

export const StagePlain = ({ stage, events, classes, className, onCreateNew, ruleEffects, ...passOnProps }: Props) => {
const [open, setOpenStatus] = useState(true);
const { id, name, icon, description, dataElements, hideDueDate, repeatable, enableUserAssignment } = stage;
const hiddenProgramStage = hideProgramStage(ruleEffects, id);
const preventAddingNewEvents = rulesEffectHideProgramStage(ruleEffects, id);
const hideProgramStage = preventAddingNewEvents && events.length === 0;

const handleOpen = useCallback(() => setOpenStatus(true), [setOpenStatus]);
const handleClose = useCallback(() => setOpenStatus(false), [setOpenStatus]);

if (hideProgramStage) return null;

return (
<div
Expand All @@ -46,8 +51,8 @@ export const StagePlain = ({ stage, events, classes, className, onCreateNew, rul
events={events}
/>}
borderless
onOpen={useCallback(() => setOpenStatus(true), [setOpenStatus])}
onClose={useCallback(() => setOpenStatus(false), [setOpenStatus])}
onOpen={handleOpen}
onClose={handleClose}
open={open}
>
{events.length > 0 ? <StageDetail
Expand All @@ -59,31 +64,22 @@ export const StagePlain = ({ stage, events, classes, className, onCreateNew, rul
repeatable={repeatable}
enableUserAssignment={enableUserAssignment}
onCreateNew={onCreateNew}
hiddenProgramStage={hiddenProgramStage}
hiddenProgramStage={preventAddingNewEvents}
{...passOnProps}
/> : (
<ConditionalTooltip
content={i18n.t("You can't add any more {{ programStageName }} events", {
programStageName: name,
<Button
small
secondary
icon={<IconAdd16 />}
className={classes.button}
dataTest="create-new-button"
onClick={() => onCreateNew(id)}
>
{i18n.t('New {{ eventName }} event', {
eventName: name,
interpolation: { escapeValue: false },
})}
enabled={hiddenProgramStage}
>
<Button
small
secondary
disabled={hiddenProgramStage}
icon={<IconAdd16 />}
className={classes.button}
dataTest="create-new-button"
onClick={() => onCreateNew(id)}
>
{i18n.t('New {{ eventName }} event', {
eventName: name,
interpolation: { escapeValue: false },
})}
</Button>
</ConditionalTooltip>
</Button>
)}
</Widget>
</div>
Expand Down
Loading