-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fix pagination issue with dispute count in task list on overview page #4388
Conversation
This looks good @shendy-a8c - we'll need a
|
6e00906
to
2891483
Compare
Yes @haszari. Thank you for making sure. |
70dd8c4
to
a9a8876
Compare
Thank you @Jinksi for adding testing instructions in this PR's description. Very much appreciated! |
I want to point out that some changes in this PR:
Are also fixed in #4414. The plan is to merge #4414 and rebase this PR on to Also, I wonder, since the task list is behind a feature flag, customers haven't seen it yet. I have a doubt that we should add any changelog entry but decided to add something. Let me know if we shouldn't include a changelog entry. |
@shendy-a8c I've been testing using node 12.22.6 as per Line 1 in 496176b
|
I try not to change the behavior of the task list, ie:
|
Ah. Thank you for pointing that out. I should have used the same node version as defined in |
This PR is ready for a review. |
@shendy-a8c I feel like this behaviour should change only to show the disputes task if there are disputes awaiting a response. Therefore, the task wouldn't show as completed or be "completable", it would simply not appear. Merchants with a large number of disputes (of any status) could see an enormous value in the completed task message, e.g. But this might be out of the scope of this PR, what do you think? |
Good point. Do you think we need to loop in product or design person or just call it? Your argument makes sense though. The minor drawback (or maybe not even a drawback) is that we will never have completed dispute-related task. It''d be either showing when incomplete or not showing at all when completed. |
If you agree, I'm leaning towards calling it. The large number in the completed task could be seen as a bug 🤔 Most other tasks in this list are automatically hidden when completed too, e.g. woocommerce-payments/client/overview/task-list/tasks.js Lines 85 to 90 in 18900e2
To clarify, I think that the disputes task should only display if there are one or more disputes awaiting a response. This is also the approach used in the WC → Home disputes task PR. |
I've found another bug if we keep the task in a completed state: clicking it directs me to the disputes page with the |
18900e2
to
161b210
Compare
Sounds good. I have rebased on to |
I've stumbled upon this Fatal Error when upgrading a JN site from WCPay 4.4.0 to this branch (zipped via
Maybe
|
@shendy-a8c I have a fix for the Fatal Error mentioned in #4388 (comment). I opened a parallel branch ( |
@Jinksi I took a look at the fatal error. Sorry for messing with your JN site but I can now also reproduce the problem consistently in a separate JN site. I find these conditions need to be met to get the fatal error:
I don't think the problem is caused by a null I think somehow the old version of I modified
Then Then, I modify this branch:
I then install I see some logging in Here's the log:
|
Regarding your fix, it does fix the problem but it's moving away from dependency injection approach. What do you think if we make the 2nd argument of |
Looks like similar case happened before when the constructor arguments of classes loaded from This reported problem is caused by this change. Not sure if it's a problem specific to WCPay. |
I tried to reproduce by creating a simple WordPress plugin and it's not behaving the same. That and the fact it only happens if store is already onboarded, I think this problem is specific to WCPay and not a problem within WP's plugin updater, so I filed a new issue. |
Apologies if this is throwing a large spanner in the works late into the piece but would it be simpler to inject the number of disputes into the JS rather than fetch it via an API request? For example these changes seem to be working for me locally. diff --git a/client/overview/index.js b/client/overview/index.js
index 551adb1d..99c5ea6e 100644
--- a/client/overview/index.js
+++ b/client/overview/index.js
@@ -34,6 +34,7 @@ const OverviewPage = () => {
wpcomReconnectUrl,
featureFlags: { accountOverviewTaskList },
needsHttpsSetup,
+ disputesNeedingResponse,
} = wcpaySettings;
const { disputes, isLoading } = useDisputes( getQuery() );
const { isLoading: settingsIsLoading, settings } = useSettings();
@@ -43,7 +44,7 @@ const OverviewPage = () => {
showUpdateDetailsTask,
wpcomReconnectUrl,
needsHttpsSetup,
- disputes,
+ disputesNeedingResponse,
} );
const tasks =
Array.isArray( tasksUnsorted ) && tasksUnsorted.sort( taskSort );
diff --git a/client/overview/task-list/tasks.js b/client/overview/task-list/tasks.js
index 8d892e46..4bf8f54d 100644
--- a/client/overview/task-list/tasks.js
+++ b/client/overview/task-list/tasks.js
@@ -31,15 +31,15 @@ export const getTasks = ( {
wpcomReconnectUrl,
isAccountOverviewTasksEnabled,
needsHttpsSetup,
- disputes = [],
+ disputesNeedingResponse,
} ) => {
const { status, currentDeadline, pastDue, accountLink } = accountStatus;
const accountRestrictedSoon = 'restricted_soon' === status;
const accountDetailsPastDue = 'restricted' === status && pastDue;
let accountDetailsTaskDescription;
- const isDisputeTaskVisible = 0 < disputes.length;
- const disputesToResolve = getDisputesToResolve( disputes );
+ const isDisputeTaskVisible = 0 < disputesNeedingResponse;
+ const disputesToResolve = disputesNeedingResponse;
if ( accountRestrictedSoon ) {
accountDetailsTaskDescription = sprintf(
@@ -138,7 +138,7 @@ export const getTasks = ( {
disputesToResolve,
'woocommerce-payments'
),
- disputesToResolve ? disputesToResolve : disputes.length
+ disputesToResolve ? disputesToResolve : disputesNeedingResponse
),
additionalInfo: disputesToResolve
? __( 'View and respond', 'woocommerce-payments' )
diff --git a/includes/admin/class-wc-payments-admin.php b/includes/admin/class-wc-payments-admin.php
index 9bd855eb..0833dab3 100644
--- a/includes/admin/class-wc-payments-admin.php
+++ b/includes/admin/class-wc-payments-admin.php
@@ -490,6 +490,7 @@ class WC_Payments_Admin {
'currentUserEmail' => $current_user_email,
'currencyData' => $currency_data,
'restUrl' => get_rest_url( null, '' ), // rest url to concatenate when merchant use Plain permalinks.
+ 'disputesNeedingResponse' => $this->get_disputes_awaiting_response_count(),
];
wp_localize_script( |
…are valid statuses.
… the number of disputes that need response to the task list on the overview page.
…e task list. - Remove accepting parameter statuses in dispute/status_counts API. - Fix task list unit test.
…iting_response disputes list filter is done in another PR, #4414.
…ty of the sentence in dispute task list and use the number of total disputes if there is 0 dispute needing response.
…ySettings instead of fetching it asynchronously from the frontend.
c9afffc
to
15fc78f
Compare
Thank you so much for the fresh approach from totally different angle, @james-allan. It does simplify things a lot. Also, as a bonus, we can avoid the fatal error talked about above! Also, it felt so good avoiding adding bunch of new lines. One little tiny drawback with this approach is that status counts will be passed on every WCPay menu page loads, not just the Overview page where it's used, which is fine because it's cached data. Another thing I found out is that wp_localize_script() will convert any value to string here, so I rebased onto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for me.
I:
- Confirmed the paging issue on
develop
where more than 25 disputes needing a response results in an incorrect number. - Confirmed this branch fixed it.
- Tested accepting a dispute and it being updated etc.
One other hidden benefit of this count being cached and injected in to the JS, is that the task loads instantly on the page, on develop, the task list was pretty slow to render because of all the querying and filtering going on.
💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 🥇 I've tested upgrading from WCPay 4.4.0 and the Fatal Error is no longer a concern.
I've also tested the task when 2, 1 and 0 disputes are awaiting a response, all working as expected.
Fixes #4123.
Changes proposed in this Pull Request
On Payments > Overview page, we display a task to open the awaiting response dispute list under the
Things to do
list. Before this PR, we're getting a list of disputes and count the ones that need response to get the number in the task. This PR takes a different approach by calling a REST API to get a list of dispute statuses and their counts, solving the problem where awating response disputes got buried in the page 2+.Testing instructions
Make sure to enable
Enable account overview task list
in WCPay Dev because the task list / 'Things to do' is behind a feature flag.You will need >25 disputed WCPay transactions. Do this by purchasing products multiple times with either of the following cards (tip: save the cards when checking out to reduce repetitive card number form inputs) :
4000000000001976
4000000000000259
Checkout the
trunk
branch.Visit Payments → Overview and observe the disputes task in the Things to do task list. Notice that the # of disputed payments is incorrect. An easy way to check is to compare with the Disputes badge in the admin menu:
Checkout this PR branch
fix/4123-dispute-count
and runnpm run build:client
Visit Payments → Overview and observe the disputes task in the Things to do task list. Notice that the # of disputed payments correct:
Notes
npm run test:js
locally with nodejs 16.npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge