Skip to content

Commit f2a8184

Browse files
committed
feat: add recent suggestion category feature to Survey model and remove auto input suggestion category
1 parent b1d97e9 commit f2a8184

File tree

14 files changed

+101
-29
lines changed

14 files changed

+101
-29
lines changed

src/client/components/survey/SurveyAIBtn/SurveyAISummary.tsx

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useTranslation } from '@i18next-toolkit/react';
33
import React, { useState } from 'react';
44
import dayjs from 'dayjs';
55
import { trpc } from '@/api/trpc';
6-
import { useEventWithLoading } from '@/hooks/useEvent';
6+
import { useEvent, useEventWithLoading } from '@/hooks/useEvent';
77
import { Button } from '../../ui/button';
8-
import { LuBot } from 'react-icons/lu';
8+
import { LuBot, LuHistory } from 'react-icons/lu';
99
import { DatePicker, DatePickerRange } from '../../DatePicker';
1010
import { Select as AntdSelect, Checkbox } from 'antd';
1111
import { toast } from 'sonner';
@@ -16,8 +16,9 @@ import {
1616
SelectTrigger,
1717
SelectValue,
1818
} from '../../ui/select';
19-
import { useWatch } from '@/hooks/useWatch';
2019
import { Alert, AlertDescription, AlertTitle } from '../../ui/alert';
20+
import { SimpleTooltip } from '@/components/ui/tooltip';
21+
import { useWatch } from '@/hooks/useWatch';
2122

2223
type RunStrategy = 'skipExist' | 'skipInSuggest' | 'rebuildAll';
2324
type LanguageStrategy = 'default' | 'user';
@@ -41,23 +42,35 @@ export const SurveyAISummary: React.FC<SurveyAISummaryProps> = React.memo(
4142
const [runStrategy, setRunStrategy] = useState<RunStrategy>('skipExist');
4243
const [languageStrategy, setLanguageStrategy] =
4344
useState<LanguageStrategy>('user');
45+
const trpcUtils = trpc.useUtils();
4446

4547
const { data: info } = trpc.survey.get.useQuery({
4648
workspaceId,
4749
surveyId,
4850
});
49-
const { data: aiCategoryList } = trpc.survey.aiCategoryList.useQuery({
50-
workspaceId,
51-
surveyId,
51+
52+
useWatch([info], () => {
53+
if (
54+
info?.recentSuggestionCategory &&
55+
info.recentSuggestionCategory.length > 0
56+
) {
57+
setCategory(info.recentSuggestionCategory);
58+
}
5259
});
5360

54-
useWatch([aiCategoryList], () => {
55-
if (aiCategoryList) {
56-
setCategory(
57-
aiCategoryList
58-
.filter((item) => item.name !== null)
59-
.map((c) => c.name!)
60-
);
61+
const handleFetchHistoryAICategory = useEvent(async () => {
62+
const categoryList = await trpcUtils.survey.aiCategoryList
63+
.fetch({
64+
workspaceId,
65+
surveyId,
66+
})
67+
.then((res) => res.map((r) => r.name).filter((n) => n !== null));
68+
69+
if (categoryList.length > 0) {
70+
setCategory(categoryList);
71+
toast(t('Use History Suggestion Category'));
72+
} else {
73+
toast(t('No History Suggestion Category'));
6174
}
6275
});
6376

@@ -122,9 +135,21 @@ export const SurveyAISummary: React.FC<SurveyAISummaryProps> = React.memo(
122135
</div>
123136
<DatePicker className="w-full" value={date} onChange={setDate} />
124137

125-
<div className="text-xs opacity-50">
126-
{t('Step 3: Please provide some suggestion category')}
138+
<div className="flex items-center space-x-2">
139+
<div className="text-xs opacity-50">
140+
{t('Step 3: Please provide some suggestion category')}
141+
</div>
142+
<SimpleTooltip content={t('Use History Suggestion Category')}>
143+
<Button
144+
variant="outline"
145+
size="icon"
146+
className="h-6 w-6"
147+
Icon={LuHistory}
148+
onClick={handleFetchHistoryAICategory}
149+
/>
150+
</SimpleTooltip>
127151
</div>
152+
128153
<AntdSelect
129154
mode="tags"
130155
className="w-full"

src/client/components/ui/tooltip.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ const TooltipContent = React.forwardRef<
1717
ref={ref}
1818
sideOffset={sideOffset}
1919
className={cn(
20-
'z-50 overflow-hidden rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-zinc-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-zinc-50 dark:text-zinc-900',
20+
'animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 overflow-hidden rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-zinc-50 dark:bg-zinc-50 dark:text-zinc-900',
2121
className
2222
)}
2323
{...props}
2424
/>
2525
));
2626
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
2727

28+
export const SimpleTooltip = React.memo(
29+
({
30+
children,
31+
content,
32+
}: {
33+
children: React.ReactNode;
34+
content: React.ReactNode;
35+
}) => {
36+
return (
37+
<Tooltip>
38+
<TooltipTrigger>{children}</TooltipTrigger>
39+
<TooltipContent>{content}</TooltipContent>
40+
</Tooltip>
41+
);
42+
}
43+
);
44+
2845
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };

src/client/public/locales/de-DE/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "Anforderungszeitüberschreitung (s)",
2323
"k1598e726": "aktueller Besucher",
2424
"k15ae36a6": "Browser",
25+
"k15caaa30": "Keine Verlaufsvorschlagskategorie",
2526
"k15cc3db9": "Benutzerdefinierte Preisgestaltung für die Berechnung der Kosten von Ausgabetoken. Preis pro 1 Million Ausgabetoken in USD.",
2627
"k16545ddd": "Modell",
2728
"k16635176": "Als gelöst markieren",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "Weiter",
659660
"ka4270309": "Ecuador",
660661
"ka44150a0": "Letzte 90 Tage",
662+
"ka4ab84b7": "Verlaufsvorschlagskategorie verwenden",
661663
"ka4e0f1e": "Versionshinweise",
662664
"ka5115b7e": "Nicht erweitert",
663665
"ka53d3c9f": "Estland",

src/client/public/locales/en/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "Request Timeout(s)",
2323
"k1598e726": "current visitor",
2424
"k15ae36a6": "Browser",
25+
"k15caaa30": "No History Suggestion Category",
2526
"k15cc3db9": "Custom pricing for output tokens cost calculation. Price per 1 million output tokens in USD.",
2627
"k16545ddd": "Model",
2728
"k16635176": "Mark as resolved",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "Next",
659660
"ka4270309": "Ecuador",
660661
"ka44150a0": "Last 90 days",
662+
"ka4ab84b7": "Use History Suggestion Category",
661663
"ka4e0f1e": "Release Notes",
662664
"ka5115b7e": "Not Extended",
663665
"ka53d3c9f": "Estonia",

src/client/public/locales/fr-FR/translation.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "Délai d'attente de la requête (s)",
2323
"k1598e726": "visiteur actuel",
2424
"k15ae36a6": "Navigateur",
25+
"k15caaa30": "Pas de catégorie de suggestion d'historique",
2526
"k15cc3db9": "Tarification personnalisée pour le calcul du coût des jetons de sortie. Prix pour 1 million de jetons de sortie en USD.",
2627
"k16545ddd": "Modèle",
2728
"k16635176": "Marquer comme résolu",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "Suivant",
659660
"ka4270309": "Équateur",
660661
"ka44150a0": "Les 90 derniers jours",
662+
"ka4ab84b7": "Utiliser la catégorie de suggestion d'historique",
661663
"ka4e0f1e": "Notes de version",
662664
"ka5115b7e": "Non étendu",
663665
"ka53d3c9f": "Estonie",
@@ -715,7 +717,7 @@
715717
"kb02a9d77": "Version HTTP non prise en charge",
716718
"kb057fbc4": "Mise à jour en temps réel",
717719
"kb090ddd": "Prix",
718-
"kb0b8443c": "Total Input Tokens",
720+
"kb0b8443c": "Total des jetons d'entrée",
719721
"kb0bfbb57": "Plage non satisfaisable",
720722
"kb0e351e0": "Rafraîchi",
721723
"kb114a2e8": "Obsolète",
@@ -734,7 +736,7 @@
734736
"kb40cfff9": "Conflit",
735737
"kb410657f": "Zambie",
736738
"kb4230f3a": "Aucun événement archivé",
737-
"kb493ab2c": "Total Price",
739+
"kb493ab2c": "Prix Total",
738740
"kb495819e": "Bénin",
739741
"kb4bfc91": "Dépendance échouée",
740742
"kb4f56447": "Guinée",

src/client/public/locales/ja-JP/translation.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "リクエストタイムアウト(秒)",
2323
"k1598e726": "現在の訪問者",
2424
"k15ae36a6": "ブラウザ",
25+
"k15caaa30": "履歴提案カテゴリなし",
2526
"k15cc3db9": "出力トークンのコスト計算のためのカスタム価格設定。100万出力トークンあたりの価格(USD)。",
2627
"k16545ddd": "モデル",
2728
"k16635176": "解決済みとしてマーク",
@@ -335,7 +336,7 @@
335336
"k5b3cec80": "AIゲートウェイを削除",
336337
"k5b5be0d4": "現在の役割",
337338
"k5b8c0125": "ソマリア",
338-
"k5bb2de23": "Playstore ID",
339+
"k5bb2de23": "PlayストアID",
339340
"k5bf77eab": "東ティモール",
340341
"k5c087fe": "カスタムモデルベースURL",
341342
"k5c18db28": "ステータスページ情報を修正",
@@ -349,7 +350,7 @@
349350
"k5dbfde6e": "ジョージア",
350351
"k5dc31ca3": "アルバ",
351352
"k5e079e86": "サブスクリプションの再充電が成功しました",
352-
"k5e5c6df1": "Appstore ID",
353+
"k5e5c6df1": "AppストアID",
353354
"k5e896fb6": "パラグアイ",
354355
"k5eb87a8b": "開始",
355356
"k5ec0de4": "HTTPSモニタリングの場合、通知方法が割り当てられている場合、通知は有効期限の1、3、7、14日前に送信されます。",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "次へ",
659660
"ka4270309": "エクアドル",
660661
"ka44150a0": "過去90日間",
662+
"ka4ab84b7": "履歴提案カテゴリを使用",
661663
"ka4e0f1e": "リリースノート",
662664
"ka5115b7e": "拡張されていない",
663665
"ka53d3c9f": "エストニア",

src/client/public/locales/pl-PL/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "Limit czasu żądania (s)",
2323
"k1598e726": "bieżący odwiedzający",
2424
"k15ae36a6": "Przeglądarka",
25+
"k15caaa30": "Brak kategorii sugestii historii",
2526
"k15cc3db9": "Niestandardowe ceny dla obliczania kosztów tokenów wyjściowych. Cena za 1 milion tokenów wyjściowych w USD.",
2627
"k16545ddd": "Model",
2728
"k16635176": "Oznacz jako rozwiązane",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "Następny",
659660
"ka4270309": "Ekwador",
660661
"ka44150a0": "Ostatnie 90 dni",
662+
"ka4ab84b7": "Użyj kategorii sugestii historii",
661663
"ka4e0f1e": "Notatki o wydaniu",
662664
"ka5115b7e": "Nie rozszerzone",
663665
"ka53d3c9f": "Estonia",

src/client/public/locales/pt-PT/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "Tempo de Espera do Pedido (s)",
2323
"k1598e726": "visitante atual",
2424
"k15ae36a6": "Navegador",
25+
"k15caaa30": "Sem Categoria de Sugestão de Histórico",
2526
"k15cc3db9": "Preços personalizados para cálculo de custo de tokens de saída. Preço por 1 milhão de tokens de saída em USD.",
2627
"k16545ddd": "Modelo",
2728
"k16635176": "Marcar como resolvido",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "Próximo",
659660
"ka4270309": "Equador",
660661
"ka44150a0": "Últimos 90 dias",
662+
"ka4ab84b7": "Usar Categoria de Sugestão de Histórico",
661663
"ka4e0f1e": "Notas de Lançamento",
662664
"ka5115b7e": "Não Estendido",
663665
"ka53d3c9f": "Estónia",

src/client/public/locales/ru-RU/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "Тайм-аут запроса (с)",
2323
"k1598e726": "текущий посетитель",
2424
"k15ae36a6": "Браузер",
25+
"k15caaa30": "Категория без истории предложений",
2526
"k15cc3db9": "Пользовательская цена для расчета стоимости выходных токенов. Цена за 1 миллион выходных токенов в долларах США.",
2627
"k16545ddd": "Модель",
2728
"k16635176": "Отметить как решенное",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "Далее",
659660
"ka4270309": "Эквадор",
660661
"ka44150a0": "Последние 90 дней",
662+
"ka4ab84b7": "Использовать категорию предложений из истории",
661663
"ka4e0f1e": "Примечания к выпуску",
662664
"ka5115b7e": "Не расширено",
663665
"ka53d3c9f": "Эстония",

src/client/public/locales/zh-CN/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"k158336d6": "请求超时(秒)",
2323
"k1598e726": "当前访客",
2424
"k15ae36a6": "浏览器",
25+
"k15caaa30": "无历史建议类别",
2526
"k15cc3db9": "用于计算输出代币成本的自定义定价。每百万输出代币的价格(美元)。",
2627
"k16545ddd": "模型",
2728
"k16635176": "标记为已解决",
@@ -658,6 +659,7 @@
658659
"ka41dbf02": "下一个",
659660
"ka4270309": "厄瓜多尔",
660661
"ka44150a0": "过去90天",
662+
"ka4ab84b7": "使用历史建议类别",
661663
"ka4e0f1e": "发行说明",
662664
"ka5115b7e": "未扩展",
663665
"ka53d3c9f": "爱沙尼亚",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Survey" ADD COLUMN "recentSuggestionCategory" TEXT[] DEFAULT ARRAY[]::TEXT[];

src/server/prisma/schema.prisma

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -772,17 +772,18 @@ enum WorkspaceAuditLogType {
772772
}
773773

774774
model Survey {
775-
id String @id @default(cuid()) @db.VarChar(30)
776-
workspaceId String @db.VarChar(30)
777-
name String
775+
id String @id @default(cuid()) @db.VarChar(30)
776+
workspaceId String @db.VarChar(30)
777+
name String
778778
/// [SurveyPayload]
779779
/// @zod.custom(imports.SurveyPayloadSchema)
780-
payload Json @db.Json
781-
feedChannelIds String[] @default([]) // send survey result to feed channel
782-
feedTemplate String @default("") // send survey result to feed channel
783-
webhookUrl String @default("")
784-
createdAt DateTime @default(now()) @db.Timestamptz(6)
785-
updatedAt DateTime @updatedAt @db.Timestamptz(6)
780+
payload Json @db.Json
781+
feedChannelIds String[] @default([]) // send survey result to feed channel
782+
feedTemplate String @default("") // send survey result to feed channel
783+
webhookUrl String @default("")
784+
recentSuggestionCategory String[] @default([]) // recent ai category which user input
785+
createdAt DateTime @default(now()) @db.Timestamptz(6)
786+
updatedAt DateTime @updatedAt @db.Timestamptz(6)
786787
787788
workspace Workspace @relation(fields: [workspaceId], references: [id], onUpdate: Cascade, onDelete: Cascade)
788789
surveyResultList SurveyResult[]

src/server/prisma/zod/survey.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const SurveyModelSchema = z.object({
1919
feedChannelIds: z.string().array(),
2020
feedTemplate: z.string(),
2121
webhookUrl: z.string(),
22+
recentSuggestionCategory: z.string().array(),
2223
createdAt: z.date(),
2324
updatedAt: z.date(),
2425
})

src/server/trpc/routers/ai.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from '../../mq/producer.js';
2727
import { OpenApiMeta } from 'trpc-to-openapi';
2828
import { OPENAPI_TAG } from '../../utils/const.js';
29+
import { prisma } from '../../model/_client.js';
2930

3031
export const aiRouter = router({
3132
ask: workspaceProcedure
@@ -132,6 +133,15 @@ export const aiRouter = router({
132133
} = input;
133134
const { language } = ctx;
134135

136+
await prisma.survey.update({
137+
where: {
138+
id: surveyId,
139+
},
140+
data: {
141+
recentSuggestionCategory: [...(suggestionCategory || [])],
142+
},
143+
});
144+
135145
await sendBuildSurveyClassifyMessageQueue({
136146
workspaceId,
137147
surveyId,

0 commit comments

Comments
 (0)