Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian committed Jan 7, 2025
1 parent 4fd7a7d commit 936bfd3
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions services/ui-src/src/components/reports/DrawerReportPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useState } from "react";
import { useContext, useEffect, useState } from "react";
import uuid from "react-uuid";
// components
import {
Expand Down Expand Up @@ -38,6 +38,7 @@ import {
FormField,
isFieldElement,
InputChangeEvent,
FormJson,
} from "types";
// assets
import addIcon from "assets/icons/icon_add_blue.png";
Expand All @@ -46,6 +47,8 @@ import unfinishedIcon from "assets/icons/icon_error_circle_bright.png";

export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
const [submitting, setSubmitting] = useState<boolean>(false);
const [selectedIsCustomEntity, setSelectedIsCustomEntity] =
useState<boolean>(false);
const { isOpen, onClose, onOpen } = useDisclosure();
const { updateReport } = useContext(ReportContext);

Expand All @@ -54,13 +57,12 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
const { report, selectedEntity, setSelectedEntity } = useStore();

const { entityType, verbiage, drawerForm, form: standardForm } = route;
const { addEntityDrawerForm } = route ?? {};
const canAddEntities = !!addEntityDrawerForm;
const addEntityDrawerForm = route.addEntityDrawerForm || ({} as FormJson);
const canAddEntities = !!addEntityDrawerForm.id;
const entities = report?.fieldData?.[entityType];

// check if there are ILOS and associated plans
const isMcparReport = route.path.includes("mcpar");
const isAnalysisMethodsPage = route.path.includes("analysis-methods");
const reportingOnIlos = route.path === "/mcpar/plan-level-indicators/ilos";
const ilos = report?.fieldData?.["ilos"];
const hasIlos = ilos?.length;
Expand All @@ -82,6 +84,16 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
reportingOnPatientAccessApi === "Yes" ? false : true
);

useEffect(() => {
const isCustomEntity =
// we are on a page where custom entities can be added
canAddEntities &&
// and the selectedEntity id is not in the default analysis methods list (only custom entity drawer page)
!getDefaultAnalysisMethodIds().includes(selectedEntity?.id!);
// enable logic for custom entity manipulation
setSelectedIsCustomEntity(isCustomEntity);
}, [selectedEntity]);

const onChange = (e: InputChangeEvent) => {
if (route.path === "/mcpar/plan-level-indicators/prior-authorization") {
setPriorAuthDisabled(e.target.value !== "Yes");
Expand All @@ -103,15 +115,13 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
let selectedEntityIndex = report?.fieldData[entityType].findIndex(
(entity: EntityShape) => entity.id === selectedEntity?.id
);
if (isAnalysisMethodsPage && selectedEntityIndex < 0) {
// if new custom entity, set index to append to array
if (canAddEntities && selectedEntityIndex < 0) {
selectedEntityIndex = currentEntities.length;
}
let referenceForm = form;
if (
isAnalysisMethodsPage &&
!getDefaultAnalysisMethodIds().includes(selectedEntity?.id!)
) {
referenceForm = addEntityDrawerForm!;
if (selectedIsCustomEntity) {
referenceForm = addEntityDrawerForm;
}
const filteredFormData = filterFormData(
enteredData,
Expand All @@ -122,12 +132,9 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
referenceForm.fields.filter(isFieldElement)
);
const newEntity = {
...selectedEntity,
...(selectedEntity || { id: uuid() }),
...filteredFormData,
};
if (!selectedEntity?.id) {
newEntity.id = uuid();
}
const newEntities = currentEntities;
newEntities[selectedEntityIndex] = newEntity;
newEntities[selectedEntityIndex] = setClearedEntriesToDefaultValue(
Expand Down Expand Up @@ -189,13 +196,12 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {

const entityRows = (entities: EntityShape[]) => {
return entities?.map((entity) => {
const isCustomEntity =
canAddEntities && !getDefaultAnalysisMethodIds().includes(entity.id);
const calculateEntityCompletion = () => {
let formFields = form.fields;
if (
isAnalysisMethodsPage &&
!getDefaultAnalysisMethodIds().includes(entity.id)
) {
formFields = addEntityDrawerForm?.fields!;
if (isCustomEntity) {
formFields = addEntityDrawerForm.fields;
}
return formFields
?.filter(isFieldElement)
Expand All @@ -214,7 +220,7 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
return (
<Flex
key={entity.id}
sx={entityRowStyling(isAnalysisMethodsPage)}
sx={entityRowStyling(canAddEntities)}
data-testid="report-drawer"
>
{isEntityCompleted ? (
Expand All @@ -224,16 +230,15 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
sx={sx.statusIcon}
/>
) : (
isAnalysisMethodsPage && (
canAddEntities && (
<Image
src={unfinishedIcon}
alt={"Entity is incomplete"}
sx={sx.statusIcon}
/>
)
)}
{isAnalysisMethodsPage &&
!getDefaultAnalysisMethodIds().includes(entity.id) ? (
{isCustomEntity ? (
<Flex direction={"column"} sx={sx.customEntityRow}>
<Heading as="h4" sx={sx.customEntityName}>
{entity.custom_analysis_method_name}
Expand Down Expand Up @@ -322,12 +327,7 @@ export const DrawerReportPage = ({ route, validateOnRender }: Props) => {
drawerTitle: `${verbiage.drawerTitle} ${selectedEntity?.name}`,
drawerInfo: verbiage.drawerInfo,
}}
form={
isAnalysisMethodsPage &&
!getDefaultAnalysisMethodIds().includes(selectedEntity?.id!)
? addEntityDrawerForm!
: form
}
form={selectedIsCustomEntity ? addEntityDrawerForm : form}
onSubmit={onSubmit}
submitting={submitting}
drawerDisclosure={{
Expand All @@ -347,7 +347,7 @@ interface Props {
validateOnRender?: boolean;
}

function entityRowStyling(isAnalysisMethodsPage: boolean) {
function entityRowStyling(canAddEntities: boolean) {
return {
justifyContent: "space-between",
alignItems: "center",
Expand All @@ -356,7 +356,7 @@ function entityRowStyling(isAnalysisMethodsPage: boolean) {
paddingLeft: "0.75rem",
borderBottom: "1.5px solid var(--chakra-colors-palette-gray_lighter)",
"&:last-of-type": {
borderBottom: !isAnalysisMethodsPage && "none",
borderBottom: canAddEntities ?? "none",
},
};
}
Expand Down

0 comments on commit 936bfd3

Please sign in to comment.