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

10409 story rebased #5386

Draft
wants to merge 59 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e3e2618
10409: Add new styling for trial sessions. Extract filters to its own…
Aug 30, 2024
482d62f
10409: Split out state for trialsessionPage into its own page container.
Aug 30, 2024
72f0b08
10409: Delete comment
Aug 30, 2024
f9f1b7e
10409: Wire up filters to state.
Sep 2, 2024
1dc609c
10409: Move filtering and formatting of trialSessions to helper inste…
Sep 2, 2024
7e6ee33
10409: Add sorting
Sep 3, 2024
3a7709f
10409: Add blue rows to display session weeks
Sep 3, 2024
aa34374
10409: organize functions
Sep 3, 2024
c77edcc
10409: Update Default state of filters
Sep 3, 2024
3b49cd6
10409 fix radio buttons
Sep 3, 2024
16580d6
10409 fix setTrialSessionsFiltersActions test
JayFlexy Sep 4, 2024
a52ecfd
10409: fix some tests, wip still figuring out purpose
JayFlexy Sep 5, 2024
df63edd
10409 fix trialSessionsHelper.test.ts tests
JayFlexy Sep 5, 2024
de7c984
10409 add some tests for new table functionality
JayFlexy Sep 5, 2024
a6218f8
10409: Remove unused
Sep 5, 2024
fba1672
10409: Add tests for filtering trial sessions
Sep 5, 2024
1d781c6
10409: Move trial sessions filtering tests over to trialSessionsHelper
Sep 5, 2024
30579c3
10409: Add filtering for unassigned judges
Sep 5, 2024
e0396e5
10409 fix proceedingtype filter test
JayFlexy Sep 9, 2024
18c9db7
10409 fix type errors
JayFlexy Sep 9, 2024
916da58
10409: Update swing session calculation to decouple from trialsession…
Sep 9, 2024
adc8b4f
10409: Update swing session helper. fix sorting
Sep 9, 2024
1d76550
10409: Remove formattedTrialSessions and split into trialSessionsPage…
Sep 9, 2024
225f53f
10409: Update integration tests to reflect new trial sessions page state
Sep 9, 2024
ff9b48a
10409: Update integration tests to reflect new trial sessions page state
Sep 9, 2024
42828f4
10409: Update integration tests to reflect new trial sessions page state
Sep 10, 2024
2d14442
10409: Update integration tests to reflect new trial sessions page state
Sep 10, 2024
75858d8
10409: Remove validation before returning trial sessions.
Sep 10, 2024
3536f6d
10409: Make a new trialSession before turning into DTO so the NOTT ca…
Sep 10, 2024
eda57a0
10409 calculate isStartDateWithinNOTTReminderRange
Sep 10, 2024
1475961
10409 calculate thirtyDaysBeforeTrialFormatted instead of storing on …
Sep 10, 2024
6fd73e3
10409 always route the user to the new tab once they have created a t…
Sep 11, 2024
4f289cd
10409 add query params back when navigating to trial sessions
Sep 11, 2024
79c56e9
10409 look at calendared trial sessions after making one
Sep 11, 2024
1f863f3
10409: Reset state when a user signs out. Only show inactive judges o…
Sep 12, 2024
80c2791
10409: Update text
Sep 12, 2024
79b89f7
10409: Remove reset to base state
Sep 12, 2024
452ba07
10409: Update tests for legacy judges only showing on closed and all
Sep 13, 2024
6795a5b
10409: temp docs
Sep 13, 2024
c92d7d0
10409: WIP adding inputs for new select dropdowns on trial sessions
Sep 17, 2024
9a83acc
10409: WIP styling trial sessions date range
Sep 18, 2024
5356374
10409: Remove temp styling
Sep 18, 2024
77cbf3d
10409: WIP start adding options to trial sessions
Sep 18, 2024
417f79e
10409: add options to filter dropdowns;
nechama-krigsman Sep 18, 2024
6d6cb5a
10409: WIP Converting judgeIds into a multi select
Sep 18, 2024
6c717b3
10409: WIP Converting TrialLocations into a multi select
Sep 18, 2024
77e2631
10409: WIP Converting session types to multi select filter
Sep 18, 2024
e4ad45f
10409: add clear trial session filter button;
nechama-krigsman Sep 19, 2024
0713553
10409: disable clear filters button when no optional filters are sele…
nechama-krigsman Sep 19, 2024
46341da
10409: Remove console logs
Sep 19, 2024
c294cf6
10409: add filtering for trial start date range;
nechama-krigsman Sep 19, 2024
2ebfde0
10409: Add functionality for reset filters
Sep 19, 2024
30e8eca
10409: fix warnings
Sep 19, 2024
d7b43ea
10409: fix reseet filters on tab change
Sep 19, 2024
1d1a0e6
10409: add trial session count;
nechama-krigsman Sep 19, 2024
8e5495a
10409: wip
JayFlexy Sep 19, 2024
6965f65
10409: Add pagination support for trial sessions
Sep 19, 2024
4618a77
10409: Change paginator location
Sep 19, 2024
4b12b16
10409: Set page number whenever filters change
Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 10409_validation_delete_me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Problem statement: How can we detect when making a validation changes to entities, we do not create invalid data in the database?

- Pull all validation rules into a single file, if they change in any way, a validation sweep must be run on the database
- Continue validating before we return inside all of our interactors but instead of exploding just silently log which entities are now invalid.
- On each deployment validate all data in the database.


Assumptions
- Not all business rules can or should live inside of the persistence layer.
- For example when a trialSession is calendared it should have a sessionType
- What is and what is not a valid entity can only be expressed inside of functions.
- Is it possible to tell if a function has been modified between different git commits?
- If it is a pure function that does not modify any external state


shared/src/business/entities/contacts/Contact.ts getValidationRules depends on instance.countryType


Thoughts
- If validation rules are expressed inside of functions it is impossible to tell if a function has changed its behavior from one release to another. If it is impossible to tell if validation rules have changed then maybe defensively checking if they have changed, and running a validation sweep on the DB is not the correct approach
- Another option is better warnings to devs about making validation changes.
- Another option is continue validating, but only log invalid values instead of throwing errors to reduce application impact.


Resources
- Validate at input time. Validate again before you put it in the database. And have database constraints to prevent bad input. And you can bet in spite of all that, bad data will still get into your database, so validate it again when you use it.
6 changes: 0 additions & 6 deletions shared/src/business/dto/trialSessions/TrialSessionInfoDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ export class TrialSessionInfoDTO {
public sessionStatus: string;
public swingSession?: boolean;
public dismissedAlertForNOTT?: boolean;
public isStartDateWithinNOTTReminderRange?: boolean;
public thirtyDaysBeforeTrialFormatted?: string;

constructor(rawTrialSession: RawTrialSession) {
this.estimatedEndDate = rawTrialSession.estimatedEndDate;
this.isCalendared = rawTrialSession.isCalendared;
this.judge = rawTrialSession.judge;
this.isStartDateWithinNOTTReminderRange =
rawTrialSession.isStartDateWithinNOTTReminderRange;
this.thirtyDaysBeforeTrialFormatted =
rawTrialSession.thirtyDaysBeforeTrialFormatted;
this.proceedingType = rawTrialSession.proceedingType;
this.sessionType = rawTrialSession.sessionType;
this.startDate = rawTrialSession.startDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ describe('TrialSession entity', () => {
{ daysFromToday: 34, expectedOutput: true },
{ daysFromToday: 35, expectedOutput: false },
];
it('should set isStartDateWithinNOTTReminderRange to false when the trial session is not calendared', () => {
it('should return false when the trial session is not calendared', () => {
const trialSession = new TrialSession({
...MOCK_TRIAL_REGULAR,
isCalendared: false,
});

expect(trialSession.isStartDateWithinNOTTReminderRange).toBe(false);
expect(
TrialSession.isStartDateWithinNOTTReminderRange({
isCalendared: trialSession.isCalendared,
startDate: trialSession.startDate,
}),
).toBe(false);
});

tests.forEach(({ daysFromToday, expectedOutput }) => {
it(`should set isStartDateWithinNOTTReminderRange to ${expectedOutput} when the trial session is calendared and the start date is ${daysFromToday} days from today`, () => {
it(`should return ${expectedOutput} when the trial session is calendared and the start date is ${daysFromToday} days from today`, () => {
const thirtyDaysFromToday = today.plus({ ['days']: daysFromToday });

const trialSession = new TrialSession({
Expand All @@ -39,9 +44,12 @@ describe('TrialSession entity', () => {
startDate: thirtyDaysFromToday,
});

expect(trialSession.isStartDateWithinNOTTReminderRange).toBe(
expectedOutput,
);
expect(
TrialSession.isStartDateWithinNOTTReminderRange({
isCalendared: trialSession.isCalendared,
startDate: trialSession.startDate,
}),
).toBe(expectedOutput);
});
});
});
Expand Down

This file was deleted.

61 changes: 27 additions & 34 deletions shared/src/business/entities/trialSessions/TrialSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class TrialSession extends JoiValidationEntity {
public irsCalendarAdministratorInfo?: RawIrsCalendarAdministratorInfo;
public isCalendared: boolean;
public isClosed?: boolean;
public isStartDateWithinNOTTReminderRange?: boolean;
public joinPhoneNumber?: string;
public judge?: TJudge;
public maxCases?: number;
Expand All @@ -107,7 +106,6 @@ export class TrialSession extends JoiValidationEntity {
public swingSessionId?: string;
public term: string;
public termYear: string;
public thirtyDaysBeforeTrialFormatted?: string;
public trialClerk?: TTrialClerk;
public trialLocation?: string;
public trialSessionId?: string;
Expand Down Expand Up @@ -198,12 +196,6 @@ export class TrialSession extends JoiValidationEntity {
};
}

if (rawSession.isCalendared && rawSession.startDate) {
this.setNoticeOfTrialReminderAlert();
} else {
this.isStartDateWithinNOTTReminderRange = false;
}

if (rawSession.trialClerk && rawSession.trialClerk.name) {
this.trialClerk = {
name: rawSession.trialClerk.name,
Expand All @@ -216,6 +208,33 @@ export class TrialSession extends JoiValidationEntity {
return sessionScope === TRIAL_SESSION_SCOPE_TYPES.standaloneRemote;
}

static isStartDateWithinNOTTReminderRange({
isCalendared,
startDate,
}: {
isCalendared?: boolean;
startDate?: string;
}): boolean {
if (!isCalendared || !startDate) {
return false;
}

const formattedStartDate = formatDateString(startDate, FORMATS.MMDDYY);
const trialStartDateString = prepareDateFromString(
formattedStartDate,
FORMATS.MMDDYY,
);

return isTodayWithinGivenInterval({
intervalEndDate: trialStartDateString.minus({
['days']: 24, // luxon's interval end date is not inclusive
}),
intervalStartDate: trialStartDateString.minus({
['days']: 34,
}),
});
}

static validationRules = {
COMMON: {
address1: JoiValidationConstants.STRING.max(100).allow('').optional(),
Expand Down Expand Up @@ -406,32 +425,6 @@ export class TrialSession extends JoiValidationEntity {
return skPrefix;
}

setNoticeOfTrialReminderAlert() {
const formattedStartDate = formatDateString(this.startDate, FORMATS.MMDDYY);
const trialStartDateString: any = prepareDateFromString(
formattedStartDate,
FORMATS.MMDDYY,
);

this.isStartDateWithinNOTTReminderRange = isTodayWithinGivenInterval({
intervalEndDate: trialStartDateString.minus({
['days']: 24, // luxon's interval end date is not inclusive
}),
intervalStartDate: trialStartDateString.minus({
['days']: 34,
}),
});

const thirtyDaysBeforeTrialInclusive: any = trialStartDateString.minus({
['days']: 29,
});

this.thirtyDaysBeforeTrialFormatted = formatDateString(
thirtyDaysBeforeTrialInclusive,
FORMATS.MMDDYY,
);
}

setAsCalendared() {
this.isCalendared = true;
this.sessionStatus = SESSION_STATUS_TYPES.open;
Expand Down
2 changes: 1 addition & 1 deletion shared/src/business/utilities/DateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
* @returns {string} a formatted date string
*/
export const formatDateString = (
dateString: string,
dateString: string | undefined,
formatArg: TimeFormatNames | TimeFormats = FORMATS.ISO,
): string => {
if (!dateString) return '';
Expand Down Expand Up @@ -608,7 +608,7 @@
const todayDate = formatNow(FORMATS.YYYYMMDD);
const dateLessthanOrEqualToToday = dateString <= todayDate;
// console.log(`dateInputValid: ${dateInputValid}`);
// console.log(`dateLessthanOrEqualToToday: ${dateLessthanOrEqualToToday}`);

Check warning on line 611 in shared/src/business/utilities/DateHandler.ts

View workflow job for this annotation

GitHub Actions / Lint

You have a misspelled word: Lessthan on Comment

Check warning on line 611 in shared/src/business/utilities/DateHandler.ts

View workflow job for this annotation

GitHub Actions / Lint

You have a misspelled word: Lessthan on Comment
return dateInputValid && dateLessthanOrEqualToToday;
};

Expand Down
5 changes: 4 additions & 1 deletion shared/src/proxies/trialSessions/getTrialSessionsProxy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TrialSessionInfoDTO } from '@shared/business/dto/trialSessions/TrialSessionInfoDTO';
import { get } from '../requests';

/**
Expand All @@ -6,7 +7,9 @@ import { get } from '../requests';
* @param {object} applicationContext the application context
* @returns {Promise<*>} the promise of the api call
*/
export const getTrialSessionsInteractor = applicationContext => {
export const getTrialSessionsInteractor = (
applicationContext,
): Promise<TrialSessionInfoDTO[]> => {
return get({
applicationContext,
endpoint: '/trial-sessions',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
mockPetitionerUser,
mockPetitionsClerkUser,
} from '@shared/test/mockAuthUsers';
import { omit } from 'lodash';

describe('getTrialSessionsInteractor', () => {
it('should throw an unauthorized error when the user does not have permission to view trial sessions', async () => {
Expand All @@ -19,19 +18,7 @@ describe('getTrialSessionsInteractor', () => {
).rejects.toThrow(new UnauthorizedError('Unauthorized'));
});

it('should throw an error when the entity returned from persistence is invalid', async () => {
applicationContext
.getPersistenceGateway()
.getTrialSessions.mockResolvedValue([
omit(MOCK_TRIAL_INPERSON, 'maxCases'),
]);

await expect(
getTrialSessionsInteractor(applicationContext, mockPetitionsClerkUser),
).rejects.toThrow('The TrialSession entity was invalid.');
});

it('should return a list of validated trial sessions', async () => {
it('should return a list of trial sessions', async () => {
applicationContext
.getPersistenceGateway()
.getTrialSessions.mockResolvedValue([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
isAuthorized,
} from '../../../../../shared/src/authorization/authorizationClientService';
import { ServerApplicationContext } from '@web-api/applicationContext';
import { TrialSession } from '../../../../../shared/src/business/entities/trialSessions/TrialSession';
import { TrialSession } from '@shared/business/entities/trialSessions/TrialSession';
import { TrialSessionInfoDTO } from '../../../../../shared/src/business/dto/trialSessions/TrialSessionInfoDTO';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
Expand All @@ -22,9 +22,7 @@ export const getTrialSessionsInteractor = async (
applicationContext,
});

const validatedSessions = TrialSession.validateRawCollection(trialSessions);

return validatedSessions.map(
trialSession => new TrialSessionInfoDTO(trialSession),
);
return trialSessions
.map(t => new TrialSession(t).toRawObject())
.map(trialSession => new TrialSessionInfoDTO(trialSession));
};
4 changes: 2 additions & 2 deletions web-api/storage/fixtures/seed/efcms-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -50345,7 +50345,7 @@
{
"caseOrder": [],
"gsi1pk": "trial-session-catalog",
"sessionStatus": "New",
"sessionStatus": "Open",
"trialLocation": "Denver, Colorado",
"proceedingType": "In Person",
"createdAt": "2019-11-02T05:00:00.000Z",
Expand All @@ -50362,7 +50362,7 @@
"startDate": "2019-12-02T05:00:00.000Z",
"maxCases": 30,
"trialSessionId": "0d943468-bc2e-4631-84e3-b084cf5b1fbb",
"isCalendared": false,
"isCalendared": true,
"status": "Closed"
},
{
Expand Down
Loading
Loading