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>
<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">
</head>
<body>

View File

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

View File

@@ -41,10 +41,29 @@ api.interceptors.response.use(
// Project API
export const projectApi = {
// Get all projects
// Get all projects (from Bzzz active repos)
getProjects: async (): Promise<Project[]> => {
const response = await api.get('/projects');
return response.data;
const response = await api.get('/api/bzzz/active-repos');
// 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