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

Chi-2357 add link contact case #1954

Merged
merged 15 commits into from
Dec 22, 2023
Merged

Conversation

acedeywin
Copy link
Contributor

@acedeywin acedeywin commented Dec 19, 2023

Primary reviewer:

Description

  • This PR adds the blue banner to link from contact to case as well as an Undo button on the orange banner after a case has been removed from the contact.

Checklist

  • Corresponding issue has been opened
  • New tests added
  • Feature flags added
  • Strings are localized
  • Tested for chat contacts
  • Tested for call contacts

Related Issues

Fixes CHI-2357

Verification steps

  • Search for contact
  • Click on a contact that has been connected to a case
  • Verify that you can see the blue banner when you preview the contact
  • Click the "Remove from Case" button to remove the case from the contact
  • Verify that there is an "Undo" button on the orange banner
  • Click on the "Undo" button to undo the previous action

Copy link
Collaborator

@stephenhand stephenhand left a 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) => {
Copy link
Collaborator

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: {
Copy link
Collaborator

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

Copy link
Contributor Author

@acedeywin acedeywin Dec 20, 2023

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

Copy link
Collaborator

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;
Copy link
Collaborator

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?

Copy link
Contributor Author

@acedeywin acedeywin Dec 20, 2023

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.

Copy link
Collaborator

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;
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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: {
Copy link
Collaborator

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;
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

@stephenhand stephenhand left a 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.

@stephenhand
Copy link
Collaborator

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

@stephenhand
Copy link
Collaborator

All good now!

@acedeywin acedeywin merged commit d6a63f5 into master Dec 22, 2023
8 checks passed
@acedeywin acedeywin deleted the CHI-2357-add_link_contact_case branch December 22, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants