diff --git a/public/app/features/alerting/unified/components/rules/CloudRules.tsx b/public/app/features/alerting/unified/components/rules/CloudRules.tsx index 05bd149c1a5..19a4ab98734 100644 --- a/public/app/features/alerting/unified/components/rules/CloudRules.tsx +++ b/public/app/features/alerting/unified/components/rules/CloudRules.tsx @@ -11,6 +11,7 @@ import { usePagination } from '../../hooks/usePagination'; import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector'; import { getPaginationStyles } from '../../styles/pagination'; import { getRulesDataSources, getRulesSourceUid } from '../../utils/datasource'; +import { isAsyncRequestStatePending } from '../../utils/redux'; import { RulesGroup } from './RulesGroup'; import { useCombinedGroupNamespace } from './useCombinedGroupNamespace'; @@ -29,10 +30,17 @@ export const CloudRules: FC = ({ namespaces, expandAll }) => { const groupsWithNamespaces = useCombinedGroupNamespace(namespaces); const dataSourcesLoading = useMemo( - () => rulesDataSources.filter((ds) => rules[ds.name]?.loading || dsConfigs[ds.name]?.loading), + () => + rulesDataSources.filter( + (ds) => isAsyncRequestStatePending(rules[ds.name]) || isAsyncRequestStatePending(dsConfigs[ds.name]) + ), [rules, dsConfigs, rulesDataSources] ); + const hasDataSourcesConfigured = rulesDataSources.length > 0; + const hasDataSourcesLoading = dataSourcesLoading.length > 0; + const hasNamespaces = namespaces.length > 0; + const { numberOfPages, onPageChange, page, pageItems } = usePagination( groupsWithNamespaces, 1, @@ -64,8 +72,10 @@ export const CloudRules: FC = ({ namespaces, expandAll }) => { /> ); })} - {namespaces?.length === 0 && !!rulesDataSources.length &&

No rules found.

} - {!rulesDataSources.length &&

There are no Prometheus or Loki data sources configured.

} + + {!hasDataSourcesConfigured &&

There are no Prometheus or Loki data sources configured.

} + {hasDataSourcesConfigured && !hasDataSourcesLoading && !hasNamespaces &&

No rules found.

} + (slice: AsyncRequestMapSlice) return Object.values(slice).some(isAsyncRequestStatePending); } -export function isAsyncRequestStatePending(state: AsyncRequestState): boolean { +export function isAsyncRequestStatePending(state?: AsyncRequestState): boolean { + if (!state) { + return false; + } + return state.dispatched && state.loading; }