Skip to content

Commit

Permalink
Limit fields to max 4 and valid statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
fcornelius committed Nov 19, 2024
1 parent 55dd26c commit 5f11951
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/widgets/services/argocd.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: ArgoCD Widget Configuration

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

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

```yaml
widget:
Expand Down
12 changes: 11 additions & 1 deletion src/widgets/argocd/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { widget } = service;

// Limits fields to available statuses
const validFields = ["apps", "synced", "outOfSync", "healthy", "progressing", "degraded", "suspended", "missing"]
widget.fields = widget.fields.filter(field => validFields.includes(field))

// Limits max number of displayed fields
const MAX_ALLOWED_FIELDS = 4;
if (widget.fields != null && widget.fields.length > MAX_ALLOWED_FIELDS) {
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
}

const { data: appsData, error: appsError } = useWidgetAPI(widget, "applications");

const appCounts = ["apps", "synced", "outOfSync", "healthy", "progressing", "degraded", "suspended", "missing"].map(
const appCounts = widget.fields.map(
(status) => {
if (status === "apps") {
return { status, count: appsData?.items?.length };
Expand Down

0 comments on commit 5f11951

Please sign in to comment.