Skip to content

Commit d6c5c6c

Browse files
committed
feat: add alerting rules tab to dev console
Signed-off-by: Gabriel Bernal <[email protected]>
1 parent cc50389 commit d6c5c6c

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

web/console-extensions.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@
170170
}
171171
}
172172
},
173+
{
174+
"type": "console.tab",
175+
"properties": {
176+
"contextId": "dev-console-observe",
177+
"name": "%plugin__monitoring-plugin~Alerting Rules%",
178+
"href": "alertrules",
179+
"component": {
180+
"$codeRef": "AlertRulesPage"
181+
}
182+
}
183+
},
173184
{
174185
"type": "console.redux-reducer",
175186
"properties": {
@@ -261,9 +272,7 @@
261272
"type": "console.page/route",
262273
"properties": {
263274
"exact": false,
264-
"path": [
265-
"/virt-monitoring"
266-
],
275+
"path": ["/virt-monitoring"],
267276
"component": { "$codeRef": "AlertingPage" }
268277
}
269278
},

web/src/components/alerting/AlertRulesDetailsPage.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import { formatPrometheusDuration } from '../console/console-shared/src/datetime
5858
import { ExternalLink } from '../console/utils/link';
5959
import {
6060
getAlertRulesUrl,
61-
getAlertsUrl,
6261
getAlertUrl,
6362
getLegacyObserveState,
6463
getNewSilenceAlertUrl,
@@ -187,16 +186,9 @@ const AlertRulesDetailsPage_: React.FC = () => {
187186
<PageGroup>
188187
<PageBreadcrumb hasBodyWrapper={false}>
189188
<Breadcrumb>
190-
{perspective === 'dev' && (
191-
<BreadcrumbItem>
192-
<Link to={getAlertsUrl(perspective, namespace)}>{t('Alerts')}</Link>
193-
</BreadcrumbItem>
194-
)}
195-
{perspective !== 'dev' && (
196-
<BreadcrumbItem>
197-
<Link to={getAlertRulesUrl(perspective)}>{t('Alerting rules')}</Link>
198-
</BreadcrumbItem>
199-
)}
189+
<BreadcrumbItem>
190+
<Link to={getAlertRulesUrl(perspective, namespace)}>{t('Alerting rules')}</Link>
191+
</BreadcrumbItem>
200192
<BreadcrumbItem isActive>{t('Alerting rule details')}</BreadcrumbItem>
201193
</Breadcrumb>
202194
</PageBreadcrumb>

web/src/components/alerting/AlertRulesPage.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
RowProps,
88
Rule,
99
TableColumn,
10+
useActiveNamespace,
1011
useListPageFilter,
1112
VirtualizedTable,
1213
} from '@openshift-console/dynamic-plugin-sdk';
@@ -96,7 +97,7 @@ const RuleTableRow: React.FC<RowProps<Rule>> = ({ obj }) => {
9697
<ResourceIcon kind={RuleResource.kind} />
9798
</FlexItem>
9899
<FlexItem>
99-
<Link to={getRuleUrl(perspective, obj)}>
100+
<Link to={getRuleUrl(perspective, obj, obj.labels.namespace)}>
100101
<Truncate content={obj.name} />
101102
</Link>
102103
</FlexItem>
@@ -118,6 +119,7 @@ const RuleTableRow: React.FC<RowProps<Rule>> = ({ obj }) => {
118119
const AlertRulesPage_: React.FC = () => {
119120
const { t } = useTranslation(process.env.I18N_NAMESPACE);
120121
const { alertsKey, silencesKey, rulesKey, perspective, defaultAlertTenant } = usePerspective();
122+
const [namespace] = useActiveNamespace();
121123

122124
useAlertsPoller();
123125

@@ -137,6 +139,14 @@ const AlertRulesPage_: React.FC = () => {
137139
[data],
138140
);
139141

142+
const namespacedData = React.useMemo(() => {
143+
if (perspective === 'dev') {
144+
return data?.filter((rule) => rule.labels?.namespace === namespace);
145+
}
146+
147+
return data;
148+
}, [data, perspective, namespace]);
149+
140150
const rowFilters: RowFilter[] = [
141151
// TODO: The "name" filter doesn't really fit useListPageFilter's idea of a RowFilter, but
142152
// useListPageFilter doesn't yet provide a better way to add a filter like this
@@ -163,7 +173,7 @@ const AlertRulesPage_: React.FC = () => {
163173
},
164174
];
165175

166-
const [staticData, filteredData, onFilterChange] = useListPageFilter(data, rowFilters);
176+
const [staticData, filteredData, onFilterChange] = useListPageFilter(namespacedData, rowFilters);
167177

168178
const columns = React.useMemo<TableColumn<Rule>[]>(
169179
() => [

web/src/components/hooks/usePerspective.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,14 @@ export const getAlertsUrl = (perspective: Perspective, namespace?: string) => {
125125
};
126126

127127
// There is no equivalent rules list page in the developer perspective
128-
export const getAlertRulesUrl = (perspective: Perspective) => {
128+
export const getAlertRulesUrl = (perspective: Perspective, namespace?: string) => {
129129
switch (perspective) {
130130
case 'acm':
131131
return `/multicloud${RuleResource.plural}`;
132132
case 'virtualization-perspective':
133133
return `/virt-monitoring/alertrules`;
134+
case 'dev':
135+
return `/dev-monitoring/ns/${namespace}/alertrules`;
134136
case 'admin':
135137
default:
136138
return RuleResource.plural;

0 commit comments

Comments
 (0)