diff --git a/public/app/features/alerting/unified/utils/redux.ts b/public/app/features/alerting/unified/utils/redux.ts index 693c0ccc2c3..7333116bf9a 100644 --- a/public/app/features/alerting/unified/utils/redux.ts +++ b/public/app/features/alerting/unified/utils/redux.ts @@ -157,6 +157,14 @@ export function messageFromError(e: Error | FetchError | SerializedError): strin return (e as Error)?.message || String(e); } +export function isAsyncRequestMapSliceSettled(slice: AsyncRequestMapSlice): boolean { + return Object.values(slice).every(isAsyncRequestStateSettled); +} + +export function isAsyncRequestStateSettled(state: AsyncRequestState): boolean { + return state.dispatched && !state.loading; +} + export function isAsyncRequestMapSliceFulfilled(slice: AsyncRequestMapSlice): boolean { return Object.values(slice).every(isAsyncRequestStateFulfilled); } diff --git a/public/app/plugins/panel/alertlist/GroupByWithLoading.tsx b/public/app/plugins/panel/alertlist/GroupByWithLoading.tsx index 672a54d4c30..56696d237c0 100644 --- a/public/app/plugins/panel/alertlist/GroupByWithLoading.tsx +++ b/public/app/plugins/panel/alertlist/GroupByWithLoading.tsx @@ -7,8 +7,8 @@ import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/ import { fetchAllPromRulesAction } from 'app/features/alerting/unified/state/actions'; import { getAllRulesSourceNames } from 'app/features/alerting/unified/utils/datasource'; import { - isAsyncRequestMapSliceFulfilled, isAsyncRequestMapSlicePending, + isAsyncRequestMapSliceSettled, } from 'app/features/alerting/unified/utils/redux'; import { useDispatch } from 'app/types'; import { AlertingRule } from 'app/types/unified-alerting'; @@ -33,7 +33,7 @@ export const GroupBy: FC = (props) => { const promRulesByDatasource = useUnifiedAlertingSelector((state) => state.promRules); const rulesDataSourceNames = useMemo(getAllRulesSourceNames, []); - const allRequestsReady = isAsyncRequestMapSliceFulfilled(promRulesByDatasource); + const allRequestsReady = isAsyncRequestMapSliceSettled(promRulesByDatasource); const loading = isAsyncRequestMapSlicePending(promRulesByDatasource); const labels = useMemo(() => {