Improve deletion handling for classes

This commit is contained in:
Nicolas Mowen 2025-11-10 06:28:47 -07:00
parent e0389382f8
commit c84bfd3ace
2 changed files with 40 additions and 20 deletions

View File

@ -44,7 +44,9 @@
},
"deleteCategory": {
"title": "Delete Class",
"desc": "Are you sure you want to delete the class {{name}}? This will permanently delete all associated images and require re-training the model."
"desc": "Are you sure you want to delete the class {{name}}? This will permanently delete all associated images and require re-training the model.",
"minClassesTitle": "Cannot Delete Class",
"minClassesDesc": "A classification model must have at least 2 classes. Add another class before deleting this one."
},
"deleteModel": {
"title": "Delete Classification Model",

View File

@ -265,10 +265,11 @@ export default function ModelTrainingView({ model }: ModelTrainingViewProps) {
);
}
// Always refresh dataset to update the categories list
refreshDataset();
if (pageToggle == "train") {
refreshTrain();
} else {
refreshDataset();
}
}
})
@ -572,27 +573,44 @@ function LibrarySelector({
>
<DialogContent>
<DialogHeader>
<DialogTitle>{t("deleteCategory.title")}</DialogTitle>
<DialogTitle>
{Object.keys(dataset).length <= 2
? t("deleteCategory.minClassesTitle")
: t("deleteCategory.title")}
</DialogTitle>
<DialogDescription>
{t("deleteCategory.desc", { name: confirmDelete })}
{Object.keys(dataset).length <= 2
? t("deleteCategory.minClassesDesc")
: t("deleteCategory.desc", { name: confirmDelete })}
</DialogDescription>
</DialogHeader>
<div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => setConfirmDelete(null)}>
{t("button.cancel", { ns: "common" })}
</Button>
<Button
variant="destructive"
className="text-white"
onClick={() => {
if (confirmDelete) {
handleDeleteCategory(confirmDelete);
setConfirmDelete(null);
}
}}
>
{t("button.delete", { ns: "common" })}
</Button>
{Object.keys(dataset).length <= 2 ? (
<Button variant="outline" onClick={() => setConfirmDelete(null)}>
{t("button.ok", { ns: "common" })}
</Button>
) : (
<>
<Button
variant="outline"
onClick={() => setConfirmDelete(null)}
>
{t("button.cancel", { ns: "common" })}
</Button>
<Button
variant="destructive"
className="text-white"
onClick={() => {
if (confirmDelete) {
handleDeleteCategory(confirmDelete);
setConfirmDelete(null);
}
}}
>
{t("button.delete", { ns: "common" })}
</Button>
</>
)}
</div>
</DialogContent>
</Dialog>