-
Notifications
You must be signed in to change notification settings - Fork 10
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
Chi-2357 add link contact case #1954
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things suggested that would streamline the implementation, but the logic looks correct
const { savedContact } = selectContactByTaskSid(state, taskId); | ||
const connectedCase = selectCaseByCaseId(state, savedContact.caseId ?? '')?.connectedCase; | ||
const caseId = savedContact?.caseId; | ||
const mapStateToProps = (state: RootState, { taskId, contactId }: OwnProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should change the ContactAddedToCaseBanner to always have a contactId passed in, it's available on TabbedForms.tsx which is the other place where this is used, so we may as well pass it in there too.
We can then simplify this logic to always expect the contact ID and always use that to look up the contact
@@ -222,6 +223,14 @@ export function reduce( | |||
}, | |||
}; | |||
} | |||
case t.SET_REMOVED_CASE_ID: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should enhance the CaseMergingBannersState that @murilovmachado created in state/case/caseBanners.ts
rather than creating another state structure. We can then also reuse those actions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephenhand - The SET_REMOVED_CASE_ID
is a new action type that would hold the caseId of the connected contact after the contact has been removed from the case. This caseId will subsequently be used when the user wants to Undo the initial action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that - I'm saying we already have a redux state & associated actions for managing whether a 'removed from case' banner should be displayed on a contact. We don't want 2 different states for managing it on 2 different pages, a contact should either be showing a 'removed from case' banner or it shouldn't.
The only thing missing from the existing state is the case ID used in the undo functionality
|
||
type OwnProps = { | ||
taskId: string; | ||
savedContact?: Contact; | ||
showRemovedFromCaseBanner?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is confusing, would showUndoButton
be more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephenhand - showRemovedFromCaseBanner
state is for the blue banner state and was previously implemented by @murilovmachado. I was only reusing it. I think this was what you meant in your previous comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this code, the part of the banner toggled by this variable isn't the whole banner, but the just the undo button. The banner itself, the warning triangle and main message are displayed whether this variable is set or not, which is why this is a misleading name in this context
|
||
type OwnProps = { | ||
taskId: string; | ||
savedContact?: Contact; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think we should simplify this logic by making the banner always expect a contactId, which it then uses to look up the contact. TabbedForms.tsx
which is the other place this banner appears already has the ID loaded from state, so it's trivial to pass it in their too and simplify this logic
We should expect a contactId rather than a full contact object, since we only use the ID anyway, anmd this is conistent with the other banner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephenhand - I wouldn't just need the contactId, else I would pass just it. I also needed to get the contact state since I will be needing it for the Undo
action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only look to use the ID in the code? Even if you do use the rest of the contact data it should be mapped from the state via it's ID in this component rather than prop drilled whole. This is consistent with the other banner interface and more aligned with our general move away from prop drilling and more direct use of redux state
|
||
type OwnProps = { | ||
taskId: string; | ||
savedContact?: Contact; | ||
showRemovedFromCaseBanner?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this code, the part of the banner toggled by this variable isn't the whole banner, but the just the undo button. The banner itself, the warning triangle and main message are displayed whether this variable is set or not, which is why this is a misleading name in this context
|
||
type OwnProps = { | ||
taskId: string; | ||
savedContact?: Contact; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only look to use the ID in the code? Even if you do use the rest of the contact data it should be mapped from the state via it's ID in this component rather than prop drilled whole. This is consistent with the other banner interface and more aligned with our general move away from prop drilling and more direct use of redux state
@@ -222,6 +223,14 @@ export function reduce( | |||
}, | |||
}; | |||
} | |||
case t.SET_REMOVED_CASE_ID: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that - I'm saying we already have a redux state & associated actions for managing whether a 'removed from case' banner should be displayed on a contact. We don't want 2 different states for managing it on 2 different pages, a contact should either be showing a 'removed from case' banner or it shouldn't.
The only thing missing from the existing state is the case ID used in the undo functionality
const caseId = savedContact?.caseId; | ||
const mapStateToProps = (state: RootState, { taskId, contactId }: OwnProps) => { | ||
const offlineSavedContact = selectContactByTaskSid(state, taskId)?.savedContact; | ||
const existingSavedContact = state[namespace][contactFormsBase].existingContacts[contactId]?.savedContact; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Sorry, missed this in the first pass] We have a selectContactStateByContactId
selector function we should use for this.
We should be using selector functions to map state to components in all new code now- in this case we already have one, but where they don't exist yet we should add them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephenhand - All feedback has been implemented.
…than contact IDs in the case connectedContacts.
…into CHI-2357-add_link_contact_case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates look good - a small issue came up in testing that if you open a contact from the case timeline, remove it, then go back to the case, the contact is still there. I made a small update to the logic used to select the connected contacts for a case from redux that fixed this
So LGTM now.
Except I broke it 🤦 - fixing it now |
…nised transfer code slightly, updated tests
…into CHI-2357-add_link_contact_case
All good now! |
Primary reviewer:
Description
Checklist
Related Issues
Fixes CHI-2357
Verification steps