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

Only show five inbox messages and add "Show more" button #35003

Merged
merged 11 commits into from Oct 13, 2022

Conversation

joelclimbsthings
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

Reducing initial inbox messages to only display 5 messages, and adding the "show more" button to load another 10 messages at a time.

Closes #34927 .

How to test the changes in this Pull Request:

  1. Checkout branch
  2. Ensure you have more than 15 inbox notes in your store (use WCA Test Helper to create more if need be)
  3. Go to Homescreen.
  4. You should only see 5 notes, with the "Show older" button at the bottom.
  5. Click the button, and it should load 10 more.
  6. The button should still remain at the bottom (if you have enough notes) and it should now read "Show more."
  7. Dismiss any note, and it should disappear, loading one more at the end of the list.
  8. Hit the "undo" button after dismissing a note, and it should reappear.
  9. The button and Footer section should disappear after all notes have been loaded.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> run changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. release: highlight Issues that have a high user impact and need to be discussed/paid attention to. labels Oct 7, 2022
@joelclimbsthings joelclimbsthings marked this pull request as draft October 7, 2022 22:40
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

Test Results Summary

Commit SHA: 1a9ba6e

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests18800201900m 56s
E2E Tests634240738m 8s

⚠️ Warning

Please address the following issues prior to merging this pull request:
  • FAILED/BROKEN TESTS. There were failed and/or broken API and E2E tests.
  • INCOMPLETE E2E TEST RUN. We have a total of 189 E2E tests, but only 73 were executed. Note that in CI, E2E tests automatically end when they encounter too many failures.

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

DEFAULT_INBOX_QUERY.per_page
);
const [ allNotesFetched, setAllNotesFetched ] = useState( false );
const [ allNotes, setAllNotes ] = useState( [] );
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 used to store fetched notes, since we don't want them all to disappear (as happens with the returned notes variable with useSelect) while fetching more notes. This results in a much better UI experience.

@@ -238,15 +299,17 @@ const InboxPanel = ( { showHeader = true } ) => {

const noteId = note.id;
try {
removeNote( noteId );
await removeNote( noteId );
invalidateResolutionForStoreSelector( 'getNotes' );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems we need to invalidate the data selector manually; I'm assuming this is due to the the fact that we're changing the inbox query with each request, but I haven't gotten too deep into this. Let me know if you see a more elegant way to manage this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense, I don't think there is a much better way around this at the moment, unless we add a new selector or change the selector to either ignore per_page prop when returning the items, or use a separate selector that just returns all the notes.
But this is fine!

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 think this will result in the simplest way to give the "rolling" notes appearance as we dismiss/etc notes. I'll keep it as is for the moment.

@joelclimbsthings joelclimbsthings self-assigned this Oct 7, 2022
@joelclimbsthings joelclimbsthings requested a review from a team October 7, 2022 23:45
@joelclimbsthings joelclimbsthings marked this pull request as ready for review October 7, 2022 23:46
@github-actions github-actions bot removed the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Oct 12, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @joelclimbsthings, this tested well. I did leave several comments within the code, not all of my suggestions are a must.
Given this would need to be in for the code freeze, the biggest item for me is having to use the notesHash thing, if we could remove that then I would be happy.
I was wondering what exact scenarios you needed the hash for?
And curious if just removing the map call within the useSelect will remove the need of having to use the hash?

plugins/woocommerce-admin/client/inbox-panel/index.js Outdated Show resolved Hide resolved
quantity_shown: allNotes.length,
} );
setNoteDisplayQty(
noteDisplayQty + ADD_NOTES_AMOUNT
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of relying on the noteDisplayQty state to re-trigger the useSelect hook, would it make more sense to remove the useSelect hook and use resolveSelect instead?
This allows you to run the getNotes selector just like apiFetch and it returns a promise, like so:
resolveSelect( NOTES_STORE_NAME ).getNotes( inboxQuery ).then( (notes) => setAllNotes(notes)

I am not opposed to the useSelect but given the extra functionality I wonder if useSelect would help simplify some of the logic, especially around when to set the all notes state.

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've greatly simplified the useSelect() in the last commit, so I don't believe we'd see much benefit from this change. I haven't used resolveSelect(), so I appreciate the insight!

@@ -238,15 +299,17 @@ const InboxPanel = ( { showHeader = true } ) => {

const noteId = note.id;
try {
removeNote( noteId );
await removeNote( noteId );
invalidateResolutionForStoreSelector( 'getNotes' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense, I don't think there is a much better way around this at the moment, unless we add a new selector or change the selector to either ignore per_page prop when returning the items, or use a separate selector that just returns all the notes.
But this is fine!

plugins/woocommerce-admin/client/inbox-panel/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

One minor suggestion for the lint error, but otherwise this looks great and tested well!

@@ -142,59 +178,78 @@ const renderNotes = ( {
);
} ) }
</TransitionGroup>
{ allNotesFetched ? null : notesHaveResolved ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Nested ternary expressions is not like by lint.
Maybe splitting this into two separate conditions would be the best?

Or could we show the InboxNotePlaceholder when allNotesFetched is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, not sure how I feel about that particular rule, but I've remedied this in 9516508.

louwie17
louwie17 previously approved these changes Oct 12, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @joelclimbsthings, this looks good and it tested well, nice work!!

@AnnaMag AnnaMag added this to the 7.1.0 milestone Oct 13, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the test Joel, and I checked the E2E tests, they do not seem to be related. I saw the same one's fail in several other PRs.
I will merge this for you.

@louwie17 louwie17 merged commit 315e163 into trunk Oct 13, 2022
@louwie17 louwie17 deleted the update/34927-inbox-expansion branch October 13, 2022 11:36
@github-actions
Copy link
Contributor

github-actions bot commented Oct 13, 2022

Hi @louwie17, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

@louwie17 louwie17 added the release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] label Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: inbox plugin: woocommerce Issues related to the WooCommerce Core plugin. release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the limit from 25 to 5 and allow users to load more messages
3 participants