Premium Analytics: add Stats endpoint foundation - #49886
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
This comment has been minimized.
This comment has been minimized.
|
Claude finished @kangzj's task in 2m 22s —— View job PR Review: Premium Analytics — Stats endpoint foundation
This is a clean, well-scoped foundation PR. The helpers mirror existing patterns ( 🟠 Inconsistent (and lossy)
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Claude finished @kangzj's task in 1m 18s —— View job Re-review: Premium Analytics — Stats endpoint foundation
The ✅
|
Review-cycle summary -
|
| Source | Comment | Resolution |
|---|---|---|
| claude[bot] | #4787142134 | Unified enabled handling, reused UseStatsOptions, documented app query namespace, and added focused coverage. |
Unaddressed human feedback: None.
CI: all required checks passing.
| }; | ||
| } | ||
|
|
||
| export function getStatsLabel( value: unknown ): string { |
There was a problem hiding this comment.
This function only seems to be used in tests, or is it supposed to be used elsewhere too?
There was a problem hiding this comment.
It is a foundation helper consumed by the endpoint-level normalizer PRs that build on this one — getStatsLabel is called from the archives, devices, and generic-list normalizers (it URL-decodes stats item labels with a safe fallback). No consumers live on this branch yet since this PR only lands the shared helpers; the tests exercise the decode/fallback behavior in the meantime.
Nikschavan
left a comment
There was a problem hiding this comment.
Thank you, this looks good. Added two questions
| return options?.enabled === undefined | ||
| ? queryOptions.enabled | ||
| : options.enabled && queryOptions.enabled !== false; |
There was a problem hiding this comment.
queryOptions.enabled can be a function predicate (TanStack Query v5 supports boolean | ((query) => boolean)), but options.enabled && queryOptions.enabled !== false always collapses to a boolean — so when a caller passes a function and options.enabled is truthy, the predicate gets silently replaced with true and the conditional gating is lost. We can keep the same "either side can disable" behavior while passing the original enabled through untouched:
| return options?.enabled === undefined | |
| ? queryOptions.enabled | |
| : options.enabled && queryOptions.enabled !== false; | |
| return options?.enabled === false ? false : queryOptions.enabled; |
There was a problem hiding this comment.
Good catch — fixed in f8a5765. Switched to return options?.enabled === false ? false : queryOptions.enabled; so a queryOptions.enabled function predicate is passed through untouched and only an explicit caller enabled: false forces a disable. The "either side can disable" truth table is unchanged (existing tests still pass) and I added a case pinning the predicate-preservation behavior.
queryOptions.enabled can be a TanStack predicate (boolean | (query) => boolean), but the AND-collapse turned a passed predicate into a plain true whenever the caller flag was truthy, dropping the gating. Pass queryOptions.enabled through untouched and only let an explicit caller enabled:false force a disable.
Fixes #
Proposed changes
Related product discussion/links
Does this pull request change what data or activity we track or use?
No. This adds shared client-side helpers only.
Testing instructions
pnpm --dir projects/packages/premium-analytics typecheck.pnpm --dir projects/packages/premium-analytics build.