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

Replace operation rep #2679

Merged
merged 13 commits into from
Jan 23, 2025
Merged

Replace operation rep #2679

merged 13 commits into from
Jan 23, 2025

Conversation

BCerki
Copy link
Contributor

@BCerki BCerki commented Jan 13, 2025

https://github.com/orgs/bcgov/projects/123/views/16?pane=issue&itemId=88758186&issue=bcgov%7Ccas-registration%7C2524

Notes:

  • I've used a url param to decide whether or not to show the alert on the contact page. As far as I could find online (e.g. https://medium.com/@awayyao/keep-page-state-between-page-navigation-in-nextjs-13-using-app-router-schema-f6eacd0300ad), the next router doesn't store any state or history. window.history doesn't store the previous url, and document.referer only gives the origin.
  • Updated the mock data so that contacts are more representative of how the app works (e.g., operations can only have contacts that belong to their operators; all registered operations have to have a contact)
  • because of ^, I noticed you can get to the operation administration page before the operation is registered if you go via the URL. I added a check in the endpoint
  • I wrote a couple comments in the card about where I haven't followed the card exactly

@@ -198,6 +199,22 @@ def create_or_update_operation_v2(

# set m2m relationships
operation.activities.set(payload.activities)
if isinstance(payload, OperationInformationInUpdate):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (vs if payload.operation_representatives) was to make mypy happy

@@ -330,12 +347,6 @@ def update_operation(
payload,
operation_id,
)

if payload.regulated_products:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already handled in create_or_update_operation_v2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, good catch, Thanks! 🙏
At some point, we might need to refactor create_or_update_operation_v2 service because it has many responsibilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this too--in other places in the app we have separate create and update functions

@BCerki BCerki force-pushed the 2524-replace-op-rep branch 5 times, most recently from fb07630 to 8583b84 Compare January 17, 2025 16:14
@@ -162,7 +190,7 @@ const formData = {
naics_code_id: 1,
secondary_naics_code_id: 2,
operation_has_multiple_operators: true,
activities: [1, 2, 3, 4, 5],
activities: [1, 2],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only mocked two activities

@BCerki BCerki force-pushed the 2524-replace-op-rep branch from 8583b84 to 444fbe4 Compare January 17, 2025 16:21
@BCerki BCerki marked this pull request as ready for review January 17, 2025 16:21
@BCerki BCerki force-pushed the 2524-replace-op-rep branch 2 times, most recently from 5af0462 to 5bda3dc Compare January 17, 2025 22:27
Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dope! 🔥 I’ve left a few small suggestions, but nothing major.

Comment on lines 18 to 25
class PlacesAssigned(Schema):
role_name: str
operation_name: str
operation_id: UUID


class ContactWithPlacesAssigned(ContactOut):
places_assigned: Optional[list[PlacesAssigned]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these schemas into the schema file?

Comment on lines 50 to 57
@classmethod
def get_if_authorized_v2(cls, user_guid: UUID, contact_id: int) -> Optional[Contact]:
user = UserDataAccessService.get_by_guid(user_guid)
user_contacts = ContactDataAccessService.get_all_contacts_for_user(user)
contact = user_contacts.filter(id=contact_id).first()
if user.is_industry_user() and not contact:
raise Exception(UNAUTHORIZED_MESSAGE)
return contact
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is the second version of a method I wrote earlier (which was never used lol). However, I'm struggling to grasp its purpose. Since we’re already retrieving all the contacts associated with the user’s operator, why do we need to check if the user is an industry user and if there’s no associated contact, why do we raise UNAUTHORIZED_MESSAGE? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh... good question. Maybe it was something about how reg1 had senior officers as part of the operator approval? I'll nix it for v2

@@ -23,7 +24,7 @@
)
@handle_http_errors()
def get_contact(request: HttpRequest, contact_id: int) -> Tuple[Literal[200], Optional[ContactWithPlacesAssigned]]:
return 200, ContactService.get_with_places_assigned(get_current_user_guid(request), contact_id)
return 200, ContactServiceV2.get_with_places_assigned_v2(get_current_user_guid(request), contact_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use ContactWithPlacesAssigned as the schema for the response? (line 18)

Comment on lines +221 to +225
(
Q(bc_obps_regulated_operation__id__icontains=bc_obps_regulated_operation)
if bc_obps_regulated_operation
else Q()
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a formatting change? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, prettier put it in

Comment on lines +85 to +89
<Note variant="important">
To remove the current operation representative, please select a new
contact to replace them.
</Note>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to show this message to internal users too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, thanks for catching

Comment on lines +54 to +63
if (response.error.includes("Please return to Contacts")) {
const splitError = response.error.split("Contacts");
response.error = (
<>
{splitError[0]} <Link href={"/contacts"}>Contacts</Link>
{splitError[1]}
</>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think adding a comment here could be helpful.

Comment on lines 11 to 17
const regulatedProducts: { id: number; name: string }[] =
await getRegulatedProducts();

const contacts: {
items: [{ id: number; first_name: string; last_name: string }];
} = await getContacts();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use error-handling logic here! Just in case fetching data fails for regulatedProducts or contacts.

Comment on lines 38 to 40
vi.mock("libs/actions/src/api/getContacts", () => ({
default: getContacts,
}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would it be better to move this to the contacts/mocks folder?

return (
<div className="flex min-w-full flex-col">
{items?.map((item) => {
const formData = item.children.props.formData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const { role_name, operation_name, operation_id } = item.children.props.formData;

'status',
'activities',
'opted_in_operation',
'contacts',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need contacts here?!

@BCerki BCerki force-pushed the 2524-replace-op-rep branch from 5bda3dc to d017894 Compare January 23, 2025 21:56
@@ -194,7 +194,7 @@ class Meta:
'status',
'activities',
'opted_in_operation',
'contacts',
# 'contacts',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover!

Comment on lines 36 to 37
def get_by_id(cls, contact_id: int) -> Contact:
return Contact.objects.get(id=contact_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this in ContactDataAccessService.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

@BCerki BCerki force-pushed the 2524-replace-op-rep branch from 41e2957 to 5d79839 Compare January 23, 2025 23:33
@BCerki BCerki merged commit 05ae1f7 into develop Jan 23, 2025
42 checks passed
@BCerki BCerki deleted the 2524-replace-op-rep branch January 23, 2025 23:52
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.

2 participants