Skip to content

Commit 31b0489

Browse files
authored
UI overhaul (#69)
1 parent 5fe10c3 commit 31b0489

File tree

27 files changed

+3535
-2940
lines changed

27 files changed

+3535
-2940
lines changed

app/api/evaluations/[id]/route.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export async function GET(
3737
const fileContent = fs.readFileSync(filePath, 'utf-8');
3838
const mockData = JSON.parse(fileContent);
3939

40-
console.log(`[MOCK MODE] Returning mock data for ID ${id} from ${mockFileName}`);
4140
return NextResponse.json(mockData, { status: 200 });
4241
} catch (err) {
4342
console.error('Error reading mock data:', err);
@@ -61,8 +60,6 @@ export async function GET(
6160
url.searchParams.set('resync_score', resyncScore);
6261
url.searchParams.set('export_format', exportFormat);
6362

64-
console.log(`[REAL BACKEND] Fetching evaluation ${id} from ${url.toString()}`);
65-
6663
const response = await fetch(url.toString(), {
6764
method: 'GET',
6865
headers: {
@@ -90,7 +87,6 @@ export async function GET(
9087
);
9188
}
9289

93-
console.log(`[REAL BACKEND] Successfully fetched evaluation ${id}`);
9490
return NextResponse.json(data, { status: 200 });
9591
} catch (error: any) {
9692
console.error('Proxy error:', error);

app/api/evaluations/datasets/[dataset_id]/route.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
import { NextRequest, NextResponse } from 'next/server';
22

3+
/**
4+
* GET /api/evaluations/datasets/:dataset_id
5+
*
6+
* Proxy endpoint to get dataset details (with optional signed URL).
7+
*/
8+
export async function GET(
9+
request: NextRequest,
10+
{ params }: { params: Promise<{ dataset_id: string }> }
11+
) {
12+
try {
13+
const apiKey = request.headers.get('X-API-KEY');
14+
if (!apiKey) {
15+
return NextResponse.json({ error: 'Missing X-API-KEY header' }, { status: 401 });
16+
}
17+
18+
const { dataset_id } = await params;
19+
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
20+
const searchParams = request.nextUrl.searchParams.toString();
21+
const queryString = searchParams ? `?${searchParams}` : '';
22+
23+
const response = await fetch(`${backendUrl}/api/v1/evaluations/datasets/${dataset_id}${queryString}`, {
24+
method: 'GET',
25+
headers: { 'X-API-KEY': apiKey },
26+
});
27+
28+
const data = await response.json();
29+
if (!response.ok) {
30+
return NextResponse.json(data, { status: response.status });
31+
}
32+
33+
// If fetch_content=true, download the CSV from the signed URL and return it
34+
const fetchContent = request.nextUrl.searchParams.get('fetch_content');
35+
if (fetchContent === 'true') {
36+
const signedUrl = data?.data?.signed_url || data?.signed_url;
37+
if (!signedUrl) {
38+
return NextResponse.json({ error: 'No signed URL available' }, { status: 404 });
39+
}
40+
const csvResponse = await fetch(signedUrl);
41+
if (!csvResponse.ok) {
42+
return NextResponse.json({ error: 'Failed to fetch CSV file' }, { status: 502 });
43+
}
44+
const csvText = await csvResponse.text();
45+
return NextResponse.json({ ...data, csv_content: csvText }, { status: 200 });
46+
}
47+
48+
return NextResponse.json(data, { status: 200 });
49+
} catch (error: any) {
50+
console.error('Proxy error:', error);
51+
return NextResponse.json(
52+
{ error: 'Failed to forward request to backend', details: error.message },
53+
{ status: 500 }
54+
);
55+
}
56+
}
57+
358
/**
459
* DELETE /api/evaluations/datasets/:dataset_id
560
*

app/api/evaluations/route.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,6 @@ export async function GET(request: NextRequest) {
2222

2323
const data = await response.json();
2424

25-
// Log the structure to help debug score visibility issues
26-
//TODO Fix it later
27-
if (data && Array.isArray(data)) {
28-
console.log('[GET /api/evaluations] Sample evaluation structure:', {
29-
firstItem: data[0] ? {
30-
id: data[0].id,
31-
hasScore: !!data[0].score,
32-
hasScores: !!data[0].scores,
33-
scoreKeys: data[0].score ? Object.keys(data[0].score) : [],
34-
scoresKeys: data[0].scores ? Object.keys(data[0].scores) : []
35-
} : 'No items'
36-
});
37-
} else if (data && data.data && Array.isArray(data.data)) {
38-
console.log('[GET /api/evaluations] Sample evaluation structure (nested):', {
39-
firstItem: data.data[0] ? {
40-
id: data.data[0].id,
41-
hasScore: !!data.data[0].score,
42-
hasScores: !!data.data[0].scores,
43-
scoreKeys: data.data[0].score ? Object.keys(data.data[0].score) : [],
44-
scoresKeys: data.data[0].scores ? Object.keys(data.data[0].scores) : []
45-
} : 'No items'
46-
});
47-
}
48-
4925
return NextResponse.json(data, { status: response.status });
5026
} catch (error) {
5127
console.error('Proxy error:', error);

app/api/evaluations/stt/datasets/[dataset_id]/route.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ export async function GET(
1616
}
1717

1818
try {
19-
// Get query parameters from the request
19+
// Forward all query parameters to the backend
2020
const { searchParams } = new URL(request.url);
21-
const includeSamples = searchParams.get('include_samples');
22-
const includeAudio = searchParams.get('include_audio');
23-
24-
// Build backend URL with query parameters
2521
const backendParams = new URLSearchParams();
26-
if (includeSamples) backendParams.append('include_samples', includeSamples);
27-
if (includeAudio) backendParams.append('include_audio', includeAudio);
22+
for (const [key, value] of searchParams.entries()) {
23+
backendParams.append(key, value);
24+
}
25+
const queryString = backendParams.toString() ? `?${backendParams.toString()}` : '';
2826

29-
const backendUrlWithParams = `${backendUrl}/api/v1/evaluations/stt/datasets/${dataset_id}${backendParams.toString() ? `?${backendParams.toString()}` : ''
30-
}`;
27+
const backendUrlWithParams = `${backendUrl}/api/v1/evaluations/stt/datasets/${dataset_id}${queryString}`;
3128

3229
const response = await fetch(backendUrlWithParams, {
3330
headers: {
@@ -43,4 +40,29 @@ export async function GET(
4340
{ status: 500 }
4441
);
4542
}
43+
}
44+
45+
export async function DELETE(
46+
request: Request,
47+
{ params }: { params: Promise<{ dataset_id: string }> }
48+
) {
49+
const { dataset_id } = await params;
50+
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
51+
const apiKey = request.headers.get('X-API-KEY');
52+
53+
if (!apiKey) {
54+
return NextResponse.json({ success: false, error: 'Unauthorized: Missing API key' }, { status: 401 });
55+
}
56+
57+
try {
58+
const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/datasets/${dataset_id}`, {
59+
method: 'DELETE',
60+
headers: { 'X-API-KEY': apiKey },
61+
});
62+
let data;
63+
try { data = await response.json(); } catch { data = { success: true }; }
64+
return NextResponse.json(data, { status: response.ok ? 200 : response.status });
65+
} catch (error: any) {
66+
return NextResponse.json({ success: false, error: 'Failed to delete dataset', details: error.message }, { status: 500 });
67+
}
4668
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export async function PATCH(
4+
request: Request,
5+
{ params }: { params: Promise<{ sample_id: string }> }
6+
) {
7+
const { sample_id } = await params;
8+
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
9+
const apiKey = request.headers.get('X-API-KEY');
10+
11+
if (!apiKey) {
12+
return NextResponse.json(
13+
{ success: false, error: 'Unauthorized: Missing API key' },
14+
{ status: 401 }
15+
);
16+
}
17+
18+
try {
19+
const body = await request.json();
20+
21+
const response = await fetch(
22+
`${backendUrl}/api/v1/evaluations/stt/samples/${sample_id}`,
23+
{
24+
method: 'PATCH',
25+
headers: {
26+
'X-API-KEY': apiKey,
27+
'Content-Type': 'application/json',
28+
},
29+
body: JSON.stringify(body),
30+
}
31+
);
32+
33+
let data;
34+
try {
35+
data = await response.json();
36+
} catch {
37+
data = { success: response.ok };
38+
}
39+
return NextResponse.json(data, { status: response.status });
40+
} catch (error: any) {
41+
console.error('Sample update error:', error);
42+
return NextResponse.json(
43+
{ success: false, error: 'Failed to update sample', details: error.message },
44+
{ status: 500 }
45+
);
46+
}
47+
}

app/api/evaluations/tts/datasets/[dataset_id]/route.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,40 @@ export async function GET(
1616
}
1717

1818
try {
19-
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets/${dataset_id}`, {
19+
// Forward query parameters to the backend
20+
const { searchParams } = new URL(request.url);
21+
const backendParams = new URLSearchParams();
22+
for (const [key, value] of searchParams.entries()) {
23+
backendParams.append(key, value);
24+
}
25+
const queryString = backendParams.toString() ? `?${backendParams.toString()}` : '';
26+
27+
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets/${dataset_id}${queryString}`, {
2028
headers: {
2129
'X-API-KEY': apiKey,
2230
},
2331
});
2432

2533
const data = await response.json();
34+
if (!response.ok) {
35+
return NextResponse.json(data, { status: response.status });
36+
}
37+
38+
// If fetch_content=true, download the CSV from the signed URL and return it
39+
const fetchContent = new URL(request.url).searchParams.get('fetch_content');
40+
if (fetchContent === 'true') {
41+
const signedUrl = data?.data?.signed_url || data?.signed_url;
42+
if (!signedUrl) {
43+
return NextResponse.json({ error: 'No signed URL available' }, { status: 404 });
44+
}
45+
const csvResponse = await fetch(signedUrl);
46+
if (!csvResponse.ok) {
47+
return NextResponse.json({ error: 'Failed to fetch CSV file' }, { status: 502 });
48+
}
49+
const csvText = await csvResponse.text();
50+
return NextResponse.json({ ...data, csv_content: csvText }, { status: 200 });
51+
}
52+
2653
return NextResponse.json(data, { status: response.status });
2754
} catch (error) {
2855
return NextResponse.json(
@@ -31,3 +58,28 @@ export async function GET(
3158
);
3259
}
3360
}
61+
62+
export async function DELETE(
63+
request: Request,
64+
{ params }: { params: Promise<{ dataset_id: string }> }
65+
) {
66+
const { dataset_id } = await params;
67+
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
68+
const apiKey = request.headers.get('X-API-KEY');
69+
70+
if (!apiKey) {
71+
return NextResponse.json({ success: false, error: 'Unauthorized: Missing API key' }, { status: 401 });
72+
}
73+
74+
try {
75+
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets/${dataset_id}`, {
76+
method: 'DELETE',
77+
headers: { 'X-API-KEY': apiKey },
78+
});
79+
let data;
80+
try { data = await response.json(); } catch { data = { success: true }; }
81+
return NextResponse.json(data, { status: response.ok ? 200 : response.status });
82+
} catch (error: any) {
83+
return NextResponse.json({ success: false, error: 'Failed to delete dataset', details: error.message }, { status: 500 });
84+
}
85+
}

app/components/ComingSoon.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,10 @@ export default function ComingSoon({ featureName, description }: ComingSoonProps
5555
</h1>
5656

5757
<div
58-
className="inline-block px-4 py-2 rounded-full mb-6"
59-
style={{
60-
backgroundColor: '#fef3c7',
61-
borderWidth: '1px',
62-
borderColor: '#fde68a'
63-
}}
58+
className="inline-block px-4 py-2 rounded-full mb-6 bg-[#fef3c7] border border-[#fde68a]"
6459
>
6560
<p
66-
className="text-sm font-semibold"
67-
style={{ color: '#92400e' }}
61+
className="text-sm font-semibold text-[#92400e]"
6862
>
6963
🚧 Being Brewed
7064
</p>

0 commit comments

Comments
 (0)