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,13 +573,28 @@ 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">
{Object.keys(dataset).length <= 2 ? (
<Button variant="outline" onClick={() => setConfirmDelete(null)}> <Button variant="outline" onClick={() => setConfirmDelete(null)}>
{t("button.ok", { ns: "common" })}
</Button>
) : (
<>
<Button
variant="outline"
onClick={() => setConfirmDelete(null)}
>
{t("button.cancel", { ns: "common" })} {t("button.cancel", { ns: "common" })}
</Button> </Button>
<Button <Button
@ -593,6 +609,8 @@ function LibrarySelector({
> >
{t("button.delete", { ns: "common" })} {t("button.delete", { ns: "common" })}
</Button> </Button>
</>
)}
</div> </div>
</DialogContent> </DialogContent>
</Dialog> </Dialog>