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

Adds ability to request inventory report. (PP-1236) #110

Merged
merged 16 commits into from
May 22, 2024

Conversation

tdilauro
Copy link
Contributor

@tdilauro tdilauro commented May 20, 2024

Description

  • Adds the ability to request an inventory report with "eligible" (as defined by the backend) collections for a library.
  • Introduces react-query (@tanstack/react-query) to the project. This will give us a path away from Redux and allow us to start making the distinction between client app state and server synchronization.
  • Adds the componentWithProviders and renderWithProviders helpers to make it easier to test with all of of our providers. It can be extended to include our Redux provider, once it's needed.

Motivation and Context

We need a way for users to trigger the inventory reports now available via the backend.

[Jira PP-1236]

How Has This Been Tested?

  • Manual testing in local dev environment against both local backend and against the AWS-hosted development server.
  • Updated some existing tests.
  • Add new tests for the new component.
  • All tests pass locally.

Checklist:

  • N/A - I have updated the documentation accordingly.
  • All new and existing tests passed.

@tdilauro tdilauro requested a review from ray-lee May 20, 2024 17:57
Copy link
Contributor

@ray-lee ray-lee left a comment

Choose a reason for hiding this comment

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

This looks fine to me. I made a few non-blocking suggestions, if only to prove that I actually read all the code. 😁

? UNKNOWN_COLLECTIONS_MESSAGE
: collections.length === 0
? NO_COLLECTIONS_MESSAGE
: SOME_COLLECTIONS_MESSAGE;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of nesting ternary operators. An extra level of indent on the inner branches might help.

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'm pretty sure I had this indented. I think eslint undid it. I'll try again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, eslint is doing this in the pre-commit hook.

I must admit that I am a fan of the ternary, even in its nested form and I prefer it over if/else if/else and switch/case alternatives in this scenario. It makes it super clear that one thing is getting assigned/returned here and that there is nothing else to keep track of.

: SOME_COLLECTIONS_MESSAGE;
const collectionList = (collections: InventoryReportCollectionInfo[]) => {
return (
collections?.length > 0 && (
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to look up what happens when you compare null/undefined with 0, and this does in fact work, but you could also remove > 0, since null, undefined, and 0 are all falsy. That might be less alarming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯! DOH!

/>,
{ queryClient }
);
container.querySelector(".modal-content");
Copy link
Contributor

@ray-lee ray-lee May 21, 2024

Choose a reason for hiding this comment

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

Does this do anything? It's in some of the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. No, it wasn't doing anything. I removed it. I was able to do what I needed with getAllByRole and queryAllByRole on the "dialog" role.

const heading = within(modalContent).getByRole("heading", {
level: MODAL_HEADING_LEVEL,
});
const modalBody = modalContent.querySelector(".modal-body");
Copy link
Contributor

@ray-lee ray-lee May 21, 2024

Choose a reason for hiding this comment

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

I feel like there should be a better (more RTL) way than querying for the class name, but I'm not sure what would be an appropriate role. I guess you could do getByText instead, but I don't see an easy way to exclude the text from being in the heading, which maybe you want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was trying to distinguish this from the heading text. I used the more RTL queries whenever I could.

{ queryClient }
);
container.querySelector(".modal-content");
const modalContent = getByRole("document");
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like getByRole("dialog") should be in here somewhere, since that would be the distinguishing characteristic of what you're looking for. But I don't know if react-bootstrap is setting that role.

Copy link
Contributor Author

@tdilauro tdilauro May 22, 2024

Choose a reason for hiding this comment

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

I did try using that initially, but it wasn't working, so I took a different tack. I did manage to sort out some of the other problems I was having, so I'll take another look at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that there are two elements with the "dialog" role, which I had somehow missed before. I switched to getAllByRole and queryAllByRole to resolve this and streamlined the tests in the process.

@tdilauro tdilauro merged commit e910982 into main May 22, 2024
1 check passed
@tdilauro tdilauro deleted the feature/request-inventory-report branch May 22, 2024 21:00
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