Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prompt deletion #270

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/frontend/pages/datasets/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 } =
Expand Down Expand Up @@ -101,8 +102,8 @@ function PromptVariation({ i, variationId, content, onDelete, markSaved }) {
{prompt?.variations?.length > 1 && (
<ActionIcon
onClick={async () => {
onDelete()
await remove()
onDelete()
}}
pos="absolute"
top={-25}
Expand All @@ -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,
Expand Down Expand Up @@ -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",
})
}
},
})
}}
Expand Down Expand Up @@ -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,
Expand Down
Loading