Skip to content

Commit

Permalink
devex-organize-docket-sorting: begin to untangle some messiness with …
Browse files Browse the repository at this point in the history
…state
  • Loading branch information
Mwindo committed Dec 9, 2024
1 parent 6400aed commit e41851b
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 65 deletions.
3 changes: 3 additions & 0 deletions __TODO_devex_docket_number_sorting.md.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Make DocketRecordSortInfo more agnostic (we can use this for anywhere we sort any field)
- Figure out how update old docketRecordSort, which I have slowly been doing
- Figure out how to avoid the different sorts we currently have going on as a result of docket number table sorting, which I started to do in generateDocketRecordPdfProxy (we were sorting the docket entries multiple times unnecessarily). It looks like we are passing along docketRecordSort and docketRecordTableSort, sometimes using one and sometimes the other (in fact, the latter was overwriting whatever we did in the former in generateDocketRecordPdfProxy). This is a code smell.
11 changes: 6 additions & 5 deletions shared/src/business/utilities/getFormattedCaseDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { Case, isSealedCase } from '../entities/cases/Case';
import {
DOCKET_ENTRY_SORT_FIELDS,
DocketEntrySortField,
DocketRecordSortInfo,
sortDocketEntries,
} from '@shared/business/utilities/sorting/docketEntrySorting';
import { DocketEntry } from '../entities/DocketEntry';
Expand Down Expand Up @@ -435,11 +435,11 @@ export const getFormattedCaseDetail = ({
applicationContext,
authorizedUser,
caseDetail,
docketRecordSort: docketEntryFieldToSortBy,
docketRecordSortInfo,
}: {
applicationContext: IApplicationContext;
caseDetail: RawCase;
docketRecordSort?: DocketEntrySortField;
docketRecordSortInfo?: DocketRecordSortInfo;
authorizedUser: UnknownAuthUser;
}) => {
const result = {
Expand All @@ -449,10 +449,11 @@ export const getFormattedCaseDetail = ({
...formatCase(applicationContext, caseDetail, authorizedUser),
};
result.formattedDocketEntries = sortDocketEntries({
ascending: docketRecordSortInfo?.ascending,
docketEntries: result.formattedDocketEntries,
sortByField: docketEntryFieldToSortBy,
sortByField: docketRecordSortInfo?.sortByField,
});
result.docketRecordSort = docketEntryFieldToSortBy;
result.docketRecordSortInfo = docketRecordSortInfo;

return result;
};
5 changes: 5 additions & 0 deletions shared/src/business/utilities/sorting/docketEntrySorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const DOCKET_ENTRY_SORT_FIELDS = {
export type DocketEntrySortField =
(typeof DOCKET_ENTRY_SORT_FIELDS)[keyof typeof DOCKET_ENTRY_SORT_FIELDS];

export type DocketRecordSortInfo = {
sortByField: DocketEntrySortField;
ascending: boolean;
};

type Comparator<T> = (a: T, b: T) => number;

type SortableDocketEntry = RawDocketEntry & { createdAtFormatted?: string };
Expand Down
6 changes: 2 additions & 4 deletions shared/src/proxies/generateDocketRecordPdfProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export const generateDocketRecordPdfInteractor = (
applicationContext,
{
docketNumber,
docketRecordSort,
docketRecordTableSort,
docketRecordSortInfo,
includePartyDetail,
isIndirectlyAssociated,
},
Expand All @@ -22,8 +21,7 @@ export const generateDocketRecordPdfInteractor = (
applicationContext,
body: {
docketNumber,
docketRecordSort,
docketRecordTableSort,
docketRecordSortInfo,
includePartyDetail,
isIndirectlyAssociated,
},
Expand Down
36 changes: 15 additions & 21 deletions web-api/src/business/useCases/generateDocketRecordPdfInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Case,
getPractitionersRepresenting,
} from '../../../../shared/src/business/entities/cases/Case';
import { DocketRecordSortInfo } from '@shared/business/utilities/sorting/docketEntrySorting';
import {
ROLE_PERMISSIONS,
isAuthorized,
Expand All @@ -10,32 +11,33 @@ import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { getCaseCaptionMeta } from '../../../../shared/src/business/utilities/getCaseCaptionMeta';
import { sortDocketEntryTable } from '@web-client/presenter/computeds/formattedDocketEntries';

export const generateDocketRecordPdfInteractor = async (
applicationContext: ServerApplicationContext,
{
docketNumber,
docketRecordSort,
docketRecordTableSort,
docketRecordSortInfo,
includePartyDetail = false,
isIndirectlyAssociated = false,
}: {
docketNumber: string;
docketRecordSort?: string;
docketRecordTableSort?: { sortField: string; sortOrder: 'asc' | 'desc' };
docketRecordSortInfo?: DocketRecordSortInfo;
includePartyDetail: boolean;
isIndirectlyAssociated?: boolean;
},
authorizedUser: UnknownAuthUser,
) => {
const isDirectlyAssociated = await applicationContext
.getPersistenceGateway()
.verifyCaseForUser({
applicationContext,
docketNumber,
userId: authorizedUser?.userId,
});
let isDirectlyAssociated = false;

if (authorizedUser?.userId) {
isDirectlyAssociated = await applicationContext
.getPersistenceGateway()
.verifyCaseForUser({
applicationContext,
docketNumber,
userId: authorizedUser?.userId,
});
}

const caseSource = await applicationContext
.getPersistenceGateway()
Expand Down Expand Up @@ -80,7 +82,7 @@ export const generateDocketRecordPdfInteractor = async (
applicationContext,
authorizedUser,
caseDetail: caseEntity,
docketRecordSort,
docketRecordSortInfo,
});

formattedCaseDetail.formattedDocketEntries =
Expand All @@ -89,14 +91,6 @@ export const generateDocketRecordPdfInteractor = async (
numberOfPages: docketEntry.numberOfPages || 0,
}));

const sortedDocketEntries = sortDocketEntryTable(
formattedCaseDetail.formattedDocketEntries,
docketRecordTableSort && docketRecordTableSort.sortField,
docketRecordTableSort && docketRecordTableSort.sortOrder,
);

formattedCaseDetail.formattedDocketEntries = sortedDocketEntries;

formattedCaseDetail.petitioners.forEach(petitioner => {
petitioner.counselDetails = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('setDefaultDocketRecordSortAction', () => {
},
});

expect(result.state.sessionMetadata.docketRecordSort['123-45']).toEqual(
'something',
);
expect(
result.state.sessionMetadata.docketRecordSortInfoByDocketNumber['123-45'],
).toEqual('something');
});

it('should default docketRecordSort if current docketNumber does not match sessionMetadata docketNumber', async () => {
Expand All @@ -23,8 +23,8 @@ describe('setDefaultDocketRecordSortAction', () => {
},
});

expect(result.state.sessionMetadata.docketRecordSort['987-65']).toEqual(
'byDate',
);
expect(
result.state.sessionMetadata.docketRecordSortInfoByDocketNumber['987-65'],
).toEqual('byDate');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export const setDefaultDocketRecordSortAction = ({
store,
}: ActionProps) => {
const docketNumber = get(state.caseDetail.docketNumber);
const hasSort = get(state.sessionMetadata.docketRecordSort[docketNumber]);
const hasSort = get(
state.sessionMetadata.docketRecordSortInfoByDocketNumber[docketNumber],
);

if (!hasSort) {
store.set(state.sessionMetadata.docketRecordSort[docketNumber], 'byDate');
store.set(
state.sessionMetadata.docketRecordSortInfoByDocketNumber[docketNumber],
'byDate',
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('toggleMobileDocketSortAction', () => {
},
});

expect(result.state.sessionMetadata.docketRecordSort['987-65']).toEqual(
'byDateDesc',
);
expect(
result.state.sessionMetadata.docketRecordSortInfoByDocketNumber['987-65'],
).toEqual('byDateDesc');
});

it('should set sessionMetadata.docketRecordSort to byDate if it is currently byDateDesc', async () => {
Expand All @@ -23,8 +23,8 @@ describe('toggleMobileDocketSortAction', () => {
},
});

expect(result.state.sessionMetadata.docketRecordSort['987-65']).toEqual(
'byDate',
);
expect(
result.state.sessionMetadata.docketRecordSortInfoByDocketNumber['987-65'],
).toEqual('byDate');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { state } from '@web-client/presenter/app.cerebral';
*/
export const toggleMobileDocketSortAction = ({ get, store }: ActionProps) => {
const docketNumber = get(state.caseDetail.docketNumber);
const currentSort = get(state.sessionMetadata.docketRecordSort[docketNumber]);
const currentSort = get(
state.sessionMetadata.docketRecordSortInfoByDocketNumber[docketNumber],
);
let newSort;
switch (currentSort) {
case 'byDate':
Expand All @@ -20,5 +22,8 @@ export const toggleMobileDocketSortAction = ({ get, store }: ActionProps) => {
newSort = 'byDate';
break;
}
store.set(state.sessionMetadata.docketRecordSort[docketNumber], newSort);
store.set(
state.sessionMetadata.docketRecordSortInfoByDocketNumber[docketNumber],
newSort,
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STATE_KEYS } from '@shared/business/entities/EntityConstants';
import { DocketRecordSortInfo } from '@shared/business/utilities/sorting/docketEntrySorting';
import { state } from '@web-client/presenter/app.cerebral';
/**
* get the pdf file and pdf blob url from the passed in htmlString
Expand All @@ -13,15 +13,10 @@ export const generateDocketRecordPdfUrlAction = async ({
props,
}: ActionProps) => {
const caseDetail = get(state.caseDetail);
const docketRecordSort = get(
state.sessionMetadata.docketRecordSort[caseDetail.docketNumber],
);

const docketRecordSortField = get(
state[STATE_KEYS.DOCKET_RECORD_TABLE_SORT].sortField,
);
const docketRecordSortOrder = get(
state[STATE_KEYS.DOCKET_RECORD_TABLE_SORT].sortOrder,
const docketRecordSortInfo: DocketRecordSortInfo = get(
state.sessionMetadata.docketRecordSortInfoByDocketNumber[
caseDetail.docketNumber
],
);

const { isAssociated } = props;
Expand All @@ -37,11 +32,7 @@ export const generateDocketRecordPdfUrlAction = async ({
.getUseCases()
.generateDocketRecordPdfInteractor(applicationContext, {
docketNumber: caseDetail.docketNumber,
docketRecordSort,
docketRecordTableSort: {
sortField: docketRecordSortField,
sortOrder: docketRecordSortOrder,
},
docketRecordSortInfo,
includePartyDetail,
isIndirectlyAssociated,
});
Expand Down
5 changes: 4 additions & 1 deletion web-client/src/presenter/computeds/docketRecordHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export const docketRecordHelper = (
sortLabelTextMobile: string;
} => {
const permissions = get(state.permissions);
const { docketRecordFilter, docketRecordSort } = get(state.sessionMetadata);
const {
docketRecordFilter,
docketRecordSortInfoByDocketNumber: docketRecordSort,
} = get(state.sessionMetadata);
const {
canAllowPrintableDocketRecord: showPrintableDocketRecord,
docketEntries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const formattedDocketEntries = (
const { formatCase } = applicationContext.getUtilities();
if (docketNumber) {
docketRecordSort = get(
state.sessionMetadata.docketRecordSort[docketNumber],
state.sessionMetadata.docketRecordSortInfoByDocketNumber[docketNumber],
);
}

Expand Down
6 changes: 5 additions & 1 deletion web-client/src/presenter/state-public.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocketRecordSortInfo } from '@shared/business/utilities/sorting/docketEntrySorting';
import {
PUBLIC_DOCKET_RECORD_FILTER_OPTIONS,
PUBLIC_TRIAL_SESSIONS_DATA_KEY,
Expand Down Expand Up @@ -95,7 +96,10 @@ export const baseState = {
},
sessionMetadata: {
docketRecordFilter: PUBLIC_DOCKET_RECORD_FILTER_OPTIONS.allDocuments,
docketRecordSort: {},
docketRecordSortInfoByDocketNumber: [] as Record<
string,
DocketRecordSortInfo
>[],
todaysOrdersSort: '',
},
showPassword: false,
Expand Down
6 changes: 5 additions & 1 deletion web-client/src/presenter/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable max-lines */
import { Contact } from '@shared/business/useCases/generatePetitionPdfInteractor';
import { DocketRecordSortInfo } from '@shared/business/utilities/sorting/docketEntrySorting';
import { FormattedPendingMotionWithWorksheet } from '@web-api/business/useCases/pendingMotion/getPendingMotionDocketEntriesForCurrentJudgeInteractor';
import { GetCasesByStatusAndByJudgeResponse } from '@web-api/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor';
import {
Expand Down Expand Up @@ -824,7 +825,10 @@ export const baseState = {
selectedWorkItems: [],
sessionMetadata: {
docketRecordFilter: DOCKET_RECORD_FILTER_OPTIONS.allDocuments,
docketRecordSort: [],
docketRecordSortInfoByDocketNumber: [] as Record<
string,
DocketRecordSortInfo
>[],
todaysOrdersSort: [],
},
setSelectedConsolidatedCasesToMultiDocketOn: false,
Expand Down

0 comments on commit e41851b

Please sign in to comment.