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(details): Add additional fields to SEATool transform; Display in UI #266

Merged
merged 18 commits into from
Dec 19, 2023
50 changes: 36 additions & 14 deletions src/packages/shared-types/seatool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ const getRaiDate = (data: SeaToolSink) => {
};
};

const zActionOfficer = z.object({
OFFICER_ID: z.number(),
FIRST_NAME: z.string(),
LAST_NAME: z.string(),
});
type ActionOfficer = z.infer<typeof zActionOfficer>;

export const seatoolSchema = z.object({
LEAD_ANALYST: z
.array(
z.object({
OFFICER_ID: z.number(),
FIRST_NAME: z.string(),
LAST_NAME: z.string(),
})
)
.nullable(),
ACTION_OFFICERS: z.array(zActionOfficer).nullish(),
LEAD_ANALYST: z.array(zActionOfficer).nullable(),
PLAN_TYPES: z
.array(
z.object({
Expand All @@ -102,6 +102,9 @@ export const seatoolSchema = z.object({
PROPOSED_DATE: z.number().nullable(),
SPW_STATUS_ID: z.number().nullable(),
STATE_CODE: z.string().nullish(),
STATUS_DATE: z.number().nullish(),
SUMMARY_MEMO: z.string().nullish(),
TITLE_NAME: z.string().nullish(),
}),
SPW_STATUS: z
.array(
Expand Down Expand Up @@ -131,11 +134,25 @@ export const seatoolSchema = z.object({
.nullable(),
});

const getDateStringOrNullFromEpoc = (epocDate: number | null) => {
if (epocDate !== null) {
return new Date(epocDate).toISOString();
}
return null;
const getDateStringOrNullFromEpoc = (epocDate: number | null | undefined) =>
epocDate !== null && epocDate !== undefined
? new Date(epocDate).toISOString()
: null;

const compileSrtList = (
officers: ActionOfficer[] | null | undefined
): string[] =>
officers?.length ? officers.map((o) => `${o.FIRST_NAME} ${o.LAST_NAME}`) : [];

const getFinalDispositionDate = (status: string, record: SeaToolSink) => {
const finalDispositionStatuses = [
SEATOOL_STATUS.APPROVED,
SEATOOL_STATUS.DISAPPROVED,
SEATOOL_STATUS.WITHDRAWN,
];
return status && finalDispositionStatuses.includes(status)
? getDateStringOrNullFromEpoc(record.STATE_PLAN.STATUS_DATE)
: null;
};

export const transformSeatoolData = (id: string) => {
Expand Down Expand Up @@ -178,6 +195,8 @@ export const transformSeatoolData = (id: string) => {
),
authority: authorityLookup(data.STATE_PLAN.PLAN_TYPE),
changedDate: getDateStringOrNullFromEpoc(data.STATE_PLAN.CHANGED_DATE),
description: data.STATE_PLAN.SUMMARY_MEMO,
finalDispositionDate: getFinalDispositionDate(seatoolStatus, data),
leadAnalystOfficerId,
leadAnalystName,
planType: data.PLAN_TYPES?.[0].PLAN_TYPE_NAME,
Expand All @@ -187,13 +206,16 @@ export const transformSeatoolData = (id: string) => {
raiRequestedDate,
raiWithdrawnDate,
rais,
reviewTeam: compileSrtList(data.ACTION_OFFICERS),
state: data.STATE_PLAN.STATE_CODE,
stateStatus: stateStatus || SEATOOL_STATUS.UNKNOWN,
statusDate: getDateStringOrNullFromEpoc(data.STATE_PLAN.STATUS_DATE),
cmsStatus: cmsStatus || SEATOOL_STATUS.UNKNOWN,
seatoolStatus,
submissionDate: getDateStringOrNullFromEpoc(
data.STATE_PLAN.SUBMISSION_DATE
),
subject: data.STATE_PLAN.TITLE_NAME,
};
});
};
Expand Down
5 changes: 5 additions & 0 deletions src/services/data/handlers/sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
const seaToolRecords: (SeaToolTransform | SeaToolRecordsToDelete)[] = [];
const docObject: Record<string, SeaToolTransform | SeaToolRecordsToDelete> =
{};
const rawArr: any[] = [];

Check warning on line 36 in src/services/data/handlers/sink.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

for (const recordKey of Object.keys(event.records)) {
for (const seatoolRecord of event.records[recordKey] as {
Expand Down Expand Up @@ -73,6 +73,8 @@
approvedEffectiveDate: null,
authority: null,
changedDate: null,
description: null,
finalDispositionDate: null,
leadAnalystName: null,
leadAnalystOfficerId: null,
planType: null,
Expand All @@ -81,11 +83,14 @@
raiReceivedDate: null,
raiRequestedDate: null,
raiWithdrawnDate: null,
reviewTeam: null,
state: null,
cmsStatus: null,
stateStatus: null,
seatoolStatus: null,
statusDate: null,
submissionDate: null,
subject: null,
};

docObject[id] = seaTombstone;
Expand Down

This file was deleted.

25 changes: 25 additions & 0 deletions src/services/ui/src/components/PackageDetails/DetailItemsGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useGetUser } from "@/api/useGetUser";
import { DetailSectionItem } from "@/pages/detail/setup/spa";

export const DetailItemsGrid = ({
displayItems,
}: {
displayItems: DetailSectionItem[];
}) => {
const { data: user } = useGetUser();
return (
<>
<div className="grid grid-cols-2 gap-4">
{displayItems.map(({ label, value, canView }) => {
return !canView(user) ? null : (
<div key={label}>
<h3 className="text-sm">{label}</h3>
{value}
</div>
);
})}
</div>
<hr className="my-4" />
</>
);
};
26 changes: 26 additions & 0 deletions src/services/ui/src/components/PackageDetails/ReviewTeamList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useMemo, useState } from "react";
import { BLANK_VALUE } from "@/consts";

export const ReviewTeamList = ({ team }: { team: string[] | undefined }) => {
const [expanded, setExpanded] = useState(false);
const displayTeam = useMemo(
() => (expanded ? team : team?.slice(0, 3)),
[expanded, team]
);
return !displayTeam || !displayTeam.length ? (
BLANK_VALUE
) : (
<ul>
{displayTeam.map((reviewer, idx) => (
<li key={`reviewteam-ul-${reviewer}-${idx}`}>{reviewer}</li>
))}
{team && team?.length > 3 && (
<li className={"text-xs text-sky-600 hover:cursor-pointer"}>
<button onClick={() => setExpanded((prev) => !prev)}>
{expanded ? "Show less" : "Show more"}
</button>
</li>
)}
</ul>
);
};
3 changes: 2 additions & 1 deletion src/services/ui/src/components/PackageDetails/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./ChipSpaPackageDetails";
export * from "./DetailItemsGrid";
export * from "./ReviewTeamList";
46 changes: 0 additions & 46 deletions src/services/ui/src/components/SubmissionInfo/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/services/ui/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export * from "./LoadingSpinner";
export * from "./PackageDetails";
export * from "./RaiList";
export * from "./SearchForm";
export * from "./SubmissionInfo";
export * from "./Modal";
export * from "./Dialog";
export * from "./Modal/ConfirmationModal";
Expand Down
11 changes: 5 additions & 6 deletions src/services/ui/src/pages/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {
Alert,
Attachmentslist,
CardWithTopBorder,
ChipSpaPackageDetails,
DetailsSection,
ErrorAlert,
LoadingSpinner,
RaiList,
SubmissionInfo,
ConfirmationModal,
} from "@/components";
import { useGetUser } from "@/api/useGetUser";
Expand All @@ -28,6 +26,8 @@ import { useGetPackageActions } from "@/api/useGetPackageActions";
import { PropsWithChildren, useState } from "react";
import { DETAILS_AND_ACTIONS_CRUMBS } from "@/pages/actions/actions-breadcrumbs";
import { API } from "aws-amplify";
import { DetailItemsGrid } from "@/components";
import { spaDetails, submissionDetails } from "@/pages/detail/setup/spa";

const DetailCardWrapper = ({
title,
Expand Down Expand Up @@ -199,10 +199,9 @@ export const DetailsContent = ({ data }: { data?: ItemResult }) => {
/>
<PackageActionsCard id={data._id} />
</section>
<DetailsSection id="package-details" title="Package Details">
<ChipSpaPackageDetails {...data?._source} />
</DetailsSection>
<SubmissionInfo {...data?._source} />
<h2 className="text-xl font-semibold mb-2">{"Package Details"}</h2>
<DetailItemsGrid displayItems={spaDetails(data._source)} />
<DetailItemsGrid displayItems={submissionDetails(data._source)} />
{/* Below is used for spacing. Keep it simple */}
<div className="mb-4" />
<DetailsSection id="attachments" title="Attachments">
Expand Down
Loading
Loading