fix: render heading immediately in MetricsPage before ctxLoading resolves#43
Conversation
…olves The heading 'Intel GPU — Metrics' was blocked behind the ctxLoading check, causing the E2E navigation test to timeout when navigating directly to /c/main/intel-gpu/metrics. The K8s.ResourceClasses.useList() hooks in IntelGpuDataContext can take time to resolve when navigating directly to the metrics route (as opposed to via sidebar), causing ctxLoading to remain true beyond the 15s test timeout. Fix: move SectionHeader outside the loading check so it renders immediately. The Loader now appears below the heading while waiting for context to load. Also disable the Refresh button during ctxLoading. Updated unit test to verify heading is visible even when ctxLoading=true. Fixes: headlamp-intel-gpu-plugin#42 Co-Authored-By: Paperclip <noreply@paperclip.ing>
There was a problem hiding this comment.
QA Code Review — PR #43 (fix/metrics-heading-renders-immediately)
Status: Code review PASSES — pending CI pass + E2E validation from Patty
Local verification
- Unit tests: 108/108 pass ✅
- TypeScript: Pre-existing errors only (same
vite-plugin-svgr/client/vite/clientmissing type definitions present onmain) ✅ - Diff review: Complete
Root cause analysis
The fix correctly addresses the issue. The original early-return pattern if (ctxLoading) { return <Loader> } prevented the SectionHeader from rendering until K8s.ResourceClasses.useList() hooks resolved in IntelGpuDataContext. On direct navigation to /metrics, this could exceed the 15s E2E timeout.
Change-by-change review
MetricsPage.tsx — heading moved outside ctxLoading guard ✅
SectionHeader title="Intel GPU — Metrics"now renders unconditionally. Correct fix.{ctxLoading && <Loader title="Loading Intel GPU data..." />}moved below the header section. The loader still appears while waiting for context — UX is preserved.- Refresh button:
disabled={fetching || ctxLoading}— prevents spurious fetches during loading. Correct. - Visual feedback:
opacity: 0.6+cursor: not-allowedwhen disabled. Good UX, uses CSS variables where appropriate.
Behavioral change note (non-blocking): MetricRequirements now renders during ctxLoading=true (previously hidden by the early return). MetricRequirements is static content — no context dependency — so this is benign. Worth knowing for future test additions.
MetricsPage.test.tsx — test updated ✅
- Test renamed and extended to assert
screen.getByText('Intel GPU — Metrics')is present whenctxLoading=true. Directly verifies the fix. - No test for
MetricRequirementsduring ctxLoading (minor gap, non-blocking for this PR).
Edge cases checked
- ctxLoading → false transition:
useEffect([ctxLoading, fetchSeq])fires whenctxLoadinggoes false, triggering fetch. This path is unchanged and still correct. - Double-loading state: When
ctxLoading=trueandfetching=true, only the ctxLoading loader shows (correct — fetch can't start until ctxLoading is false per the effect guard). - No regressions on other pages — diff is isolated to
MetricsPage.tsxand its test.
Blockers before approval
- CI must pass officially (current status:
action_required— no jobs executed, same workflow approval gate as previous PRs in this repo) - Pixel Patty must post E2E validation
Will return to formally approve once both are green.
QA Update — E2E Analysis (PRI-1016)E2E status: FAILED — but the failure is NOT caused by changes in this PR. Failure details
Why this PR cannot independently pass E2EThis PR only changes Circular dependency
Required actionOne of:
I cannot formally approve this PR until E2E passes. The code change itself is correct — I'm not requesting changes to the code. |
…ing selectors (combined)
|
Closing in favor of combined PR #45 which includes all three fixes. |
Summary
Fix E2E navigation test failure where the heading was never found within 15s timeout when navigating directly to
/c/main/intel-gpu/metrics.Root cause: The
SectionHeaderwas blocked behind thectxLoadingcheck in MetricsPage. When navigating directly to the metrics route (vs via sidebar), theK8s.ResourceClasses.useList()hooks inIntelGpuDataContextcan take time to resolve, causingctxLoadingto remaintruebeyond the test timeout.Fix: Move
SectionHeaderoutside the loading check so it renders immediately. TheLoadernow appears below the heading while waiting for context. Also disabled theRefreshbutton duringctxLoading.Changes
src/components/MetricsPage.tsx: Moved heading before loading check, added disabled/opacity styling to Refresh button during ctxLoadingsrc/components/MetricsPage.test.tsx: Updated test to verify heading is visible even when ctxLoading=trueTesting
navigation between plugin views worksshould now pass (specifically the/metricsstep)Fixes: headlamp-intel-gpu-plugin#42
cc @cpfarhood