Skip to content

Commit 388ec4e

Browse files
committed
Limit fields to max 4 and valid statuses
1 parent 55dd26c commit 388ec4e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docs/widgets/services/argocd.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: ArgoCD Widget Configuration
55

66
Learn more about [ArgoCD](https://argo-cd.readthedocs.io/en/stable/).
77

8-
Allowed fields: `["apps", "synced", "outOfSync", "healthy", "progressing", "degraded", "suspended", "missing"]`
8+
Allowed fields (limited to a max of 4): `["apps", "synced", "outOfSync", "healthy", "progressing", "degraded", "suspended", "missing"]`
99

1010
```yaml
1111
widget:

src/widgets/argocd/component.jsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
55
export default function Component({ service }) {
66
const { widget } = service;
77

8+
// Limits fields to available statuses
9+
const validFields = ["apps", "synced", "outOfSync", "healthy", "progressing", "degraded", "suspended", "missing"]
10+
widget.fields = widget.fields.filter(field => validFields.includes(field))
11+
12+
// Limits max number of displayed fields
13+
const MAX_ALLOWED_FIELDS = 4;
14+
if (widget.fields != null && widget.fields.length > MAX_ALLOWED_FIELDS) {
15+
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
16+
}
17+
818
const { data: appsData, error: appsError } = useWidgetAPI(widget, "applications");
919

10-
const appCounts = ["apps", "synced", "outOfSync", "healthy", "progressing", "degraded", "suspended", "missing"].map(
20+
const appCounts = widget.fields.map(
1121
(status) => {
1222
if (status === "apps") {
1323
return { status, count: appsData?.items?.length };

0 commit comments

Comments
 (0)