Alerting: Fix available labels in the alert panel groupby dropdown (#63573)

This commit is contained in:
Konrad Lalik 2023-02-27 14:48:05 +01:00 committed by GitHub
parent 2372b7c626
commit 5f35995cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -157,6 +157,14 @@ export function messageFromError(e: Error | FetchError | SerializedError): strin
return (e as Error)?.message || String(e); return (e as Error)?.message || String(e);
} }
export function isAsyncRequestMapSliceSettled<T>(slice: AsyncRequestMapSlice<T>): boolean {
return Object.values(slice).every(isAsyncRequestStateSettled);
}
export function isAsyncRequestStateSettled<T>(state: AsyncRequestState<T>): boolean {
return state.dispatched && !state.loading;
}
export function isAsyncRequestMapSliceFulfilled<T>(slice: AsyncRequestMapSlice<T>): boolean { export function isAsyncRequestMapSliceFulfilled<T>(slice: AsyncRequestMapSlice<T>): boolean {
return Object.values(slice).every(isAsyncRequestStateFulfilled); return Object.values(slice).every(isAsyncRequestStateFulfilled);
} }

View File

@ -7,8 +7,8 @@ import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/
import { fetchAllPromRulesAction } from 'app/features/alerting/unified/state/actions'; import { fetchAllPromRulesAction } from 'app/features/alerting/unified/state/actions';
import { getAllRulesSourceNames } from 'app/features/alerting/unified/utils/datasource'; import { getAllRulesSourceNames } from 'app/features/alerting/unified/utils/datasource';
import { import {
isAsyncRequestMapSliceFulfilled,
isAsyncRequestMapSlicePending, isAsyncRequestMapSlicePending,
isAsyncRequestMapSliceSettled,
} from 'app/features/alerting/unified/utils/redux'; } from 'app/features/alerting/unified/utils/redux';
import { useDispatch } from 'app/types'; import { useDispatch } from 'app/types';
import { AlertingRule } from 'app/types/unified-alerting'; import { AlertingRule } from 'app/types/unified-alerting';
@ -33,7 +33,7 @@ export const GroupBy: FC<Props> = (props) => {
const promRulesByDatasource = useUnifiedAlertingSelector((state) => state.promRules); const promRulesByDatasource = useUnifiedAlertingSelector((state) => state.promRules);
const rulesDataSourceNames = useMemo(getAllRulesSourceNames, []); const rulesDataSourceNames = useMemo(getAllRulesSourceNames, []);
const allRequestsReady = isAsyncRequestMapSliceFulfilled(promRulesByDatasource); const allRequestsReady = isAsyncRequestMapSliceSettled(promRulesByDatasource);
const loading = isAsyncRequestMapSlicePending(promRulesByDatasource); const loading = isAsyncRequestMapSlicePending(promRulesByDatasource);
const labels = useMemo(() => { const labels = useMemo(() => {