Remove optional chaining op on widget.fields

This commit is contained in:
Felix Cornelius 2024-11-19 22:38:18 +01:00
parent 63e07652a0
commit b4e9f096f3

View File

@ -10,18 +10,20 @@ export default function Component({ service }) {
} }
const MAX_ALLOWED_FIELDS = 4; const MAX_ALLOWED_FIELDS = 4;
if (widget.fields?.length > MAX_ALLOWED_FIELDS) { if (widget.fields.length > MAX_ALLOWED_FIELDS) {
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS); widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
} }
const { data: appsData, error: appsError } = useWidgetAPI(widget, "applications"); const { data: appsData, error: appsError } = useWidgetAPI(widget, "applications");
const appCounts = widget.fields?.map((status) => { const appCounts = widget.fields.map((status) => {
if (status === "apps") { if (status === "apps") {
return { status, count: appsData?.items?.length }; return { status, count: appsData?.items?.length };
} }
const count = appsData?.items?.filter( const count = appsData?.items?.filter(
(item) => item.status?.sync?.status.toLowerCase() === status.toLowerCase() || item.status?.health?.status.toLowerCase() === status.toLowerCase(), (item) =>
item.status?.sync?.status.toLowerCase() === status.toLowerCase() ||
item.status?.health?.status.toLowerCase() === status.toLowerCase(),
).length; ).length;
return { status, count }; return { status, count };
}); });
@ -33,7 +35,7 @@ export default function Component({ service }) {
if (!appsData) { if (!appsData) {
return ( return (
<Container service={service}> <Container service={service}>
{appCounts?.map((a) => ( {appCounts.map((a) => (
<Block label={`argocd.${a.status}`} key={a.status} /> <Block label={`argocd.${a.status}`} key={a.status} />
))} ))}
</Container> </Container>
@ -42,7 +44,7 @@ export default function Component({ service }) {
return ( return (
<Container service={service}> <Container service={service}>
{appCounts?.map((a) => ( {appCounts.map((a) => (
<Block label={`argocd.${a.status}`} key={a.status} value={a.count} /> <Block label={`argocd.${a.status}`} key={a.status} value={a.count} />
))} ))}
</Container> </Container>