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": { "deleteCategory": {
"title": "Delete Class", "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": { "deleteModel": {
"title": "Delete Classification Model", "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") { if (pageToggle == "train") {
refreshTrain(); refreshTrain();
} else {
refreshDataset();
} }
} }
}) })
@ -572,27 +573,44 @@ function LibrarySelector({
> >
<DialogContent> <DialogContent>
<DialogHeader> <DialogHeader>
<DialogTitle>{t("deleteCategory.title")}</DialogTitle> <DialogTitle>
{Object.keys(dataset).length <= 2
? t("deleteCategory.minClassesTitle")
: t("deleteCategory.title")}
</DialogTitle>
<DialogDescription> <DialogDescription>
{t("deleteCategory.desc", { name: confirmDelete })} {Object.keys(dataset).length <= 2
? t("deleteCategory.minClassesDesc")
: t("deleteCategory.desc", { name: confirmDelete })}
</DialogDescription> </DialogDescription>
</DialogHeader> </DialogHeader>
<div className="flex justify-end gap-2"> <div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => setConfirmDelete(null)}> {Object.keys(dataset).length <= 2 ? (
{t("button.cancel", { ns: "common" })} <Button variant="outline" onClick={() => setConfirmDelete(null)}>
</Button> {t("button.ok", { ns: "common" })}
<Button </Button>
variant="destructive" ) : (
className="text-white" <>
onClick={() => { <Button
if (confirmDelete) { variant="outline"
handleDeleteCategory(confirmDelete); onClick={() => setConfirmDelete(null)}
setConfirmDelete(null); >
} {t("button.cancel", { ns: "common" })}
}} </Button>
> <Button
{t("button.delete", { ns: "common" })} variant="destructive"
</Button> className="text-white"
onClick={() => {
if (confirmDelete) {
handleDeleteCategory(confirmDelete);
setConfirmDelete(null);
}
}}
>
{t("button.delete", { ns: "common" })}
</Button>
</>
)}
</div> </div>
</DialogContent> </DialogContent>
</Dialog> </Dialog>