diff --git a/shared/src/business/utilities/documentGenerators/trialSessionPlanningReport.ts b/shared/src/business/utilities/documentGenerators/trialSessionPlanningReport.ts index 57192b348ca..49dda1ae977 100644 --- a/shared/src/business/utilities/documentGenerators/trialSessionPlanningReport.ts +++ b/shared/src/business/utilities/documentGenerators/trialSessionPlanningReport.ts @@ -2,7 +2,7 @@ import { DatePrintedFooter } from '@shared/business/utilities/pdfGenerator/compo import { PreviousTerm, TrialLocationData, -} from '@web-api/business/useCases/trialSessions/runTrialSessionPlanningReportInteractor'; +} from '@web-api/business/useCases/trialSessions/getTrialSessionPlanningReportDataInteractor'; import { ReportsMetaHeader } from '@shared/business/utilities/pdfGenerator/components/ReportsMetaHeader'; import { ServerApplicationContext } from '@web-api/applicationContext'; import { TrialSessionPlanningReport } from '@shared/business/utilities/pdfGenerator/documentTemplates/TrialSessionPlanningReport'; diff --git a/web-api/src/business/useCases/trialSessions/runTrialSessionPlanningReportInteractor.ts b/web-api/src/business/useCases/trialSessions/runTrialSessionPlanningReportInteractor.ts index f2d2c7ff746..06e70e1b155 100644 --- a/web-api/src/business/useCases/trialSessions/runTrialSessionPlanningReportInteractor.ts +++ b/web-api/src/business/useCases/trialSessions/runTrialSessionPlanningReportInteractor.ts @@ -2,31 +2,10 @@ import { ROLE_PERMISSIONS, isAuthorized, } from '@shared/authorization/authorizationClientService'; -import { RawTrialSession } from '@shared/business/entities/trialSessions/TrialSession'; -import { - SESSION_TYPES, - TRIAL_CITIES, - US_STATES, -} from '@shared/business/entities/EntityConstants'; import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { capitalize, invert } from 'lodash'; - -export type PreviousTerm = { - term: string; - termDisplay: string; - year: string; -}; - -export type TrialLocationData = { - allCaseCount: number; - previousTermsData: string[][]; - regularCaseCount: number; - smallCaseCount: number; - stateAbbreviation: string; - trialCityState: string; -}; +import { capitalize } from 'lodash'; export const runTrialSessionPlanningReportInteractor = async ( applicationContext: ServerApplicationContext, @@ -40,11 +19,13 @@ export const runTrialSessionPlanningReportInteractor = async ( throw new UnauthorizedError('Unauthorized'); } - const reportData = await getTrialSessionPlanningReportData({ - applicationContext, - term, - year, - }); + const reportData = await applicationContext + .getUseCases() + .getTrialSessionPlanningReportDataInteractor( + applicationContext, + { term, year: Number(year) }, + authorizedUser, + ); const trialSessionPlanningReport = await applicationContext .getDocumentGenerators() @@ -63,155 +44,3 @@ export const runTrialSessionPlanningReportInteractor = async ( useTempBucket: true, }); }; - -const getTrialSessionPlanningReportData = async ({ - applicationContext, - term, - year, -}: { - applicationContext: ServerApplicationContext; - term: string; - year: string; -}): Promise<{ - previousTerms: PreviousTerm[]; - trialLocationData: TrialLocationData[]; -}> => { - const previousTerms: PreviousTerm[] = []; - let currentTerm: string = term; - let currentYear: string = year; - for (let i = 0; i < 3; i++) { - const previous = getPreviousTerm(currentTerm, currentYear); - previousTerms.push(previous); - currentTerm = previous.term; - currentYear = previous.year; - } - - const trialCities = TRIAL_CITIES.ALL.sort((a, b) => { - return applicationContext.getUtilities().compareStrings(a.city, b.city); - }); - - const allTrialSessions = ( - await applicationContext - .getPersistenceGateway() - .getTrialSessions({ applicationContext }) - ).filter(session => - ['Regular', 'Small', 'Hybrid', 'Hybrid-S'].includes(session.sessionType), - ); - - const trialLocationData: TrialLocationData[] = await Promise.all( - trialCities.map(trialLocation => - getTrialLocation(applicationContext, { - allTrialSessions, - previousTerms, - trialLocation, - }), - ), - ); - - return { previousTerms, trialLocationData }; -}; - -const getPreviousTerm = ( - currentTerm: string, - currentYear: string, -): PreviousTerm => { - const terms = [ - `fall ${+currentYear - 1}`, - `winter ${currentYear}`, - `spring ${currentYear}`, - `fall ${currentYear}`, - ]; - const termsReversed = terms.reverse(); - const termI = terms.findIndex(t => `${currentTerm} ${currentYear}` === t); - const [term, year] = termsReversed[termI + 1].split(' '); - - const termDisplay = `${capitalize(term)} ${year}`; - return { - term, - termDisplay, - year, - }; -}; - -const getTrialLocation = async ( - applicationContext: ServerApplicationContext, - { - allTrialSessions, - previousTerms, - trialLocation, - }: { - trialLocation: { city: string; state: string }; - previousTerms: PreviousTerm[]; - allTrialSessions: RawTrialSession[]; - }, -): Promise => { - const trialCityState = `${trialLocation.city}, ${trialLocation.state}`; - const trialCityStateStripped = trialCityState.replace(/[\s.,]/g, ''); - const stateAbbreviation = invert(US_STATES)[trialLocation.state]; - - const eligibleCasesSmall = await applicationContext - .getPersistenceGateway() - .getEligibleCasesForTrialCity({ - applicationContext, - procedureType: 'Small', - trialCity: trialCityStateStripped, - }); - const eligibleCasesRegular = await applicationContext - .getPersistenceGateway() - .getEligibleCasesForTrialCity({ - applicationContext, - procedureType: 'Regular', - trialCity: trialCityStateStripped, - }); - - const smallCaseCount = eligibleCasesSmall.length; - const regularCaseCount = eligibleCasesRegular.length; - const allCaseCount = smallCaseCount + regularCaseCount; - - const previousTermsData: string[][] = []; - previousTerms.forEach(previousTerm => { - const previousTermSessions = allTrialSessions.filter( - trialSession => - trialSession.term.toLowerCase() === previousTerm.term.toLowerCase() && - trialSession.termYear === previousTerm.year && - trialSession.trialLocation === trialCityState, - ); - - previousTermSessions.sort((a, b) => { - return applicationContext - .getUtilities() - .compareISODateStrings(a.startDate, b.startDate); - }); - - const previousTermSessionList: string[] = []; - previousTermSessions.forEach(previousTermSession => { - if ( - previousTermSession && - previousTermSession.sessionType && - previousTermSession.judge - ) { - const sessionTypeChar = - previousTermSession.sessionType === SESSION_TYPES.hybridSmall - ? 'HS' - : previousTermSession.sessionType.charAt(0); - const strippedJudgeName = previousTermSession.judge.name.replace( - 'Judge ', - '', - ); - previousTermSessionList.push( - `(${sessionTypeChar}) ${strippedJudgeName}`, - ); - } - }); - previousTermsData.push(previousTermSessionList); - }); - - return { - allCaseCount, - previousTermsData, - regularCaseCount, - smallCaseCount, - stateAbbreviation, - trialCityState, - }; -}; diff --git a/web-client/src/presenter/actions/TrialSession/runTrialSessionPlanningReportAction.ts b/web-client/src/presenter/actions/TrialSession/runTrialSessionPlanningReportAction.ts index f7fa6d75576..e16475e9550 100644 --- a/web-client/src/presenter/actions/TrialSession/runTrialSessionPlanningReportAction.ts +++ b/web-client/src/presenter/actions/TrialSession/runTrialSessionPlanningReportAction.ts @@ -1,5 +1,3 @@ -import { state } from '@web-client/presenter/app.cerebral'; - /** * get the pdf file and pdf blob url from the passed in htmlString * @param {object} providers the providers object @@ -8,9 +6,9 @@ import { state } from '@web-client/presenter/app.cerebral'; */ export const runTrialSessionPlanningReportAction = async ({ applicationContext, - get, + props, }: ActionProps) => { - const { term, year } = get(state.modal); + const { term, year } = props; const { url } = await applicationContext .getUseCases() diff --git a/web-client/src/presenter/actions/validateTrialSessionPlanningAction.ts b/web-client/src/presenter/actions/validateTrialSessionPlanningAction.ts index 408add2af2d..b2513c7e3dd 100644 --- a/web-client/src/presenter/actions/validateTrialSessionPlanningAction.ts +++ b/web-client/src/presenter/actions/validateTrialSessionPlanningAction.ts @@ -1,5 +1,3 @@ -import { state } from '@web-client/presenter/app.cerebral'; - /** * validate the trial session planning modal * @param {object} providers the providers object @@ -8,10 +6,10 @@ import { state } from '@web-client/presenter/app.cerebral'; * @returns {object} the next path based on if validation was successful or error */ export const validateTrialSessionPlanningAction = ({ - get, path, -}: ActionProps) => { - const { term, year } = get(state.modal); + props, +}: ActionProps<{ term: string; year: number }>) => { + const { term, year } = props; let errors = null; if (!term || !year) { diff --git a/web-client/src/presenter/computeds/trialSessionPlanningReportViewHelper.ts b/web-client/src/presenter/computeds/trialSessionPlanningReportViewHelper.ts index 0c5f90c864e..8ee76cfb3ba 100644 --- a/web-client/src/presenter/computeds/trialSessionPlanningReportViewHelper.ts +++ b/web-client/src/presenter/computeds/trialSessionPlanningReportViewHelper.ts @@ -13,8 +13,10 @@ export type TrialLocationDataFormatted = TrialLocationData & { type TrialSessionPlanningReportViewHelperResults = { citiesNotCalendaredInTwoPreviousTerms: string[][]; trialSessionPlanningReportHeader: string; - previousTermsFormatted: { termDisplayFormatted }[]; + previousTermsFormatted: { termDisplayFormatted: string }[]; trialLocationDataFormatted: TrialLocationDataFormatted[]; + trialTerm: string; + trialYear: number; }; function formatCities(allCities: string[]): string[][] { @@ -95,8 +97,11 @@ export const trialSessionPlanningReportViewHelper = ( previousTermsFormatted, trialLocationDataFormatted, trialSessionPlanningReportHeader, + trialTerm, + trialYear, }; }; + function formatLastVisitedDate(lastVisitedDate: string | undefined): string { if (!lastVisitedDate) return 'Never visited.'; const formattedSessionWeekStartDate = createDateAtStartOfWeekEST( diff --git a/web-client/src/presenter/presenter.ts b/web-client/src/presenter/presenter.ts index 9cc75457819..e6da1efa824 100644 --- a/web-client/src/presenter/presenter.ts +++ b/web-client/src/presenter/presenter.ts @@ -1194,8 +1194,7 @@ export const presenterSequences = { reviewCaseAssociationRequestSequence as unknown as Function, reviewExternalDocumentInformationSequence: reviewExternalDocumentInformationSequence as unknown as Function, - runTrialSessionPlanningReportSequence: - runTrialSessionPlanningReportSequence as unknown as Function, + runTrialSessionPlanningReportSequence, saveCourtIssuedDocketEntrySequence: saveCourtIssuedDocketEntrySequence as unknown as Function, saveDocketEntryForLaterCompleteSequence: diff --git a/web-client/src/presenter/sequences/runTrialSessionPlanningReportSequence.ts b/web-client/src/presenter/sequences/runTrialSessionPlanningReportSequence.ts index b3174af481a..ba9208caebf 100644 --- a/web-client/src/presenter/sequences/runTrialSessionPlanningReportSequence.ts +++ b/web-client/src/presenter/sequences/runTrialSessionPlanningReportSequence.ts @@ -21,4 +21,4 @@ export const runTrialSessionPlanningReportSequence = [ navigateToTrialSessionPlanningReportAction, ]), }, -]; +] as unknown as (props: { term: string; year: number }) => void; diff --git a/web-client/src/views/TrialSessions/TrialSessionPlanningReportView.tsx b/web-client/src/views/TrialSessions/TrialSessionPlanningReportView.tsx index 223137c91e4..c94cfa7e94d 100644 --- a/web-client/src/views/TrialSessions/TrialSessionPlanningReportView.tsx +++ b/web-client/src/views/TrialSessions/TrialSessionPlanningReportView.tsx @@ -2,18 +2,22 @@ import { BigHeader } from '@web-client/views/BigHeader'; import { Button } from '@web-client/ustc-ui/Button/Button'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { TrialLocationDataFormatted } from '@web-client/presenter/computeds/trialSessionPlanningReportViewHelper'; -import { state as cerebralState } from '@web-client/presenter/app.cerebral'; +import { + state as cerebralState, + sequences, +} from '@web-client/presenter/app.cerebral'; import { connect } from '@web-client/presenter/shared.cerebral'; import React from 'react'; export const TrialSessionPlanningReportView = connect( { - trialSessionPlanningReportData: - cerebralState.trialSessionPlanningReportData, + runTrialSessionPlanningReportSequence: + sequences.runTrialSessionPlanningReportSequence, trialSessionPlanningReportViewHelper: cerebralState.trialSessionPlanningReportViewHelper, }, function TrialSessionPlanningReportView({ + runTrialSessionPlanningReportSequence, trialSessionPlanningReportViewHelper, }) { const { @@ -35,7 +39,10 @@ export const TrialSessionPlanningReportView = connect( @@ -79,8 +92,13 @@ function TrialSessionPlanningReportHeader({ @@ -91,7 +109,7 @@ function TrialSessionPlanningReportHeader({ type TrialSessionPlanningReportTableParams = { locationData: TrialLocationDataFormatted[]; - previousTerms: { termDisplayFormatted }[]; + previousTerms: { termDisplayFormatted: string }[]; }; function TrialSessionPlanningReportTable({ @@ -108,8 +126,12 @@ function TrialSessionPlanningReportTable({ All Small Regular - {previousTerms.map((term, index) => { - return {term.termDisplayFormatted}; + {previousTerms.map(term => { + return ( + + {term.termDisplayFormatted} + + ); })} Special Blocked @@ -117,13 +139,13 @@ function TrialSessionPlanningReportTable({ {locationData && - locationData.map((trialLocation, idx) => { + locationData.map(trialLocation => { return ( {trialLocation.hasNotBeenCalendared && ( @@ -139,27 +161,32 @@ function TrialSessionPlanningReportTable({ {trialLocation.allCaseCount} {trialLocation.smallCaseCount} {trialLocation.regularCaseCount} - {trialLocation.previousTermsData && - trialLocation.previousTermsData.map((prevTerm, index) => { - const hasData = - Array.isArray(prevTerm) && prevTerm.length > 0; + {trialLocation.previousTermsData.map(prevTerm => { + const hasData = + Array.isArray(prevTerm) && prevTerm.length > 0; - return ( - - {hasData ? ( - prevTerm.map(data => ( -
{data}
- )) - ) : ( - - )} - - ); - })} + return ( + + {hasData ? ( + prevTerm.map(data => ( +
+ {data} +
+ )) + ) : ( + + )} + + ); + })} {trialLocation.specialCaseCount} {trialLocation.blockedCaseCount}