Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared useAsync<T> React hook for standardizing async data/loading/error state handling with stale-request cancellation, and migrates a couple of existing hooks to validate the approach.
Changes:
- Added generic
useAsynchook with request-id-based stale request cancellation andreset(). - Added dedicated unit tests for
useAsync(success, error, cancellation, args passthrough, reset, unmount behavior). - Refactored
useChartDataandusePipelineRunsto useuseAsyncand remove bespoke cancellation/boilerplate.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| plugins/aks-desktop/src/hooks/useAsync.ts | New shared async state hook with cancellation + reset. |
| plugins/aks-desktop/src/hooks/useAsync.test.ts | Unit tests validating useAsync behavior. |
| plugins/aks-desktop/src/components/Scaling/hooks/useChartData.ts | Migrates chart data fetching/caching hook to useAsync. |
| plugins/aks-desktop/src/components/Deployments/hooks/usePipelineRuns.ts | Migrates GitHub pipeline runs hook to useAsync. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/Scaling/hooks/useChartData.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Deployments/hooks/usePipelineRuns.ts
Outdated
Show resolved
Hide resolved
4b91cbb to
3f2841c
Compare
3f2841c to
f40e9bb
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/Deployments/hooks/usePipelineRuns.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Scaling/hooks/useChartData.ts
Outdated
Show resolved
Hide resolved
f40e9bb to
aab9ed4
Compare
Provides a reusable hook that handles loading, error, and data state for async operations with race-condition protection and unmount safety. Supports both immediate (run on mount) and deferred (manual execute) modes with type-safe overloads.
Replaces hand-rolled loading/error/staleness logic with useAsync, removing ~60 lines of boilerplate while preserving caching and Prometheus query behavior.
aab9ed4 to
4d0ccda
Compare
4d0ccda to
1965ca9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaces manual signal-based cancellation and state management with useAsync, simplifying the hook while preserving partial-failure handling and sorted/truncated results.
1965ca9 to
1391ffb
Compare
Summary
Closes #533
useAsync<T>hook (src/hooks/useAsync.ts) that encapsulates the loading/error/datauseStatepattern with built-in request-ID-based cancellation, used by 12+ hooks across the codebaseuseChartDataandusePipelineRunsas proof-of-concept consumers, reducing boilerplate by ~90 linesDetails
The hook provides:
data,loading,errorstate managementexecute(...args)for manual triggeringreset()to clear stateTest plan
npm run tscpasses (pre-existing guidepup module errors only)npm test -- --runpasses (pre-existing failures only)npx vitest run src/hooks/useAsync.test.ts— 7/7 tests pass