fix: cascade experiment removal to experiment_calibration
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import db from '@/lib/db';
|
import db from '@/lib/db';
|
||||||
import { experiment } from '@/lib/model/experiment';
|
import { experiment } from '@/lib/model/experiment';
|
||||||
|
import { experiment_calibration } from '@/lib/model/experiment_calibration';
|
||||||
import { annotation } from '@/lib/model/annotation';
|
import { annotation } from '@/lib/model/annotation';
|
||||||
import { participant } from '@/lib/model/participant';
|
import { participant } from '@/lib/model/participant';
|
||||||
import { and, eq } from 'drizzle-orm';
|
import { and, eq } from 'drizzle-orm';
|
||||||
@@ -108,6 +109,9 @@ export async function deleteExperiment(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Delete all experiment_calibration records first
|
||||||
|
await db.delete(experiment_calibration).where(eq(experiment_calibration.experimentId, id));
|
||||||
|
|
||||||
// Delete the experiment
|
// Delete the experiment
|
||||||
await db.delete(experiment).where(eq(experiment.id, id));
|
await db.delete(experiment).where(eq(experiment.id, id));
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ import Modal from '@/components/Modal';
|
|||||||
import { Dataset } from '@/lib/model/dataset';
|
import { Dataset } from '@/lib/model/dataset';
|
||||||
import { getAllDatasets } from '@/app/actions/datasets';
|
import { getAllDatasets } from '@/app/actions/datasets';
|
||||||
|
|
||||||
|
const ANNOTATION_TOOLS = [
|
||||||
|
{ value: 'quality-choice', label: 'Quality Choice' },
|
||||||
|
{ value: 'binary', label: 'Binary' },
|
||||||
|
// Future tools can be added here
|
||||||
|
];
|
||||||
|
|
||||||
interface CreateExperimentModalProps {
|
interface CreateExperimentModalProps {
|
||||||
datasetId?: number;
|
datasetId?: number;
|
||||||
}
|
}
|
||||||
@@ -15,6 +21,7 @@ export default function CreateExperimentModal({ datasetId }: CreateExperimentMod
|
|||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
const [description, setDescription] = useState('');
|
const [description, setDescription] = useState('');
|
||||||
const [selectedDatasetId, setSelectedDatasetId] = useState<number | ''>(datasetId || '');
|
const [selectedDatasetId, setSelectedDatasetId] = useState<number | ''>(datasetId || '');
|
||||||
|
const [annotationTool, setAnnotationTool] = useState('quality-choice');
|
||||||
const [onboardingEnabled, setOnboardingEnabled] = useState(false);
|
const [onboardingEnabled, setOnboardingEnabled] = useState(false);
|
||||||
const [calibrationEnabled, setCalibrationEnabled] = useState(false);
|
const [calibrationEnabled, setCalibrationEnabled] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -64,12 +71,14 @@ export default function CreateExperimentModal({ datasetId }: CreateExperimentMod
|
|||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
description: description.trim() || undefined,
|
description: description.trim() || undefined,
|
||||||
datasetId: Number(selectedDatasetId),
|
datasetId: Number(selectedDatasetId),
|
||||||
|
annotationTool,
|
||||||
onboardingEnabled,
|
onboardingEnabled,
|
||||||
calibrationEnabled
|
calibrationEnabled
|
||||||
});
|
});
|
||||||
setName('');
|
setName('');
|
||||||
setDescription('');
|
setDescription('');
|
||||||
setSelectedDatasetId(datasetId || '');
|
setSelectedDatasetId(datasetId || '');
|
||||||
|
setAnnotationTool('quality-choice');
|
||||||
setOnboardingEnabled(false);
|
setOnboardingEnabled(false);
|
||||||
setCalibrationEnabled(false);
|
setCalibrationEnabled(false);
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
@@ -92,6 +101,7 @@ export default function CreateExperimentModal({ datasetId }: CreateExperimentMod
|
|||||||
setName('');
|
setName('');
|
||||||
setDescription('');
|
setDescription('');
|
||||||
setSelectedDatasetId(datasetId || '');
|
setSelectedDatasetId(datasetId || '');
|
||||||
|
setAnnotationTool('quality-choice');
|
||||||
setOnboardingEnabled(false);
|
setOnboardingEnabled(false);
|
||||||
setCalibrationEnabled(false);
|
setCalibrationEnabled(false);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -162,6 +172,25 @@ export default function CreateExperimentModal({ datasetId }: CreateExperimentMod
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="annotationTool" className="block text-sm font-medium mb-2">
|
||||||
|
Annotation Tool
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="annotationTool"
|
||||||
|
value={annotationTool}
|
||||||
|
onChange={(e) => setAnnotationTool(e.target.value)}
|
||||||
|
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{ANNOTATION_TOOLS.map((tool) => (
|
||||||
|
<option key={tool.value} value={tool.value}>
|
||||||
|
{tool.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
{!datasetId && (
|
{!datasetId && (
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="datasetId" className="block text-sm font-medium mb-2">
|
<label htmlFor="datasetId" className="block text-sm font-medium mb-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user