Skip to content

Commit

Permalink
Notification parameters: Make inpage search usable
Browse files Browse the repository at this point in the history
CMK-19591

Change-Id: I9245fa4f4647e23ae68045a17e7b29ce48bda1b1
  • Loading branch information
makanakoeln committed Oct 24, 2024
1 parent b797717 commit 960c9ad
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
23 changes: 17 additions & 6 deletions cmk/gui/wato/pages/notifications/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import abc
import json
import re
import time
from collections.abc import Collection, Generator, Iterator, Mapping
from copy import deepcopy
Expand Down Expand Up @@ -3034,10 +3035,17 @@ def _get_parameter_rulesets(
self,
all_parameters: NotificationParameterSpecs,
) -> Generator[Rule]:
search_term = request.get_str_input("search", "")
search_term = search_term.lower() if search_term else ""
match_regex = re.compile(search_term, re.IGNORECASE)
for script_name, title in notification_script_choices():
# Not all notification scripts have parameters
if script_name not in notification_parameter_registry:
continue

if not match_regex.search(title):
continue

method_parameters: dict[NotificationParameterID, NotificationParameterItem] | None = (
all_parameters.get(script_name)
)
Expand All @@ -3056,18 +3064,21 @@ def _get_parameter_rulesets(

def _get_notification_parameters_data(self) -> NotificationParametersOverview:
all_parameters = NotificationParameterConfigFile().load_for_reading()
filtered_parameters = list(self._get_parameter_rulesets(all_parameters))
return NotificationParametersOverview(
parameters=[
RuleSection(
i18n=_("Parameters for"),
topics=[
RuleTopic(
i18n=None,
rules=list(self._get_parameter_rulesets(all_parameters)),
)
],
topics=[RuleTopic(i18n=None, rules=filtered_parameters)],
)
]
if filtered_parameters
else [],
i18n={
"no_parameter_match": _(
"Found no matching parameters. Please try another search term."
)
},
)


Expand Down
3 changes: 2 additions & 1 deletion cmk/gui/watolib/notification_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Optional
from typing import Any, Optional


@dataclass(kw_only=True)
Expand Down Expand Up @@ -94,6 +94,7 @@ class Notifications:
@dataclass(kw_only=True)
class NotificationParametersOverview:
parameters: list[RuleSection]
i18n: dict[str, Any]


@dataclass(kw_only=True)
Expand Down
3 changes: 2 additions & 1 deletion packages/cmk-frontend-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ function setupVue() {
}
case 'notification_parameters_overview': {
app = createApp(NotificationParametersOverviewApp, {
parameters: appData.parameters
parameters: appData.parameters,
i18n: appData.i18n
})
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ import type { RuleSection } from '@/notification/type_defs'

defineProps<{
parameters: RuleSection[]
i18n: Record<string, string>
}>()
</script>

<template>
<NotificationRules :rule_sections="parameters"></NotificationRules>
<NotificationRules v-if="parameters.length !== 0" :rule_sections="parameters"></NotificationRules>
<table v-else class="table ruleset">
<tbody>
<tr>
<td>
<div class="ruleset data odd0 no_match">
{{ i18n.no_parameter_match }}
</div>
</td>
</tr>
</tbody>
</table>
</template>

<style scoped></style>
1 change: 1 addition & 0 deletions packages/cmk-frontend-vue/src/notification/type_defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface Rule {
}
export interface NotificationParametersOverview {
parameters: RuleSection1[];
i18n: {};
}
export interface RuleSection1 {
i18n: string;
Expand Down
8 changes: 7 additions & 1 deletion packages/cmk-shared-typing/source/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@
"type": "object",
"$ref": "#/$defs/rule_section"
}
},
"i18n": {
"type": "object",
"no_parameter_match": {
"type": "string"
}
}
},
"required": ["parameters"]
"required": ["parameters", "i18n"]
},
"fallback_warning": {
"type": "object",
Expand Down

0 comments on commit 960c9ad

Please sign in to comment.