From 194dbead830c90ef10cf608ab6ebd16b29a600b8 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 27 Feb 2023 17:58:52 +0100 Subject: [PATCH] [v9.4.x] Alerting: Fix available labels in the alert panel groupby dropdown (#63799) Alerting: Fix available labels in the alert panel groupby dropdown (#63573) (cherry picked from commit 5f35995cd411a55645fe106c3cc0f7982835bda3) Co-authored-by: Konrad Lalik --- public/app/features/alerting/unified/utils/redux.ts | 8 ++++++++ public/app/plugins/panel/alertlist/GroupByWithLoading.tsx | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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(() => {