feat: Add segmented control for custom and copilot prompts in PromptBody component
This commit is contained in:
parent
58304d9ca7
commit
80413a3c26
@ -8,16 +8,12 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
Form,
|
Form,
|
||||||
Switch,
|
Switch,
|
||||||
|
Segmented
|
||||||
} from "antd"
|
} from "antd"
|
||||||
import { Trash2, Pen, Computer, Zap } from "lucide-react"
|
import { Trash2, Pen, Computer, Zap } from "lucide-react"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import {
|
import { deletePromptById, getAllPrompts, savePrompt, updatePrompt } from "@/db"
|
||||||
deletePromptById,
|
|
||||||
getAllPrompts,
|
|
||||||
savePrompt,
|
|
||||||
updatePrompt
|
|
||||||
} from "@/db"
|
|
||||||
|
|
||||||
export const PromptBody = () => {
|
export const PromptBody = () => {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
@ -27,7 +23,9 @@ export const PromptBody = () => {
|
|||||||
const [createForm] = Form.useForm()
|
const [createForm] = Form.useForm()
|
||||||
const [editForm] = Form.useForm()
|
const [editForm] = Form.useForm()
|
||||||
const { t } = useTranslation("settings")
|
const { t } = useTranslation("settings")
|
||||||
|
const [selectedSegment, setSelectedSegment] = useState<"custom" | "copilot">(
|
||||||
|
"custom"
|
||||||
|
)
|
||||||
const { data, status } = useQuery({
|
const { data, status } = useQuery({
|
||||||
queryKey: ["fetchAllPrompts"],
|
queryKey: ["fetchAllPrompts"],
|
||||||
queryFn: getAllPrompts
|
queryFn: getAllPrompts
|
||||||
@ -103,8 +101,8 @@ export const PromptBody = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
function customPrompts() {
|
||||||
<div>
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<div className="-ml-4 -mt-2 flex flex-wrap items-center justify-end sm:flex-nowrap">
|
<div className="-ml-4 -mt-2 flex flex-wrap items-center justify-end sm:flex-nowrap">
|
||||||
@ -127,30 +125,38 @@ export const PromptBody = () => {
|
|||||||
title: t("managePrompts.columns.title"),
|
title: t("managePrompts.columns.title"),
|
||||||
dataIndex: "title",
|
dataIndex: "title",
|
||||||
key: "title",
|
key: "title",
|
||||||
render: (content) => (<span className="line-clamp-1">{content}</span>)
|
render: (content) => (
|
||||||
|
<span className="line-clamp-1">{content}</span>
|
||||||
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("managePrompts.columns.prompt"),
|
title: t("managePrompts.columns.prompt"),
|
||||||
dataIndex: "content",
|
dataIndex: "content",
|
||||||
key: "content",
|
key: "content",
|
||||||
render: (content) => (<span className="line-clamp-1">{content}</span>)
|
render: (content) => (
|
||||||
|
<span className="line-clamp-1">{content}</span>
|
||||||
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("managePrompts.columns.type"),
|
title: t("managePrompts.columns.type"),
|
||||||
dataIndex: "is_system",
|
dataIndex: "is_system",
|
||||||
key: "is_system",
|
key: "is_system",
|
||||||
render: (is_system) =>
|
render: (is_system) => (
|
||||||
<span className="flex items-center gap-2 text-xs w-32">
|
<span className="flex items-center gap-2 text-xs w-32">
|
||||||
{is_system ? (
|
{is_system ? (
|
||||||
<>
|
<>
|
||||||
<Computer className="size-4" /> {t("managePrompts.systemPrompt")}
|
<Computer className="size-4" />{" "}
|
||||||
|
{t("managePrompts.systemPrompt")}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Zap className="size-4" /> {t("managePrompts.quickPrompt")}
|
<Zap className="size-4" />{" "}
|
||||||
|
{t("managePrompts.quickPrompt")}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</span> },
|
</span>
|
||||||
|
)
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: t("managePrompts.columns.actions"),
|
title: t("managePrompts.columns.actions"),
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
@ -189,6 +195,29 @@ export const PromptBody = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center justify-end mb-6">
|
||||||
|
<Segmented
|
||||||
|
size="large"
|
||||||
|
options={[
|
||||||
|
{
|
||||||
|
label: "Custom Prompts",
|
||||||
|
value: "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Copilot Prompts",
|
||||||
|
value: "copilot"
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
onChange={(value) => {
|
||||||
|
setSelectedSegment(value as "custom" | "copilot")
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{selectedSegment === "custom" && customPrompts()}
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
title={t("managePrompts.modal.addTitle")}
|
title={t("managePrompts.modal.addTitle")}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user