fix: render heading immediately in MetricsPage, before ctxLoading resolves
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>
This commit is contained in:
@@ -106,11 +106,13 @@ describe('MetricsPage', () => {
|
|||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows loader when ctxLoading=true', () => {
|
it('shows loader when ctxLoading=true but heading is visible immediately', () => {
|
||||||
vi.mocked(useIntelGpuContext).mockReturnValue(makeContext({ loading: true }));
|
vi.mocked(useIntelGpuContext).mockReturnValue(makeContext({ loading: true }));
|
||||||
// fetchGpuMetrics should never be called in loading state
|
// fetchGpuMetrics should never be called in loading state
|
||||||
vi.mocked(fetchGpuMetrics).mockResolvedValue(null);
|
vi.mocked(fetchGpuMetrics).mockResolvedValue(null);
|
||||||
render(<MetricsPage />);
|
render(<MetricsPage />);
|
||||||
|
// Heading renders immediately, loader appears below it while waiting for context
|
||||||
|
expect(screen.getByText('Intel GPU — Metrics')).toBeInTheDocument();
|
||||||
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Intel GPU data...');
|
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Intel GPU data...');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -230,10 +230,6 @@ export default function MetricsPage() {
|
|||||||
};
|
};
|
||||||
}, [ctxLoading, fetchSeq]);
|
}, [ctxLoading, fetchSeq]);
|
||||||
|
|
||||||
if (ctxLoading) {
|
|
||||||
return <Loader title="Loading Intel GPU data..." />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -247,7 +243,7 @@ export default function MetricsPage() {
|
|||||||
<SectionHeader title="Intel GPU — Metrics" />
|
<SectionHeader title="Intel GPU — Metrics" />
|
||||||
<button
|
<button
|
||||||
onClick={() => void doFetch()}
|
onClick={() => void doFetch()}
|
||||||
disabled={fetching}
|
disabled={fetching || ctxLoading}
|
||||||
aria-label="Refresh metrics"
|
aria-label="Refresh metrics"
|
||||||
style={{
|
style={{
|
||||||
padding: '6px 16px',
|
padding: '6px 16px',
|
||||||
@@ -255,15 +251,18 @@ export default function MetricsPage() {
|
|||||||
color: 'var(--mui-palette-primary-main, #0071c5)',
|
color: 'var(--mui-palette-primary-main, #0071c5)',
|
||||||
border: '1px solid var(--mui-palette-primary-main, #0071c5)',
|
border: '1px solid var(--mui-palette-primary-main, #0071c5)',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
cursor: 'pointer',
|
cursor: fetching || ctxLoading ? 'not-allowed' : 'pointer',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
|
opacity: fetching || ctxLoading ? 0.6 : 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{fetching ? 'Refreshing…' : 'Refresh'}
|
{fetching ? 'Refreshing…' : 'Refresh'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{ctxLoading && <Loader title="Loading Intel GPU data..." />}
|
||||||
|
|
||||||
<MetricRequirements />
|
<MetricRequirements />
|
||||||
|
|
||||||
{fetching && !metrics && <Loader title="Querying Prometheus for GPU metrics..." />}
|
{fetching && !metrics && <Loader title="Querying Prometheus for GPU metrics..." />}
|
||||||
|
|||||||
Reference in New Issue
Block a user