Skip to content

OBPIH-5926 / OBPIH-6206 Delete product source preference records#4534

Merged
awalkowiak merged 14 commits intofeature/product-supplier-list-redesignfrom
OBPIH-5926
Mar 7, 2024
Merged

OBPIH-5926 / OBPIH-6206 Delete product source preference records#4534
awalkowiak merged 14 commits intofeature/product-supplier-list-redesignfrom
OBPIH-5926

Conversation

@alannadolny
Copy link
Collaborator

No description provided.


const afterDelete = () => {
setValue('defaultPreferenceType', emptyPreferenceType);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

not a must have, but I just feel like 27-41 lines could also be included in the hook you've created.
Another not "must have" (because it won't impact the performance at all) is that the emptyPreferenceType could be outside of the component, because its body never changes when a re-render happens (it is not dependent on the component life cycle)

Copy link
Collaborator

Choose a reason for hiding this comment

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

or forget about this comment - I didn't realize you have different implementations of that depending on whether it is the default preference type or the table.


const isPreferenceTypeEmpty = !_.some(
Object.values(_.omit(preferenceTypeData || {}, 'id')),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't it be cleaner to do it using isEmpty?

const isPreferenceTypeEmpty = _.isEmpty(_.omit(preferenceTypeData || {}, 'id'))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not the same.
As an empty preferenceType, we are considering { bidName: '', validityStartDate: '', ... }

  1. isEmpty
    In this case, this function returns false because it checks if the object has any keys (it has, but with empty values)
  2. some + Object.values
    In this case, we are taking only the values of the keys, so it gives us an array like that ['', '', ...] and then we are checking the truthiness of this array, and because of the fact every value in this array is falsy, the whole array is also falsy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, my bad, didn't understand the context before your explanation.

if (preferenceTypeData?.id) {
await productSupplierApi.deleteProductSupplierPreference(preferenceTypeData?.id);
}
afterDelete?.();
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we eventually don't call the delete (because of the if above), should we call the afterDelete anyway, or should it be inside the if also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, because if the row doesn't have the ID, it means it is a new row, so we don't have to make an API call, but we still would like to clear \ remove this row.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks, this is what I wanted to hear

useDeletePreferenceType.propTypes = {
preferenceTypeData: PropTypes.shape({}),
afterDelete: PropTypes.func.isRequired,
isDefaultPreferenceType: PropTypes.bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't you miss onCancel here?

updatedRows,
triggerValidation,
}) => {
const [selectedRow, setSelectedRow] = useState(null);
Copy link
Collaborator

@kchelstowski kchelstowski Mar 7, 2024

Choose a reason for hiding this comment

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

let's add index to the name (or add a comment above that it is index of a row).

@awalkowiak awalkowiak merged commit acb9a39 into feature/product-supplier-list-redesign Mar 7, 2024
@awalkowiak awalkowiak deleted the OBPIH-5926 branch March 7, 2024 10:18
awalkowiak pushed a commit that referenced this pull request Mar 12, 2024
* OBPIH-5926 Add translations

* OBPIH-5926 Add function for resetting inputted values

* OBPIH-5926 Adjust styling

* OBPIH-5926 Create hook for deleting preferenceType

* OBPIH-6206 Add new translations

* OBPIH-6206 Fix product supplier urls

* OBPIH-6206 Export function for resetting default preference type

* OBPIH-6206 Fix attributes styling

* OBPIH-6206 Add new param to components

* OBPIH-6206 Adjust hook for deleting preference types within the table

* OBPIH-6206 Use the hook in table

* OBPIH-6206 Remove unused property

* OBPIH-6206 Split imports into new lines

* OBPIH-6206 Add onCancel to propTypes and rename selectedRow variable
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