Skip to content

Commit

Permalink
feat: bread crumbs for survey list page
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Feb 13, 2025
1 parent 0592d5b commit 4e10a46
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/data/repositories/SurveyFormD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export class SurveyD2Repository implements SurveyRepository {
const prevalenceSurveyName = survey.dataValues?.find(
dv => dv.dataElement === PREVALENCE_SURVEY_NAME_DATAELEMENT_ID
)?.value;

const customASTGuideline = survey.dataValues?.find(
dv => dv.dataElement === AMR_SURVEYS_PREVALENCE_DEA_CUSTOM_AST_GUIDE
)?.value;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/entities/AMRSurveyModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type SurveyRule = {

export interface AMRSurveyModule {
id: string;
name: string;
name: "PPS" | "Prevalence";
color: string;
surveyPrograms: NamedRef[];
userGroups: UserGroups;
Expand Down
16 changes: 12 additions & 4 deletions src/domain/usecases/GetAllSurveysUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ export class GetAllSurveysUseCase {
.map(child => child.count)
.reduce((agg, childCount) => agg + childCount, 0);

const rootName =
survey.rootSurvey.name === ""
? parentDetails.name
: survey.rootSurvey.name;

const newRootSurvey: SurveyBase = {
surveyType: survey.rootSurvey.surveyType,
id: survey.rootSurvey.id,
name:
survey.rootSurvey.name === ""
? parentDetails.name
: survey.rootSurvey.name,
name: rootName,
astGuideline: survey.rootSurvey.astGuideline
? survey.rootSurvey.astGuideline
: parentDetails.astGuidelineType,
};

const updatedSurvey: Survey = {
...survey,
name:
surveyFormType === "PrevalenceSurveyForm"
? parentDetails.name
: surveyFormType === "PrevalenceFacilityLevelForm"
? survey.facilityCode ?? survey.name
: survey.name,
rootSurvey: newRootSurvey,
childCount: count,
};
Expand Down
4 changes: 4 additions & 0 deletions src/domain/usecases/GetPaginatedSurveysUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export class GetPaginatedSurveysUseCase {

const updatedSurvey: Survey = {
...survey,
name:
surveyFormType === "PrevalenceCaseReportForm"
? survey.uniquePatient?.id ?? survey.name
: survey.name,
rootSurvey: newRootSurvey,
childCount: childCount,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Breadcrumbs, Button } from "@material-ui/core";
import { NavLink } from "react-router-dom";
import styled from "styled-components";
import ChevronRightIcon from "@material-ui/icons/ChevronRight";
import { useCurrentSurveys } from "../../contexts/current-surveys-context";
import { palette } from "../../pages/app/themes/dhis2.theme";
import { SURVEY_FORM_TYPES } from "../../../domain/entities/Survey";
import { useCurrentSurveys } from "../../../contexts/current-surveys-context";
import { palette } from "../../../pages/app/themes/dhis2.theme";
import { SURVEY_FORM_TYPES } from "../../../../domain/entities/Survey";
import i18n from "@eyeseetea/feedback-component/locales";
import { getUserAccess } from "../../../domain/utils/menuHelper";
import { useAppContext } from "../../contexts/app-context";
import { useCurrentModule } from "../../contexts/current-module-context";
import { getUserAccess } from "../../../../domain/utils/menuHelper";
import { useAppContext } from "../../../contexts/app-context";
import { useCurrentModule } from "../../../contexts/current-module-context";

export interface SurveyListBreadCrumbProps {
export interface PPSListBreadCrumbsProps {
formType: SURVEY_FORM_TYPES;
}

export const SurveyListBreadCrumb: React.FC<SurveyListBreadCrumbProps> = ({ formType }) => {
export const PPSListBreadCrumbs: React.FC<PPSListBreadCrumbsProps> = ({ formType }) => {
const {
currentPPSSurveyForm,
currentCountryQuestionnaire,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { Breadcrumbs, Button } from "@material-ui/core";
import { NavLink } from "react-router-dom";
import styled from "styled-components";
import ChevronRightIcon from "@material-ui/icons/ChevronRight";
import { useCurrentSurveys } from "../../../contexts/current-surveys-context";
import { palette } from "../../../pages/app/themes/dhis2.theme";
import { SURVEY_FORM_TYPES } from "../../../../domain/entities/Survey";
import i18n from "@eyeseetea/feedback-component/locales";
import { useCallback } from "react";
import { getSurveyDisplayName } from "../../../../domain/utils/PPSProgramsHelper";

export interface PrevalenceListBreadCrumbsProps {
formType: SURVEY_FORM_TYPES;
}

export const PrevalenceListBreadCrumbs: React.FC<PrevalenceListBreadCrumbsProps> = ({
formType,
}) => {
const { currentPrevalenceSurveyForm, currentFacilityLevelForm, currentCaseReportForm } =
useCurrentSurveys();

const isPrevelanceChild = useCallback(() => {
return (
formType === "PrevalenceCaseReportForm" ||
formType === "PrevalenceCentralRefLabForm" ||
formType === "PrevalencePathogenIsolatesLog" ||
formType === "PrevalenceSampleShipTrackForm" ||
formType === "PrevalenceSupranationalRefLabForm" ||
formType === "PrevalenceDischarge" ||
formType === "PrevalenceD28FollowUp" ||
formType === "PrevalenceCohortEnrolment"
);
}, [formType]);

const getCaseReportNameCrumb = useCallback(() => {
return (
<>
<Button
component={NavLink}
to={`/survey/PrevalenceCaseReportForm/${currentCaseReportForm?.id}`}
exact={true}
>
<span>{currentCaseReportForm?.name}</span>
</Button>
<ChevronRightIcon />
</>
);
}, [currentCaseReportForm]);

return (
<StyledBreadCrumbs aria-label="breadcrumb" separator={<ChevronRightIcon />}>
<Button component={NavLink} to={`/surveys/PrevalenceSurveyForm`} exact={true}>
<span> {i18n.t("Prevalence Surveys")}</span>
</Button>

{(formType === "PrevalenceFacilityLevelForm" || isPrevelanceChild()) && (
<StyledBreadCrumbChild>
<>
<Button
component={NavLink}
to={`/survey/PrevalenceSurveyForm/${currentPrevalenceSurveyForm?.id}`}
exact={true}
>
<span>{currentPrevalenceSurveyForm?.name}</span>
</Button>
<ChevronRightIcon />
</>
<Button
component={NavLink}
to={`/surveys/PrevalenceFacilityLevelForm`}
exact={true}
>
<span>{i18n.t("Facilities")}</span>
</Button>
</StyledBreadCrumbChild>
)}

{isPrevelanceChild() && (
<StyledBreadCrumbChild>
<>
<Button
component={NavLink}
to={`/survey/PrevalenceFacilityLevelForm/${currentFacilityLevelForm?.id}`}
exact={true}
>
<span>{currentFacilityLevelForm?.name}</span>
</Button>
<ChevronRightIcon />
</>
<Button
component={NavLink}
to={`/surveys/PrevalenceCaseReportForm`}
exact={true}
>
<span>{i18n.t("Case Reports")}</span>
</Button>
</StyledBreadCrumbChild>
)}

{isPrevelanceChild() && !(formType === "PrevalenceCaseReportForm") && (
<StyledBreadCrumbChild>
{getCaseReportNameCrumb()}
<Button>
<span>{i18n.t(`${getSurveyDisplayName(formType)} List`)}</span>
</Button>
</StyledBreadCrumbChild>
)}
</StyledBreadCrumbs>
);
};

export const StyledBreadCrumbChild = styled.div`
display: flex;
align-items: center;
`;

export const StyledBreadCrumbs = styled(Breadcrumbs)`
font-weight: 300;
a {
padding: 0px;
}
li {
display: flex;
align-items: center;
.MuiButton-root {
span {
color: ${palette.primary.main};
}
}
.MuiButton-text {
min-width: 0;
}
}
svg {
color: ${palette.shadow};
}
.MuiBreadcrumbs-separator {
padding: 0;
margin: 0;
}
`;
5 changes: 4 additions & 1 deletion src/webapp/components/survey/SurveyFormBreadCrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { useCurrentSurveys } from "../../contexts/current-surveys-context";
import { SURVEY_FORM_TYPES } from "../../../domain/entities/Survey";
import i18n from "@eyeseetea/feedback-component/locales";
import { Id } from "../../../domain/entities/Ref";
import { StyledBreadCrumbChild, StyledBreadCrumbs } from "../survey-list/SurveyListBreadCrumb";
import {
StyledBreadCrumbChild,
StyledBreadCrumbs,
} from "../survey-list/bread-crumbs/PPSListBreadCrumbs";
import { useAppContext } from "../../contexts/app-context";
import { useCurrentModule } from "../../contexts/current-module-context";
import { getUserAccess } from "../../../domain/utils/menuHelper";
Expand Down
8 changes: 6 additions & 2 deletions src/webapp/pages/survey-list/SurveyListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import styled from "styled-components";
import { SURVEY_FORM_TYPES } from "../../../domain/entities/Survey";
import { SurveyList } from "../../components/survey-list/SurveyList";
import { useCurrentSurveys } from "../../contexts/current-surveys-context";
import { SurveyListBreadCrumb } from "../../components/survey-list/SurveyListBreadCrumb";
import { PPSListBreadCrumbs } from "../../components/survey-list/bread-crumbs/PPSListBreadCrumbs";
import { useCurrentModule } from "../../contexts/current-module-context";
import { useRedirectHome } from "./useRedirectHome";
import { getUserAccess } from "../../../domain/utils/menuHelper";
import { useAppContext } from "../../contexts/app-context";
import { PrevalenceListBreadCrumbs } from "../../components/survey-list/bread-crumbs/PrevalenceListBreadCrumbs";

export const SurveyListPage: React.FC = React.memo(() => {
const { formType } = useParams<{ formType: SURVEY_FORM_TYPES }>();
Expand Down Expand Up @@ -48,7 +49,10 @@ export const SurveyListPage: React.FC = React.memo(() => {

return (
<ContentWrapper>
{currentModule?.name === "PPS" && <SurveyListBreadCrumb formType={formType} />}
{currentModule?.name === "PPS" && <PPSListBreadCrumbs formType={formType} />}
{currentModule?.name === "Prevalence" && (
<PrevalenceListBreadCrumbs formType={formType} />
)}
<SurveyList surveyFormType={formType} />
</ContentWrapper>
);
Expand Down

0 comments on commit 4e10a46

Please sign in to comment.