-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [DHIS2-17575] disable create new buttons if no data write access (
- Loading branch information
1 parent
9dc3ef5
commit 5b3cd1c
Showing
13 changed files
with
165 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
cypress/e2e/EnrollmentAddEventPage/ProgramStageSelector/ProgramStageSelector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...omponents/WidgetStagesAndEvents/Stages/Stage/StageCreateNewButton/StageCreateNewButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// @flow | ||
import React, { useMemo } from 'react'; | ||
import { Button, IconAdd16 } from '@dhis2/ui'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import { ConditionalTooltip } from '../../../../Tooltips/ConditionalTooltip'; | ||
|
||
type Props = { | ||
onCreateNew: (stageId: string) => void, | ||
stageWriteAccess: ?boolean, | ||
eventCount: number, | ||
repeatable: ?boolean, | ||
preventAddingEventActionInEffect: ?boolean, | ||
eventName: string, | ||
} | ||
|
||
export const StageCreateNewButton = ({ | ||
onCreateNew, | ||
stageWriteAccess, | ||
eventCount, | ||
repeatable, | ||
preventAddingEventActionInEffect, | ||
eventName, | ||
}: Props) => { | ||
const { isDisabled, tooltipContent } = useMemo(() => { | ||
if (!stageWriteAccess) { | ||
return ({ | ||
isDisabled: true, | ||
tooltipContent: i18n.t('You do not have access to create events in this stage', { | ||
programStageName: eventName, | ||
interpolation: { escapeValue: false }, | ||
}), | ||
}); | ||
} | ||
if (preventAddingEventActionInEffect) { | ||
return { | ||
isDisabled: true, | ||
tooltipContent: i18n.t("You can't add any more {{ programStageName }} events", { | ||
programStageName: eventName, | ||
interpolation: { escapeValue: false }, | ||
}), | ||
}; | ||
} | ||
if (!repeatable && eventCount > 0) { | ||
return { | ||
isDisabled: true, | ||
tooltipContent: i18n.t('This stage can only have one event'), | ||
}; | ||
} | ||
return { | ||
isDisabled: false, | ||
tooltipContent: '', | ||
}; | ||
}, [eventCount, eventName, preventAddingEventActionInEffect, repeatable, stageWriteAccess]); | ||
|
||
return ( | ||
<ConditionalTooltip | ||
enabled={isDisabled} | ||
content={tooltipContent} | ||
closeDelay={50} | ||
> | ||
<Button | ||
small | ||
secondary | ||
icon={<IconAdd16 />} | ||
onClick={onCreateNew} | ||
dataTest={'create-new-button'} | ||
disabled={isDisabled} | ||
> | ||
{i18n.t('New {{ eventName }} event', { | ||
eventName, interpolation: { escapeValue: false }, | ||
})} | ||
</Button> | ||
</ConditionalTooltip> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
.../capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageCreateNewButton/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @flow | ||
|
||
export { StageCreateNewButton } from './StageCreateNewButton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters