Compare commits

...

1 Commits

4 changed files with 24 additions and 9 deletions

View File

@@ -33,6 +33,9 @@ interface Props {
viewMode: ViewMode; viewMode: ViewMode;
} }
const NoGroupPrefix = 'no_group_for_rule_';
const isNoGroup = (group: string) => group.startsWith(NoGroupPrefix);
export const RulesGroup = React.memo(({ group, namespace, expandAll, viewMode }: Props) => { export const RulesGroup = React.memo(({ group, namespace, expandAll, viewMode }: Props) => {
const { rulesSource } = namespace; const { rulesSource } = namespace;
const rulesSourceName = getRulesSourceName(rulesSource); const rulesSourceName = getRulesSourceName(rulesSource);
@@ -164,11 +167,14 @@ export const RulesGroup = React.memo(({ group, namespace, expandAll, viewMode }:
} }
// ungrouped rules are rules that are in the "default" group name // ungrouped rules are rules that are in the "default" group name
const groupName = isListView ? ( let groupName = <RuleLocation namespace={decodeGrafanaNamespace(namespace).name} group={group.name} />;
<RuleLocation namespace={decodeGrafanaNamespace(namespace).name} /> if (isListView) {
) : ( groupName = <RuleLocation namespace={decodeGrafanaNamespace(namespace).name} />;
<RuleLocation namespace={decodeGrafanaNamespace(namespace).name} group={group.name} /> } else if (isNoGroup(group.name)) {
groupName = (
<RuleLocation namespace={decodeGrafanaNamespace(namespace).name} group={`${group.rules[0].name} (Ungrouped)`} />
); );
}
return ( return (
<div className={styles.wrapper} data-testid="rule-group"> <div className={styles.wrapper} data-testid="rule-group">

View File

@@ -147,6 +147,9 @@ interface GrafanaRuleGroupListItemProps {
namespaceName: string; namespaceName: string;
} }
const NoGroupPrefix = 'no_group_for_rule_';
const isNoGroup = (group: string) => group.startsWith(NoGroupPrefix);
export function GrafanaRuleGroupListItem({ group, namespaceName }: GrafanaRuleGroupListItemProps) { export function GrafanaRuleGroupListItem({ group, namespaceName }: GrafanaRuleGroupListItemProps) {
const groupIdentifier: GrafanaRuleGroupIdentifier = useMemo( const groupIdentifier: GrafanaRuleGroupIdentifier = useMemo(
() => ({ () => ({
@@ -161,10 +164,12 @@ export function GrafanaRuleGroupListItem({ group, namespaceName }: GrafanaRuleGr
const detailsLink = groups.detailsPageLink(GRAFANA_RULES_SOURCE_NAME, group.folderUid, group.name); const detailsLink = groups.detailsPageLink(GRAFANA_RULES_SOURCE_NAME, group.folderUid, group.name);
const groupDisplayName = isNoGroup(group.name) ? `${group.rules[0].name} (Ungrouped)` : group.name;
return ( return (
<ListGroup <ListGroup
key={group.name} key={group.name}
name={group.name} name={groupDisplayName}
metaRight={<GroupIntervalIndicator seconds={group.interval} />} metaRight={<GroupIntervalIndicator seconds={group.interval} />}
href={detailsLink} href={detailsLink}
isOpen={false} isOpen={false}

View File

@@ -12,9 +12,13 @@ interface RuleLocationProps {
application?: RulesSourceApplication; application?: RulesSourceApplication;
} }
const NoGroupPrefix = 'no_group_for_rule_';
const isNoGroup = (group: string) => group.startsWith(NoGroupPrefix);
export function RuleLocation({ namespace, group, groupUrl, rulesSource, application }: RuleLocationProps) { export function RuleLocation({ namespace, group, groupUrl, rulesSource, application }: RuleLocationProps) {
const isGrafanaApp = application === 'grafana'; const isGrafanaApp = application === 'grafana';
const isDataSourceApp = !!rulesSource && !!application && !isGrafanaApp; const isDataSourceApp = !!rulesSource && !!application && !isGrafanaApp;
const groupText = isNoGroup(group) ? 'Ungrouped' : group;
return ( return (
<Stack direction="row" alignItems="center" gap={0.5}> <Stack direction="row" alignItems="center" gap={0.5}>
@@ -32,10 +36,10 @@ export function RuleLocation({ namespace, group, groupUrl, rulesSource, applicat
<Icon size="sm" name="angle-right" /> <Icon size="sm" name="angle-right" />
{groupUrl ? ( {groupUrl ? (
<TextLink href={groupUrl} color="secondary" variant="bodySmall" inline={false}> <TextLink href={groupUrl} color="secondary" variant="bodySmall" inline={false}>
{group} {groupText}
</TextLink> </TextLink>
) : ( ) : (
group groupText
)} )}
</Stack> </Stack>
</Stack> </Stack>