Fix frontend API integration: correct endpoint and data transformation

- Change getProjects() to call /api/bzzz/active-repos instead of /projects
- Transform Bzzz repository response structure from nested {repositories: [...]} to flat array
- Map repository fields to Project interface with status field (ready_to_claim -> active/inactive)
- Remove defensive array checks since API now returns proper array structure
- Fix TypeError: r.filter is not a function by ensuring proper data flow

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
anthonyrawlins
2025-07-14 22:29:11 +10:00
parent 8a2e6b42dc
commit 2b5e6a492d
4 changed files with 57 additions and 41 deletions

File diff suppressed because one or more lines are too long

View File

@@ -61,7 +61,7 @@
} }
} }
</style> </style>
<script type="module" crossorigin src="/assets/index-S7T45P97.js"></script> <script type="module" crossorigin src="/assets/index-f7xYn9lw.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CYSOVan7.css"> <link rel="stylesheet" crossorigin href="/assets/index-CYSOVan7.css">
</head> </head>
<body> <body>

View File

@@ -45,18 +45,15 @@ export default function Dashboard() {
queryFn: () => clusterApi.getWorkflows() queryFn: () => clusterApi.getWorkflows()
}); });
// Calculate stats from real data - ensure arrays exist // Calculate stats from real data
const projectsArray = Array.isArray(projects) ? projects : [];
const workflowsArray = Array.isArray(workflows) ? workflows : [];
const stats = { const stats = {
projects: { projects: {
total: projectsArray.length, total: projects.length,
active: projectsArray.filter(p => p.status === 'active').length active: projects.filter(p => p.status === 'active').length
}, },
workflows: { workflows: {
total: workflowsArray.length, total: workflows.length,
active: workflowsArray.filter((w: any) => w.active).length active: workflows.filter((w: any) => w.active).length
}, },
cluster: { cluster: {
total_nodes: clusterOverview?.total_nodes || 0, total_nodes: clusterOverview?.total_nodes || 0,

View File

@@ -41,10 +41,29 @@ api.interceptors.response.use(
// Project API // Project API
export const projectApi = { export const projectApi = {
// Get all projects // Get all projects (from Bzzz active repos)
getProjects: async (): Promise<Project[]> => { getProjects: async (): Promise<Project[]> => {
const response = await api.get('/projects'); const response = await api.get('/api/bzzz/active-repos');
return response.data; // Transform Bzzz repository objects to Project objects with status
if (response.data && response.data.repositories) {
return response.data.repositories.map((repo: any) => ({
id: repo.project_id,
name: repo.name,
description: `${repo.name} - ${repo.owner}/${repo.repository}`,
status: repo.ready_to_claim ? 'active' : 'inactive',
git_url: repo.git_url,
owner: repo.owner,
repository: repo.repository,
branch: repo.branch,
bzzz_enabled: repo.bzzz_enabled,
ready_to_claim: repo.ready_to_claim,
private_repo: repo.private_repo,
github_token_required: repo.github_token_required,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString()
}));
}
return [];
}, },
// Get a single project by ID // Get a single project by ID