Skip to content

Commit

Permalink
10293: format items for pending report when setting to state instead …
Browse files Browse the repository at this point in the history
…of in computed
  • Loading branch information
akuny committed Dec 5, 2024
1 parent 9bc1810 commit c99874c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 69 deletions.
2 changes: 1 addition & 1 deletion shared/src/business/utilities/formatPendingItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type PendingItemFormatted = {

export const formatPendingItem = (
item: PendingItem,
{ applicationContext }: { applicationContext: IApplicationContext },
{ applicationContext },
): PendingItemFormatted => {
const pendingItemWithConsolidatedFlags = applicationContext
.getUtilities()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ import { PendingItem } from '@web-api/business/useCases/pendingItems/fetchPendin
import { state } from '@web-client/presenter/app.cerebral';

export const setPendingItemsAction = ({
applicationContext,

props,
store,
}: ActionProps<{ pendingItems: PendingItem[] }>) => {
const { pendingItems } = props;
store.set(state.pendingReports.pendingItems, pendingItems);
store.set(state.pendingReports.hasPendingItemsResults, !!pendingItems.length);
store.set(state.pendingReports.pendingItemsTotal, pendingItems.length);
const formattedPendingItems = pendingItems.map(item =>
applicationContext
.getUtilities()
.formatPendingItem(item, { applicationContext }),
);

store.set(state.pendingReports.pendingItems, formattedPendingItems);
store.set(
state.pendingReports.hasPendingItemsResults,
!!formattedPendingItems.length,
);
store.set(
state.pendingReports.pendingItemsTotal,
formattedPendingItems.length,
);
};
54 changes: 3 additions & 51 deletions web-client/src/presenter/computeds/formattedPendingItems.test.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
import {
PendingReports,
initialPendingReportsState,
} from '@web-client/presenter/state/pendingReportState';
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
import { cloneDeep } from 'lodash';
import { formattedPendingItemsHelper as formattedPendingItemsComputed } from './formattedPendingItems';
import { initialPendingReportsState } from '@web-client/presenter/state/pendingReportState';
import { runCompute } from '@web-client/presenter/test.cerebral';
import { withAppContextDecorator } from '../../withAppContext';

describe('formattedPendingItems', () => {
const { CHIEF_JUDGE, DOCKET_NUMBER_SUFFIXES, STATUS_TYPES } =
applicationContext.getConstants();
const { CHIEF_JUDGE } = applicationContext.getConstants();

const formattedPendingItems = withAppContextDecorator(
formattedPendingItemsComputed,
);

let mockPendingItems;

let pendingReportsState: PendingReports;
beforeEach(() => {
mockPendingItems = [
{
associatedJudge: CHIEF_JUDGE,
caseStatus: STATUS_TYPES.new,
createdAt: '2019-01-10',
docketEntryId: '33ddbf4f-90f8-417c-8967-57851b0b9069',
docketNumber: '101-19',
docketNumberSuffix: DOCKET_NUMBER_SUFFIXES.WHISTLEBLOWER,
documentType: 'Administrative Record',
eventCode: 'ADMR',
receivedAt: '2019-01-10',
},
{
associatedJudge: CHIEF_JUDGE,
caseStatus: STATUS_TYPES.new,
createdAt: '2018-01-20',
docketEntryId: 'dd956ab1-5cde-4e78-bae0-fff4aee40426',
docketNumber: '101-19',
docketNumberSuffix: DOCKET_NUMBER_SUFFIXES.WHISTLEBLOWER,
documentTitle: 'Affidavit of Sally in Support of Petition',
documentType: 'Affidavit in Support',
eventCode: 'AFF',
receivedAt: '2018-01-20',
},
{
associatedJudge: 'Judge A',
caseStatus: STATUS_TYPES.new,
createdAt: '2018-01-20',
docketEntryId: 'dd956ab1-5cde-4e78-bae0-ac7faee40426',
docketNumber: '103-19',
docketNumberSuffix: DOCKET_NUMBER_SUFFIXES.WHISTLEBLOWER,
documentTitle: 'Affidavit of Bob in Support of Petition',
documentType: 'Affidavit in Support',
eventCode: 'AFF',
receivedAt: '2018-01-20',
},
];

pendingReportsState = cloneDeep(initialPendingReportsState);
pendingReportsState.pendingItems = mockPendingItems;
});
const pendingReportsState = cloneDeep(initialPendingReportsState);

it('should return formatted and sorted list of judges', () => {
const result = runCompute(formattedPendingItems, {
Expand Down
8 changes: 0 additions & 8 deletions web-client/src/presenter/computeds/formattedPendingItems.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Get } from 'cerebral';
import { PendingItemFormatted } from '@shared/business/utilities/formatPendingItem';
import { state } from '@web-client/presenter/app.cerebral';
import qs from 'qs';

Expand All @@ -9,15 +8,9 @@ export const formattedPendingItemsHelper = (
): {
printUrl: string;
judges: string[];
items: PendingItemFormatted[];
} => {
const { CHIEF_JUDGE } = applicationContext.getConstants();

const items = get(state.pendingReports.pendingItems).map(item =>
applicationContext
.getUtilities()
.formatPendingItem(item, { applicationContext }),
);
const judgeFilter = get(state.screenMetadata.pendingItemsFilters.judge);
const judges = get(state.judges)
.map(i => applicationContext.getUtilities().formatJudgeName(i.name))
Expand All @@ -27,7 +20,6 @@ export const formattedPendingItemsHelper = (
const queryString = qs.stringify({ judgeFilter });

return {
items,
judges,
printUrl: `/reports/pending-report/printable?${queryString}`,
};
Expand Down
4 changes: 2 additions & 2 deletions web-client/src/presenter/state/pendingReportState.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PendingItem } from '@web-api/business/useCases/pendingItems/fetchPendingItemsInteractor';
import { PendingItemFormatted } from '@shared/business/utilities/formatPendingItem';

export type PendingReports = {
pendingItemsTotal: number;
hasPendingItemsResults: boolean;
pendingItems: PendingItem[];
pendingItems: PendingItemFormatted[];
selectedJudge: string;
};

Expand Down
7 changes: 3 additions & 4 deletions web-client/src/views/PendingReport/PendingReportList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const PendingReportList = connect(
{
formattedPendingItemsHelper: state.formattedPendingItemsHelper,
hasPendingItemsResults: state.pendingReports.hasPendingItemsResults,
pendingItems: state.pendingReports.pendingItems,
pendingItemsTotal: state.pendingReports.pendingItemsTotal,
pendingReportListHelper: state.pendingReportListHelper,
setPendingReportSelectedJudgeSequence:
Expand All @@ -22,17 +23,15 @@ export const PendingReportList = connect(
function PendingReportList({
formattedPendingItemsHelper,
hasPendingItemsResults,
pendingItems,
pendingItemsTotal,
pendingReportListHelper,
setPendingReportSelectedJudgeSequence,
}) {
const paginatorTop = useRef(null);

const { activePage, pageRecords, setActivePage, totalPages } =
useClientSidePaginator(
formattedPendingItemsHelper.items,
PENDING_REPORT_PAGE_SIZE,
);
useClientSidePaginator(pendingItems, PENDING_REPORT_PAGE_SIZE);

return (
<>
Expand Down

0 comments on commit c99874c

Please sign in to comment.