Open tomalec opened 3 years ago
@jconroy The solution doesn't seem straightforward to me, I'm not sure if we can finish the potentially new UI, and data flow shortly. So, I'm not sure where to assign it to our project boards.
Here are a few fast but not 100% clean workarounds, I can think of:
per_page
to the maximum, to reduce the risk of our early adopters facing the issue.I'll wait to see what the team thinks on this one
Assume the per_size
affects both intervals
and products
/programs
, I think we would not have any easy way to deal it with wp-data
. To minimize duplicate API requests and to display correct information to users as soon as possible, the approach I have in mind so far is:
createRegistrySelector
that just like the getReport, for selecting all intervals
. This new selector still using the getReportByApiQuery
inside to avoid increasing API requestsintervals
in another separated node in the data store of the reducer. The new selector uses this separated node to retrieve complete intervals
data as well.isFulfilled
to the getReportByApiQuery
resolver. Usage example I pushed in a draft branch - https://github.com/woocommerce/google-listings-and-ads/blob/df042aa0fc1a1dfb34635b4d9c5ab1128c61d750/js/src/data/resolvers.js#L87-L89But the downside of this approach is that it adds more complexity to the way we use wp-data
.
Unfortunately, I do not have any sample data, and mocking it with our simplistic mocking hook, is not possible.
I have the same problem. 😂 There are some difficulties in verifying the feasibility and complete the implementation in the absence of actual data. Is there any chance we can at least have the mock data to simulate it?
do you have an idea how to mimic that behavior on the server-side, so JS could receive many "pages" for a single query?
I was hoping to be able to just read the parameters from the request. By adding the second parameter to the filter you get access to the request which can be used to mimic any type of response. For example if in the file mocks/mc/reports/programs.json
you add a page token like:
"test_next_page": "pagetwo"
Then add a second file with report data called mocks/mc/reports/programs-pagetwo.json
You can then use a snippet like this to make sure it returns the right response file:
add_filter(
'gla_prepared_response_mc-reports-programs',
function( $response, $request ) {
$file = 'programs.json';
if ( ! empty( $request['test_next_page'] ) ) {
$file = "programs-{$request['test_next_page']}.json";
}
return json_decode( file_get_contents( __DIR__ . '/google-listings-and-ads/tests/mocks/mc/reports/' . $file ), true ) ?: [];
},
10,
2
);
The problem with this technique is that it doesn't prevent the "real" request from happening. So we can't use the actual parameter "next_page" and have to rename it to "test_next_page". I'm going to try and see if there is a better way to mock the data but for initial testing you should manage to get by using this technique.
I created a PR for mocked report responses here https://github.com/woocommerce/google-listings-and-ads/pull/659 The free listings program report has an example how it can return multiple pages.
We discussed it today on Dev call, the general summary was:
per_page
is correlated to the amount of data we receive, but there is no 1:1 direct information on if there are any more products|programs
or intervals
to be fetched.Given the free listings reports, API is flaky it would be nice to have an error solution as in https://github.com/woocommerce/google-listings-and-ads/issues/270 done first, so we could act on errors coming for individual pages.
Describe the bug:
Unfortunately, the paging of Google reports API data does not match the "pagination" concept of our
woocommerce/components
.As stated in https://github.com/woocommerce/google-listings-and-ads/issues/589#issuecomment-839724571 the fact, we asked for
10
results, doesn't mean we will have full data for10
products, or10
intervals. This means, that to populate the data fields in our UI, we would have to keep on requesting fornext_page
s until we have them all.We can limit the problem by increasing
per_page
to quite a large number, so the majority of merchants would be served by a single request and not "chunked" experience. But still, there may be a case that after waiting (already few sec.) for the first chunk of data, a merchant will need to wait for more to come.We have to adapt our data utils, UI, and UX for that:
next_page
property and do not perform any subsequent requests. We need to fetch another page if available.intervals
as they come https://github.com/woocommerce/google-listings-and-ads/issues/589Expected behavior:
I should eventually see the complete report data.
Actual behavior:
If the dataset is big enough, I would see only the first chunk
Steps to reproduce:
Unfortunately, I do not have any sample data, and mocking it with our simplistic mocking hook, is not possible.
@mikkamp, do you have an idea how to mimic that behavior on the server-side, so JS could receive many "pages" for a single query?
Additional details:
@eason9487 , @ecgan do you have some ideas what would be the easiest,/best way to implement that
next_page
flow with ourwp-data
stores?