import { css } from '@emotion/css'; import pluralize from 'pluralize'; import React, { FC, useMemo } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { LoadingPlaceholder, useStyles2 } from '@grafana/ui'; import { CombinedRuleNamespace } from 'app/types/unified-alerting'; import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector'; import { getRulesDataSources, getRulesSourceName } from '../../utils/datasource'; import { RulesGroup } from './RulesGroup'; interface Props { namespaces: CombinedRuleNamespace[]; expandAll: boolean; } export const CloudRules: FC = ({ namespaces, expandAll }) => { const styles = useStyles2(getStyles); const dsConfigs = useUnifiedAlertingSelector((state) => state.dataSources); const rules = useUnifiedAlertingSelector((state) => state.promRules); const rulesDataSources = useMemo(getRulesDataSources, []); const dataSourcesLoading = useMemo( () => rulesDataSources.filter((ds) => rules[ds.name]?.loading || dsConfigs[ds.name]?.loading), [rules, dsConfigs, rulesDataSources] ); return (
Mimir / Cortex / Loki
{dataSourcesLoading.length ? ( ) : (
)}
{namespaces.map((namespace) => { const { groups, rulesSource } = namespace; return groups.map((group) => ( )); })} {namespaces?.length === 0 && !!rulesDataSources.length &&

No rules found.

} {!rulesDataSources.length &&

There are no Prometheus or Loki datas sources configured.

}
); }; const getStyles = (theme: GrafanaTheme2) => ({ loader: css` margin-bottom: 0; `, sectionHeader: css` display: flex; justify-content: space-between; `, wrapper: css` margin-bottom: ${theme.v1.spacing.xl}; `, });