feat: added initial export of participant/annotation-data
This commit is contained in:
58
src/components/ExportAllParticipantDataButton.tsx
Normal file
58
src/components/ExportAllParticipantDataButton.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
'use client';
|
||||
|
||||
import { exportAllParticipantDataAsZip } from '@/app/actions/participants';
|
||||
import { useState } from 'react';
|
||||
|
||||
interface ExportAllParticipantDataButtonProps {
|
||||
experimentId: number;
|
||||
}
|
||||
|
||||
export default function ExportAllParticipantDataButton({
|
||||
experimentId,
|
||||
}: ExportAllParticipantDataButtonProps) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const { base64Data, filename } = await exportAllParticipantDataAsZip(experimentId);
|
||||
|
||||
// Convert base64 back to Blob
|
||||
const binaryString = atob(base64Data);
|
||||
const bytes = new Uint8Array(binaryString.length);
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
const blob = new Blob([bytes], { type: 'application/zip' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to export data');
|
||||
console.error('Export error:', err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<button
|
||||
onClick={handleExport}
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
{isLoading ? 'Exporting...' : 'Export all Data as ZIP'}
|
||||
</button>
|
||||
{error && <div className="text-red-600 text-sm">{error}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
55
src/components/ExportParticipantDataButton.tsx
Normal file
55
src/components/ExportParticipantDataButton.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
'use client';
|
||||
|
||||
import { exportParticipantDataAsJson } from '@/app/actions/participants';
|
||||
import { useState } from 'react';
|
||||
|
||||
interface ExportParticipantDataButtonProps {
|
||||
experimentId: number;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export default function ExportParticipantDataButton({
|
||||
experimentId,
|
||||
userId,
|
||||
}: ExportParticipantDataButtonProps) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const { jsonData, filename } = await exportParticipantDataAsJson(experimentId, userId);
|
||||
|
||||
// Create blob and trigger download
|
||||
const blob = new Blob([jsonData], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to export data');
|
||||
console.error('Export error:', err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<button
|
||||
onClick={handleExport}
|
||||
disabled={isLoading}
|
||||
className="px-3 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors text-sm font-medium"
|
||||
>
|
||||
{isLoading ? 'Exporting...' : 'Export as JSON'}
|
||||
</button>
|
||||
{error && <div className="text-red-600 text-sm">{error}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { ParticipantDetail, getParticipantCalibrationScores } from '@/app/action
|
||||
import { useEffect, useState } from 'react';
|
||||
import CalibrationScoresDisplay from './CalibrationScoresDisplay';
|
||||
import AudioPlayer from './AudioPlayer';
|
||||
import ExportParticipantDataButton from './ExportParticipantDataButton';
|
||||
|
||||
interface ParticipantDetailViewProps {
|
||||
participant: ParticipantDetail;
|
||||
@@ -44,7 +45,10 @@ export default function ParticipantDetailView({ participant, experimentId }: Par
|
||||
<div className="space-y-6">
|
||||
{/* Header Card */}
|
||||
<div className="bg-white rounded-lg shadow p-6">
|
||||
<h2 className="text-2xl font-bold text-gray-900 mb-4">{participant.userId}</h2>
|
||||
<div className="flex justify-between items-start mb-4">
|
||||
<h2 className="text-2xl font-bold text-gray-900">{participant.userId}</h2>
|
||||
<ExportParticipantDataButton experimentId={experimentId} userId={participant.userId} />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<div className="bg-blue-50 rounded p-4">
|
||||
<div className="text-sm text-gray-600 mb-1">Status</div>
|
||||
|
||||
Reference in New Issue
Block a user