From 957fa0432cdfee90cfa17e60cb5d619b07cb0c25 Mon Sep 17 00:00:00 2001 From: hughcrt Date: Thu, 2 May 2024 23:00:35 -0300 Subject: [PATCH] Ok --- packages/frontend/pages/datasets/[id].tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/frontend/pages/datasets/[id].tsx b/packages/frontend/pages/datasets/[id].tsx index f33d2919..a8de1e3d 100644 --- a/packages/frontend/pages/datasets/[id].tsx +++ b/packages/frontend/pages/datasets/[id].tsx @@ -30,6 +30,7 @@ import { modals } from "@mantine/modals" import { IconCircleMinus, IconPlus } from "@tabler/icons-react" import { useRouter } from "next/router" import { useEffect, useState } from "react" +import { notifications } from "@mantine/notifications" function PromptVariation({ i, variationId, content, onDelete, markSaved }) { const { variation, update, remove, mutate } = @@ -101,8 +102,8 @@ function PromptVariation({ i, variationId, content, onDelete, markSaved }) { {prompt?.variations?.length > 1 && ( { - onDelete() await remove() + onDelete() }} pos="absolute" top={-25} @@ -117,7 +118,7 @@ function PromptVariation({ i, variationId, content, onDelete, markSaved }) { ) } -function PromptTab({ isText, promptId, onDelete, markSaved }) { +function PromptTab({ isText, promptId, onDelete, markSaved, canBeDeleted }) { const { prompt, update, @@ -215,8 +216,16 @@ function PromptTab({ isText, promptId, onDelete, markSaved }) { labels: { confirm: "Confirm", cancel: "Cancel" }, onConfirm: async () => { - onDelete() - await remove() + if (canBeDeleted) { + await remove() + onDelete() + } else { + notifications.show({ + title: "You can't delete this Prompt", + message: "You need at least one Prompt in your Dataset", + color: "red", + }) + } }, }) }} @@ -358,6 +367,7 @@ export default function NewDataset() { promptId={prompt.id} isText={dataset?.format === "text"} markSaved={markSaved} + canBeDeleted={dataset?.prompts?.length > 1} onDelete={() => { mutate({ ...dataset,