Skip to content

CHI-3279: Fix referencing for timelines to prevent issues with case search results going blank. Fix orphaned case check #2952

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 12 additions & 8 deletions plugin-hrm-form/src/___tests__/components/case/Case.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ beforeEach(() => {
describe('useState mocked', () => {
const verifyTimelineActions = () => {
['household', 'incident', 'perpetrator'].forEach(sectionType => {
expect(mockNewGetTimelineAction).toHaveBeenCalledWith(case1.connectedCase.id, sectionType, [sectionType], false, {
limit: 100,
offset: 0,
});
expect(mockNewGetTimelineAction).toHaveBeenCalledWith(
case1.connectedCase.id,
sectionType,
[sectionType],
false,
{
limit: 100,
offset: 0,
},
`case-${case1.connectedCase.id}`,
);
});

expect(mockNewGetTimelineAction).toHaveBeenCalledWith(
Expand All @@ -96,6 +103,7 @@ describe('useState mocked', () => {
expect.arrayContaining(['referral', 'note']),
true,
{ limit: 5, offset: 0 },
`case-${case1.connectedCase.id}`,
);
};

Expand Down Expand Up @@ -136,12 +144,8 @@ describe('useState mocked', () => {
twilioWorkerId: WORKER_SID,
status: 'open',
info: { definitionVersion: DefinitionVersionId.v1 },
categories: {},
accountSid: 'AC-accountSid',
helpline: 'helpline',
firstContact: {
id: 'contact1',
} as Contact,
},
availableStatusTransitions: [],
references: new Set(['x']),
Expand Down
11 changes: 10 additions & 1 deletion plugin-hrm-form/src/___tests__/states/case/timeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('newGetTimelineAsyncAction', () => {
['note', 'household'],
true,
SAMPLE_PAGINATION,
'test-reference',
);
expect(getCaseTimeline).toHaveBeenCalledWith(TEST_CASE_ID, ['note', 'household'], true, SAMPLE_PAGINATION);

Expand All @@ -120,6 +121,7 @@ describe('newGetTimelineAsyncAction', () => {
timelineId: TEST_TIMELINE_ID,
caseId: TEST_CASE_ID,
pagination: SAMPLE_PAGINATION,
reference: 'test-reference',
});
});

Expand Down Expand Up @@ -197,7 +199,14 @@ describe('newGetTimelineAsyncAction', () => {
} = getState() as HrmState;
mockGetCaseTimeline.mockResolvedValue(apiResponse);
await ((dispatch(
newGetTimelineAsyncAction(TEST_CASE_ID, TEST_TIMELINE_ID, ['note', 'household'], true, pagination),
newGetTimelineAsyncAction(
TEST_CASE_ID,
TEST_TIMELINE_ID,
['note', 'household'],
true,
pagination,
'test-reference',
),
) as unknown) as PromiseLike<void>);
const {
connectedCase: {
Expand Down
9 changes: 8 additions & 1 deletion plugin-hrm-form/src/components/case/CaseSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ const CaseSection: React.FC<Props> = ({ taskSid, canAdd, sectionType }) => {
// eslint-disable-next-line no-console
console.log(`Fetching ${sectionType} sections for case ${caseId}`);
asyncDispatcher(
newGetTimelineAsyncAction(caseId, sectionType, [sectionType], false, { offset: 0, limit: MAX_SECTIONS }),
newGetTimelineAsyncAction(
caseId,
sectionType,
[sectionType],
false,
{ offset: 0, limit: MAX_SECTIONS },
`case-${caseId}`,
),
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
30 changes: 22 additions & 8 deletions plugin-hrm-form/src/components/case/casePrint/CasePrintView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ const CasePrintView: React.FC<OwnProps> = ({ task }) => {
useEffect(() => {
if (!contactTimeline) {
dispatch(
newGetTimelineAsyncAction(connectedCase.id, 'print-contacts', [], true, {
offset: 0,
limit: MAX_PRINTOUT_CONTACTS,
}),
newGetTimelineAsyncAction(
connectedCase.id,
'print-contacts',
[],
true,
{
offset: 0,
limit: MAX_PRINTOUT_CONTACTS,
},
`case-${connectedCase.id}`,
),
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -129,10 +136,17 @@ const CasePrintView: React.FC<OwnProps> = ({ task }) => {
useEffect(
() => {
dispatch(
newGetTimelineAsyncAction(connectedCase.id, sectionType, [sectionType], false, {
offset: 0,
limit: MAX_SECTIONS,
}),
newGetTimelineAsyncAction(
connectedCase.id,
sectionType,
[sectionType],
false,
{
offset: 0,
limit: MAX_SECTIONS,
},
`case-${connectedCase.id}`,
),
);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
15 changes: 11 additions & 4 deletions plugin-hrm-form/src/components/case/timeline/FullTimelineView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ const mapDispatchToProps = (dispatch: Dispatch<any>, { task }: MyProps) => {
changeRoute({ route: 'case', subroute: 'timeline', caseId, page }, task.taskSid, ChangeRouteMode.Replace),
);
dispatch(
newGetTimelineAsyncAction(caseId, 'prime-timeline', ['note', 'referral'], true, {
offset: page * TIMELINE_PAGE_SIZE,
limit: TIMELINE_PAGE_SIZE,
}),
newGetTimelineAsyncAction(
caseId,
'prime-timeline',
['note', 'referral'],
true,
{
offset: page * TIMELINE_PAGE_SIZE,
limit: TIMELINE_PAGE_SIZE,
},
`case-${caseId}`,
),
);
},
};
Expand Down
15 changes: 11 additions & 4 deletions plugin-hrm-form/src/components/case/timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ const Timeline: React.FC<OwnProps> = ({
if (caseId) {
console.log(`Fetching main timeline sections for case ${caseId}`);
asyncDispatch(dispatch)(
newGetTimelineAsyncAction(caseId, timelineId, timelineCaseSectionTypes, true, {
offset: page * pageSize,
limit: pageSize,
}),
newGetTimelineAsyncAction(
caseId,
timelineId,
timelineCaseSectionTypes,
true,
{
offset: page * pageSize,
limit: pageSize,
},
`case-${caseId}`,
),
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
4 changes: 3 additions & 1 deletion plugin-hrm-form/src/components/caseList/CaseListTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ const CaseListTableRow: React.FC<Props> = ({ caseId, handleClickViewCase }) => {

useEffect(() => {
if (!timelineCategories) {
dispatch(newGetTimelineAsyncAction(caseId, CONTACTS_TIMELINE_ID, [], true, { offset: 0, limit: 10000 }));
dispatch(
newGetTimelineAsyncAction(caseId, CONTACTS_TIMELINE_ID, [], true, { offset: 0, limit: 10000 }, `case-list`),
);
}
}, [timelineCategories, caseId, dispatch]);

Expand Down
19 changes: 16 additions & 3 deletions plugin-hrm-form/src/components/search/CasePreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
newGetTimelineAsyncAction,
selectCaseLabel,
selectTimelineContactCategories,
selectTimelineCount,
} from '../../../states/case/timeline';

type Props = {
Expand All @@ -60,6 +61,9 @@ const CasePreview: React.FC<Props> = ({ currentCase, onClickViewCase, counselors
const timelineCategories = useSelector((state: RootState) =>
selectTimelineContactCategories(state, currentCase.id, CONTACTS_TIMELINE_ID),
);
const contactCount = useSelector((state: RootState) =>
selectTimelineCount(state, currentCase.id, CONTACTS_TIMELINE_ID),
);
const caseLabel = useSelector((state: RootState) =>
selectCaseLabel(state, currentCase.id, CONTACTS_TIMELINE_ID, {
substituteForId: false,
Expand All @@ -71,15 +75,24 @@ const CasePreview: React.FC<Props> = ({ currentCase, onClickViewCase, counselors

useEffect(() => {
if (!timelineCategories) {
dispatch(newGetTimelineAsyncAction(currentCase.id, CONTACTS_TIMELINE_ID, [], true, { offset: 0, limit: 10000 }));
dispatch(
newGetTimelineAsyncAction(
currentCase.id,
CONTACTS_TIMELINE_ID,
[],
true,
{ offset: 0, limit: 10000 },
`search-${task.taskSid}`,
),
);
}
}, [timelineCategories, currentCase.id, dispatch]);
}, [timelineCategories, currentCase.id, dispatch, task.taskSid]);

const { id, createdAt, status, info, twilioWorkerId } = currentCase;
const updatedAtObj = getUpdatedDate(currentCase);
const followUpDateObj = info.followUpDate ? new Date(info.followUpDate) : undefined;
const { definitionVersion: versionId } = info;
const orphanedCase = !timelineCategories;
const orphanedCase = contactCount === 0;
const summary = info?.summary;
const counselor = counselorsHash[twilioWorkerId];

Expand Down
4 changes: 3 additions & 1 deletion plugin-hrm-form/src/states/case/hooks/useCaseSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const useCaseSectionsLoader = ({
return;
}

asyncDispatch(dispatch)(newGetTimelineAsyncAction(caseId, sectionType, [sectionType], false, { offset, limit }));
asyncDispatch(dispatch)(
newGetTimelineAsyncAction(caseId, sectionType, [sectionType], false, { offset, limit }, `case-${caseId}`),
);
}, [caseId, dispatch, limit, offset, sectionType]);

const safeToLoad = Boolean(caseId) && exists;
Expand Down
5 changes: 4 additions & 1 deletion plugin-hrm-form/src/states/case/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ export const newGetTimelineAsyncAction = createAsyncAction(
sectionTypes: string[],
includeContacts: boolean,
pagination: PaginationSettings,
reference: string,
): Promise<{
timelineResult: TimelineResult<Date>;
caseId: Case['id'];
timelineId: string;
pagination: PaginationSettings;
reference: string;
}> => {
return {
timelineResult: await getCaseTimeline(caseId, sectionTypes, includeContacts, pagination),
caseId,
timelineId,
pagination,
reference,
};
},
);
Expand Down Expand Up @@ -211,5 +214,5 @@ export const selectCaseLabel = (
return contactLabelFromHrmContact(def, firstContact.activity, contactLabelOptions);
}
}
return undefined;
return contactLabelOptions?.placeholder ?? '';
};
4 changes: 2 additions & 2 deletions plugin-hrm-form/src/states/contacts/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ export function reduce(
return loadContactListIntoState(state, rootState.configuration, action.searchResult.contacts, `${action.taskId}-search-contact`);
}
case GET_CASE_TIMELINE_ACTION_FULFILLED: {
const { payload: { caseId, timelineResult: { activities } } } = action;
const { payload: { timelineResult: { activities }, reference } } = action;
const contacts = activities.filter(isContactTimelineActivity).map(({ activity })=> activity);
return loadContactListIntoState(state, rootState.configuration, contacts, `case-${caseId}`, false);
return loadContactListIntoState(state, rootState.configuration, contacts, reference, false);
}
case CREATE_CASE_ACTION_FULFILLED: {
const { payload: { connectedContact } } = action as CreateCaseAsyncActionFulfilled;
Expand Down
Loading