feat: Add missing text placeholder in prompt help messages for different locales

This commit is contained in:
n4ze3m 2024-08-04 16:47:28 +05:30
parent 1bb6d3a89a
commit 2cc880c722
10 changed files with 113 additions and 13 deletions

View File

@ -170,7 +170,8 @@
"label": "Prompt", "label": "Prompt",
"placeholder": "Enter Prompt", "placeholder": "Enter Prompt",
"required": "Please enter a prompt", "required": "Please enter a prompt",
"help": "You can use {key} as variable in your prompt." "help": "You can use {key} as variable in your prompt.",
"missingTextPlaceholder": "The {text} variable is missing in the prompt. Please add it."
}, },
"isSystem": { "isSystem": {
"label": "Is System Prompt" "label": "Is System Prompt"

View File

@ -170,7 +170,8 @@
"label": "Prompt", "label": "Prompt",
"placeholder": "Ingrese un prompt", "placeholder": "Ingrese un prompt",
"required": "Por favor, ingrese un prompt", "required": "Por favor, ingrese un prompt",
"help": "Puede usar {key} como variable en su prompt." "help": "Puede usar {key} como variable en su prompt.",
"missingTextPlaceholder": "Falta la variable {text} en el mensaje. Por favor, añádela."
}, },
"isSystem": { "isSystem": {
"label": "Es un Prompt del Sistema" "label": "Es un Prompt del Sistema"

View File

@ -170,7 +170,8 @@
"label": "Prompt", "label": "Prompt",
"placeholder": "Entrer Prompt", "placeholder": "Entrer Prompt",
"required": "Veuillez entrer un prompt", "required": "Veuillez entrer un prompt",
"help": "Vous pouvez utiliser {key} comme variable dans votre prompt." "help": "Vous pouvez utiliser {key} comme variable dans votre prompt.",
"missingTextPlaceholder": "La variable {text} est manquante dans le message. Veuillez l'ajouter."
}, },
"isSystem": { "isSystem": {
"label": "Est un prompt système" "label": "Est un prompt système"

View File

@ -170,7 +170,8 @@
"label": "Prompt", "label": "Prompt",
"placeholder": "Inserisci Prompt", "placeholder": "Inserisci Prompt",
"required": "Scrivi il prompt", "required": "Scrivi il prompt",
"help": "Puoi usare {key} come variabile nel tuo prompt." "help": "Puoi usare {key} come variabile nel tuo prompt.",
"missingTextPlaceholder": "La variabile {text} manca nel prompt. Per favore, aggiungila."
}, },
"isSystem": { "isSystem": {
"label": "Prompt di Sistema" "label": "Prompt di Sistema"

View File

@ -173,7 +173,8 @@
"label": "プロンプト", "label": "プロンプト",
"placeholder": "プロンプトを入力", "placeholder": "プロンプトを入力",
"required": "プロンプトを入力してください", "required": "プロンプトを入力してください",
"help": "プロンプト内で{key}を変数として使用できます。" "help": "プロンプト内で{key}を変数として使用できます。",
"missingTextPlaceholder": "プロンプトに{text}変数がありません。追加してください。"
}, },
"isSystem": { "isSystem": {
"label": "システムプロンプト" "label": "システムプロンプト"

View File

@ -173,7 +173,8 @@
"label": "പ്രോംപ്റ്റ്", "label": "പ്രോംപ്റ്റ്",
"placeholder": "പ്രോംപ്റ്റ് നല്കുക", "placeholder": "പ്രോംപ്റ്റ് നല്കുക",
"required": "ദയവായി ഒരു പ്രോംപ്റ്റ് നല്കുക", "required": "ദയവായി ഒരു പ്രോംപ്റ്റ് നല്കുക",
"help": "നിങ്ങള്‍ക്ക് {key} എന്ന രീതിയില്‍ പ്രോംപ്റ്റില്‍ വേരിയബിളുകള്‍ ഉപയോഗിക്കാവുന്നതാണ്." "help": "നിങ്ങള്‍ക്ക് {key} എന്ന രീതിയില്‍ പ്രോംപ്റ്റില്‍ വേരിയബിളുകള്‍ ഉപയോഗിക്കാവുന്നതാണ്.",
"missingTextPlaceholder": "പ്രോംപ്റ്റിൽ {text} വേരിയബിൾ കാണുന്നില്ല. ദയവായി അത് ചേർക്കുക."
}, },
"isSystem": { "isSystem": {
"label": "സിസ്റ്റം പ്രോംപ്റ്റ് ആണോ" "label": "സിസ്റ്റം പ്രോംപ്റ്റ് ആണോ"

View File

@ -170,7 +170,8 @@
"label": "Prompt", "label": "Prompt",
"placeholder": "Digite o Prompt", "placeholder": "Digite o Prompt",
"required": "Por favor, insira um prompt", "required": "Por favor, insira um prompt",
"help": "Você pode usar {key} como variável em seu prompt." "help": "Você pode usar {key} como variável em seu prompt.",
"missingTextPlaceholder": "A variável {text} está faltando no prompt. Por favor, adicione-a."
}, },
"isSystem": { "isSystem": {
"label": "É um Prompt do Sistema" "label": "É um Prompt do Sistema"

View File

@ -171,7 +171,8 @@
"label": "Подсказка", "label": "Подсказка",
"placeholder": "Введите подсказку", "placeholder": "Введите подсказку",
"required": "Пожалуйста, введите подсказку", "required": "Пожалуйста, введите подсказку",
"help": "Вы можете использовать {key} в качестве переменной в своей подсказке." "help": "Вы можете использовать {key} в качестве переменной в своей подсказке.",
"missingTextPlaceholder": "Переменная {text} отсутствует в подсказке. Пожалуйста, добавьте ее."
}, },
"isSystem": { "isSystem": {
"label": "Это системная подсказка" "label": "Это системная подсказка"

View File

@ -174,7 +174,8 @@
"label": "提示词", "label": "提示词",
"placeholder": "输入提示词", "placeholder": "输入提示词",
"required": "请输入提示词", "required": "请输入提示词",
"help": "您可以在提示词中使用 {key} 作为变量。" "help": "您可以在提示词中使用 {key} 作为变量。",
"missingTextPlaceholder": "提示中缺少{text}变量。请添加它。"
}, },
"isSystem": { "isSystem": {
"label": "是否为系统提示词" "label": "是否为系统提示词"

View File

@ -15,7 +15,10 @@ 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 { deletePromptById, getAllPrompts, savePrompt, updatePrompt } from "@/db" import { deletePromptById, getAllPrompts, savePrompt, updatePrompt } from "@/db"
import { getAllCopilotPrompts } from "@/services/application" import {
getAllCopilotPrompts,
setAllCopilotPrompts
} from "@/services/application"
import { tagColors } from "@/utils/color" import { tagColors } from "@/utils/color"
export const PromptBody = () => { export const PromptBody = () => {
@ -29,6 +32,11 @@ export const PromptBody = () => {
const [selectedSegment, setSelectedSegment] = useState<"custom" | "copilot">( const [selectedSegment, setSelectedSegment] = useState<"custom" | "copilot">(
"custom" "custom"
) )
const [openCopilotEdit, setOpenCopilotEdit] = useState(false)
const [editCopilotId, setEditCopilotId] = useState("")
const [editCopilotForm] = Form.useForm()
const { data, status } = useQuery({ const { data, status } = useQuery({
queryKey: ["fetchAllPrompts"], queryKey: ["fetchAllPrompts"],
queryFn: getAllPrompts queryFn: getAllPrompts
@ -109,6 +117,36 @@ export const PromptBody = () => {
} }
}) })
const { mutate: updateCopilotPrompt, isPending: isUpdatingCopilotPrompt } =
useMutation({
mutationFn: async (data: any) => {
return await setAllCopilotPrompts([
{
key: data.key,
prompt: data.prompt
}
])
},
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["fetchCopilotPrompts"]
})
setOpenCopilotEdit(false)
editCopilotForm.resetFields()
notification.success({
message: t("managePrompts.notification.updatedSuccess"),
description: t("managePrompts.notification.updatedSuccessDesc")
})
},
onError: (error) => {
notification.error({
message: t("managePrompts.notification.error"),
description:
error?.message || t("managePrompts.notification.someError")
})
}
})
function customPrompts() { function customPrompts() {
return ( return (
<div> <div>
@ -241,9 +279,9 @@ export const PromptBody = () => {
<Tooltip title={t("managePrompts.tooltip.edit")}> <Tooltip title={t("managePrompts.tooltip.edit")}>
<button <button
onClick={() => { onClick={() => {
// setEditId(record.id) setEditCopilotId(record.key)
// editForm.setFieldsValue(record) editCopilotForm.setFieldsValue(record)
// setOpenEdit(true) setOpenCopilotEdit(true)
}} }}
className="text-gray-500 dark:text-gray-400"> className="text-gray-500 dark:text-gray-400">
<Pen className="size-4" /> <Pen className="size-4" />
@ -396,6 +434,59 @@ export const PromptBody = () => {
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
<Modal
title={t("managePrompts.modal.editTitle")}
open={openCopilotEdit}
onCancel={() => setOpenCopilotEdit(false)}
footer={null}>
<Form
onFinish={(values) =>
updateCopilotPrompt({
key: editCopilotId,
prompt: values.prompt
})
}
layout="vertical"
form={editCopilotForm}>
<Form.Item
name="prompt"
label={t("managePrompts.form.prompt.label")}
rules={[
{
required: true,
message: t("managePrompts.form.prompt.required")
},
{
validator: (_, value) => {
if (value && value.includes("{text}")) {
return Promise.resolve()
}
return Promise.reject(
new Error(
t("managePrompts.form.prompt.missingTextPlaceholder")
)
)
}
}
]}>
<Input.TextArea
placeholder={t("managePrompts.form.prompt.placeholder")}
autoSize={{ minRows: 3, maxRows: 10 }}
/>
</Form.Item>
<Form.Item>
<button
disabled={isUpdatingCopilotPrompt}
className="inline-flex justify-center w-full text-center mt-4 items-center rounded-md border border-transparent bg-black px-2 py-2 text-sm font-medium leading-4 text-white shadow-sm hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 dark:bg-white dark:text-gray-800 dark:hover:bg-gray-100 dark:focus:ring-gray-500 dark:focus:ring-offset-gray-100 disabled:opacity-50 ">
{isUpdatingCopilotPrompt
? t("managePrompts.form.btnEdit.saving")
: t("managePrompts.form.btnEdit.save")}
</button>
</Form.Item>
</Form>
</Modal>
</div> </div>
) )
} }