mirror of
https://github.com/SigNoz/signoz.git
synced 2026-08-30 00:00:36 +01:00
Some checks failed
build-staging / prepare (push) Has been cancelled
build-staging / js-build (push) Has been cancelled
build-staging / go-build (push) Has been cancelled
build-staging / staging (push) Has been cancelled
cacheci / tests (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
## Pull Request --- ### 📄 Summary > Why does this change exist? > What problem does it solve, and why is this the right approach? These are pending code that was supposed to be deleted after Infrastructure Monitoring & Alert History adopt the QBv5. #### Issues closed by this PR > Reference issues using `Closes #issue-number` to enable automatic closure on merge. Closes https://github.com/SigNoz/engineering-pod/issues/5117 Closes https://github.com/SigNoz/engineering-pod/issues/5116 --- ### ✅ Change Type _Select all that apply_ - [ ] ✨ Feature - [ ] 🐛 Bug fix - [x] ♻️ Refactor - [ ] 🛠️ Infra / Tooling - [ ] 🧪 Test-only --- ### 🧪 Testing Strategy > How was this change validated? - Tests added/updated: Yes - Manual verification: - - Edge cases covered: - --- ### ⚠️ Risk & Impact Assessment > What could break? How do we recover? - Blast radius: Query Builder - Potential regressions: Deleting more code than needed - Rollback plan: Revert the deletion. --- ### 📝 Changelog > Fill only if this affects users, APIs, UI, or documented behavior > Use **N/A** for internal or non-user-facing changes | Field | Value | |------|-------| | Deployment Type | Cloud / OSS / Enterprise | | Change Type | Maintenance | | Description | N/A | --- ### 📋 Checklist - [x] Tests added or explicitly not required - [x] Manually tested - [ ] Breaking changes documented - [ ] Backward compatibility considered
36 lines
914 B
TypeScript
36 lines
914 B
TypeScript
import { useRef } from 'react';
|
|
|
|
export type UseStableTotalCountParams = {
|
|
total: number | undefined;
|
|
isLoading: boolean;
|
|
/**
|
|
* Identifies the list being counted. When it changes, the cached count is
|
|
* dropped so the previous list's page count cannot outlive it.
|
|
*/
|
|
resetKey: string | undefined;
|
|
};
|
|
|
|
/**
|
|
* Holds on to the last non-zero total so the pagination does not flash while the
|
|
* same list refetches, and forgets it as soon as `resetKey` moves to another list.
|
|
*/
|
|
export function useStableTotalCount({
|
|
total,
|
|
isLoading,
|
|
resetKey,
|
|
}: UseStableTotalCountParams): number {
|
|
const prevTotalRef = useRef(total || 0);
|
|
const prevResetKeyRef = useRef(resetKey);
|
|
|
|
if (prevResetKeyRef.current !== resetKey) {
|
|
prevResetKeyRef.current = resetKey;
|
|
prevTotalRef.current = 0;
|
|
}
|
|
|
|
if (total && total > 0) {
|
|
prevTotalRef.current = total;
|
|
}
|
|
|
|
return isLoading ? prevTotalRef.current : total || 0;
|
|
}
|