Skip to content

Commit

Permalink
feat: breadcrumb for event and enrollment pages
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Oct 17, 2024
1 parent c24d3eb commit 8daf8ac
Show file tree
Hide file tree
Showing 22 changed files with 662 additions and 145 deletions.
73 changes: 35 additions & 38 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-10-10T14:29:59.249Z\n"
"PO-Revision-Date: 2024-10-10T14:29:59.249Z\n"
"POT-Creation-Date: 2024-10-16T14:15:58.172Z\n"
"PO-Revision-Date: 2024-10-16T14:15:58.172Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -35,6 +35,39 @@ msgstr ""
"(in the same domain). Please refresh this page if you would like to use "
"this version again, but be aware that this will close other versions."

msgid "Enrollment dashboard"
msgstr "Enrollment dashboard"

msgid "View event"
msgstr "View event"

msgid "Edit event"
msgstr "Edit event"

msgid "New event"
msgstr "New event"

msgid "Active enrollments"
msgstr "Active enrollments"

msgid "Completed enrollments"
msgstr "Completed enrollments"

msgid "Cancelled enrollments"
msgstr "Cancelled enrollments"

msgid "Search"
msgstr "Search"

msgid "{{trackedEntityName}} list"
msgstr "{{trackedEntityName}} list"

msgid "Working List"
msgstr "Working List"

msgid "Event list"
msgstr "Event list"

msgid "More"
msgstr "More"

Expand Down Expand Up @@ -293,9 +326,6 @@ msgstr "Yes, discard changes"
msgid "No, cancel"
msgstr "No, cancel"

msgid "New event"
msgstr "New event"

msgid "You don't have access to create an event in the current selections"
msgstr "You don't have access to create an event in the current selections"

Expand Down Expand Up @@ -514,9 +544,6 @@ msgstr "Type to filter options"
msgid "No match found"
msgstr "No match found"

msgid "Search"
msgstr "Search"

msgid "Clear"
msgstr "Clear"

Expand Down Expand Up @@ -747,9 +774,6 @@ msgstr "Program Stages could not be loaded"
msgid "Stage"
msgstr "Stage"

msgid "Registered events"
msgstr "Registered events"

msgid ""
"The category option is not valid for the selected organisation unit. Please "
"select a valid combination."
Expand Down Expand Up @@ -857,9 +881,6 @@ msgstr "event"
msgid "You don't have access to edit this event"
msgstr "You don't have access to edit this event"

msgid "Edit event"
msgstr "Edit event"

msgid "View changelog"
msgstr "View changelog"

Expand All @@ -885,9 +906,6 @@ msgstr "Indicators"
msgid "Warnings"
msgstr "Warnings"

msgid "Show all events"
msgstr "Show all events"

msgid "Event could not be loaded. Are you sure it exists?"
msgstr "Event could not be loaded. Are you sure it exists?"

Expand All @@ -897,15 +915,6 @@ msgstr "Event could not be loaded"
msgid "Organisation unit could not be loaded"
msgstr "Organisation unit could not be loaded"

msgid "Dashboard"
msgstr "Dashboard"

msgid "Edit Event"
msgstr "Edit Event"

msgid "View Event"
msgstr "View Event"

msgid "Selected program"
msgstr "Selected program"

Expand Down Expand Up @@ -1071,9 +1080,6 @@ msgstr "Create new event"
msgid "Search for a {{trackedEntityName}} in {{programName}}"
msgstr "Search for a {{trackedEntityName}} in {{programName}}"

msgid "Back to list"
msgstr "Back to list"

msgid "No tracked entity types available"
msgstr "No tracked entity types available"

Expand Down Expand Up @@ -1602,15 +1608,6 @@ msgstr "Follow up"
msgid "Choose a program stage to filter by {{label}}"
msgstr "Choose a program stage to filter by {{label}}"

msgid "Active enrollments"
msgstr "Active enrollments"

msgid "Completed enrollments"
msgstr "Completed enrollments"

msgid "Cancelled enrollments"
msgstr "Cancelled enrollments"

msgid "Working list could not be updated"
msgstr "Working list could not be updated"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// @flow
import type { ComponentType } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import i18n from '@dhis2/d2-i18n';
import { withStyles } from '@material-ui/core/styles';
import { colors, IconChevronRight16 } from '@dhis2/ui';
import { useWorkingListLabel } from './hooks/useWorkingListLabel';
import { BreadcrumbItem } from '../common/BreadcrumbItem';
import { defaultDialogProps } from '../../Dialogs/DiscardDialog.constants';
import { DiscardDialog } from '../../Dialogs/DiscardDialog.component';

type Props = {
onBackToMainPage: () => void,
onBackToDashboard?: () => void,
onBackToViewEvent?: () => void,
displayFrontPageList: boolean,
programId: string,
userInteractionInProgress?: boolean,
trackedEntityName?: string,
};

export const EventStatuses = {
ACTIVE: 'ACTIVE',
COMPLETED: 'COMPLETED',
SKIPPED: 'SKIPPED',
SCHEDULE: 'SCHEDULE',
OVERDUE: 'OVERDUE',
};

const styles = {
container: {
display: 'flex',
alignItems: 'center',
},
};

export const EnrollmentPageKeys = Object.freeze({
MAIN_PAGE: 'mainPage',
OVERVIEW: 'overview',
NEW_EVENT: 'newEvent',
EDIT_EVENT: 'editEvent',
VIEW_EVENT: 'viewEvent',
});

const eventIsScheduled = eventStatus => [EventStatuses.SCHEDULE, EventStatuses.OVERDUE, EventStatuses.SKIPPED]
.includes(eventStatus);

const BreadcrumbsPlain = ({
onBackToMainPage,
onBackToDashboard,
onBackToViewEvent,
eventStatus,
programId,
trackedEntityName,
displayFrontPageList,
userInteractionInProgress = false,
page,
classes,
}) => {
const [openWarning, setOpenWarning] = useState(null);

const { label } = useWorkingListLabel({
trackedEntityName,
programId,
displayFrontPageList,
});

const handleNavigation = useCallback((callback, warningType) => {
if (userInteractionInProgress) {
setOpenWarning(warningType);
} else {
callback && callback();
}
}, [userInteractionInProgress]);

const breadcrumbItems = useMemo(() => ([
{
key: 'mainPage',
onClick: () => handleNavigation(onBackToMainPage, 'mainPage'),
label,
selected: page === EnrollmentPageKeys.MAIN_PAGE,
condition: true,
},
{
key: 'dashboard',
onClick: () => handleNavigation(onBackToDashboard, 'dashboard'),
label: i18n.t('Enrollment dashboard'),
selected: page === EnrollmentPageKeys.OVERVIEW,
condition: page !== EnrollmentPageKeys.MAIN_PAGE,
},
{
key: 'viewEvent',
onClick: () => {
handleNavigation(onBackToViewEvent, 'viewEvent');
},
label: i18n.t('View event'),
selected: page === EnrollmentPageKeys.VIEW_EVENT,
condition: page === EnrollmentPageKeys.VIEW_EVENT ||
(page === EnrollmentPageKeys.EDIT_EVENT && !eventIsScheduled(eventStatus)),
},
{
key: 'editEvent',
onClick: () => {},
label: i18n.t('Edit event'),
selected: page === EnrollmentPageKeys.EDIT_EVENT,
condition: page === EnrollmentPageKeys.EDIT_EVENT,
},
{
key: 'newEvent',
onClick: () => {},
label: i18n.t('New event'),
selected: page === EnrollmentPageKeys.NEW_EVENT,
condition: page === EnrollmentPageKeys.NEW_EVENT,
},
].filter(item => item.condition !== false)), [
label,
page,
eventStatus,
handleNavigation,
onBackToMainPage,
onBackToDashboard,
onBackToViewEvent,
]);

return (
<div className={classes.container}>
{breadcrumbItems.map((button, index) => (
<React.Fragment key={button.key}>
<BreadcrumbItem
label={button.label}
onClick={button.onClick}
selected={button.selected}
/>
{index < (breadcrumbItems.length - 1) && (
<IconChevronRight16 color={colors.grey800} />
)}
</React.Fragment>
))}

<DiscardDialog
open={openWarning === 'mainPage'}
onDestroy={() => {
setOpenWarning(null);
onBackToMainPage && onBackToMainPage();
}}
onCancel={() => setOpenWarning(null)}
{...defaultDialogProps}
/>

<DiscardDialog
open={openWarning === 'dashboard'}
onDestroy={() => {
setOpenWarning(null);
onBackToDashboard && onBackToDashboard();
}}
onCancel={() => setOpenWarning(null)}
{...defaultDialogProps}
/>

<DiscardDialog
open={openWarning === 'viewEvent'}
onDestroy={() => {
setOpenWarning(null);
onBackToViewEvent && onBackToViewEvent();
}}
onCancel={() => setOpenWarning(null)}
{...defaultDialogProps}
/>
</div>
);
};

export const EnrollmentBreadcrumb: ComponentType<$Diff<Props, CssClasses>> = withStyles(styles)(BreadcrumbsPlain);
Loading

0 comments on commit 8daf8ac

Please sign in to comment.