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

✨ BusinessServices: Update Notification and refactors update/create modal and queries #1210

Merged
merged 4 commits into from
Jul 27, 2023
Merged

✨ BusinessServices: Update Notification and refactors update/create modal and queries #1210

merged 4 commits into from
Jul 27, 2023

Conversation

gildub
Copy link
Contributor

@gildub gildub commented Jul 26, 2023

While resolving the related notification issues (see associated MTA-1024) this also refactors create/update modal and tries to bring more consistency.

Includes following changes :

  • Push edit/create notifications down to BusinessServiceForm
  • Use onClose to replace onSave and onCancel
  • Replace REST functions to use axios instead of deprecated APIClient().
  • Use React Query mutations instead of legacy queries
  • Consolidate New/Edit Modal duplication

Partially address https://issues.redhat.com/browse/MTA-1024

@gildub gildub self-assigned this Jul 26, 2023
@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Patch coverage: 33.33% and project coverage change: -0.08% ⚠️

Comparison is base (97005b7) 44.10% compared to head (b10c025) 44.02%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1210      +/-   ##
==========================================
- Coverage   44.10%   44.02%   -0.08%     
==========================================
  Files         177      177              
  Lines        4501     4511      +10     
  Branches     1007     1007              
==========================================
+ Hits         1985     1986       +1     
- Misses       2505     2514       +9     
  Partials       11       11              
Flag Coverage Δ
unitests 44.02% <33.33%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
client/src/app/queries/businessservices.ts 30.76% <20.00%> (-11.54%) ⬇️
client/src/app/api/rest.ts 54.46% <60.00%> (+0.46%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

): Promise<BusinessService> => axios.delete(`${BUSINESS_SERVICES}/${id}`);

export const createBusinessService = (
obj: New<BusinessService>
Copy link
Member

Choose a reason for hiding this comment

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

I would like to see a more descriptive param name here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336, the entire rest.ts file is using obj as parameter for passing the payload.
I don't see the gain to explicitly name the payload but that might be opinionated.
And if we do that then we're going to be inconsistent across the file.

onClose();
};

const onUpdateBusinessServiceSuccess = (
Copy link
Member

Choose a reason for hiding this comment

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

We should be using a combined success handler here like we are for applications. Or at least we should agree on a style and be consistent across slices of the app.

Copy link
Contributor Author

@gildub gildub Jul 27, 2023

Choose a reason for hiding this comment

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

@ibolton336,

The Applications case is actually more an exception.

To have combined success handlers for both create/edit means both needs to provide the name of the modified resource which I believe is out of scope. To discuss the matter, please seee #1214.

Copy link
Member

Choose a reason for hiding this comment

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

Thx. I read the issue but I still don't see why the application handler is a special case. Maybe it would just be easier to move the on create / on update success handlers to their own functions for the applications? Just for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336,
you're right, the Application isn't a special case, I confused it with the MigrationTargets where we have to pass the reference to scroll down the page.
So revisiting this, we want to be consistent and have separate handlers, I'm changing the handlers in #1207.

We might eventually revisit that, consistently of course, or not once we decide to pass along the object name to the save/edit.

};

export const useUpdateBusinessServiceMutation = (
onSuccess: (res: any) => void,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onSuccess: (res: any) => void,
onSuccess: (businessServiceName: string) => void,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336, all queries are using res as parameter for onSuccess().
Therefore I don't see the value of such change and the gain in the meaning.
I'm not necessarily against it meanwhile if we decide such change then we'd have to make it consistent across the all queries.

Copy link
Member

@ibolton336 ibolton336 Jul 27, 2023

Choose a reason for hiding this comment

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

Np - My main gripe here was the use of the 'any' type. Seems like since we are working on tech debt, it would be a good time to address. And by narrowing what we are passing from the response ( we aren't using the entire response), we can reduce complexity in the handlers which are using this param up the chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336, you had a good point with the any type.
This isn't the case anymore as there is no need to pass anything for now (see update) until we eventually address that later if we decide to pass object name to update queries.

Comment on lines 65 to 66
onSuccess: (res) => {
onSuccess(res);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onSuccess: (res) => {
onSuccess(res);
onSuccess: (_, vars) => {
onSuccess(vars.businessService.name);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336,

This seems to be out of scope, please see why here #1214 to following-up.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind not doing this. Just seemed like an easy solution that would help standardize notifications with more info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336, I agree but I would like to have an agreed overall approach to address this across the board.

@gildub gildub requested a review from ibolton336 July 27, 2023 11:18
@@ -35,7 +35,7 @@ export interface FormValues {
}

export interface BusinessServiceFormProps {
businessService?: BusinessService;
businessService: BusinessService | null;
Copy link
Member

Choose a reason for hiding this comment

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

This seems to go against what we have done across the app for optional props. Having the prop be undefined makes sense as it is omitted for new businessServices & doesn't need to be explicitly set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibolton336, I thought about that but this isn't an optional prop anymore as it was before.
The Form requires the businessService prop.
The modal state value provides either the object value itself or null:

const businessServiceToUpdate =
    createUpdateModalState !== "create" ? createUpdateModalState : null;

@gildub gildub requested a review from ibolton336 July 27, 2023 13:45
Signed-off-by: Gilles Dubreuil <gdubreui@redhat.com>
Signed-off-by: Gilles Dubreuil <gdubreui@redhat.com>
Signed-off-by: Gilles Dubreuil <gdubreui@redhat.com>
Signed-off-by: Gilles Dubreuil <gdubreui@redhat.com>
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