Skip to content
Merged
Show file tree
Hide file tree
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
54 changes: 43 additions & 11 deletions packages/ui/src/components/HistoryDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@
@update:show="(value: boolean) => !value && close()"
>
<template #header-extra>
<NButton
v-if="sortedHistory && sortedHistory.length > 0"
@click="handleClear"
size="small"
quaternary
>
{{ t('common.clear') }}
</NButton>
<NSpace align="center" :size="12">
<NInput
v-model:value="searchQuery"
:placeholder="t('history.searchPlaceholder')"
size="small"
style="width: 200px"
clearable
>
<template #prefix>
<span style="font-size: 14px;">🔍</span>
</template>
</NInput>
<NButton
v-if="sortedHistory && sortedHistory.length > 0"
@click="handleClear"
size="small"
quaternary
>
{{ t('common.clear') }}
</NButton>
</NSpace>
</template>

<NScrollbar style="max-height: 65vh;">
<NSpace vertical :size="16" v-if="sortedHistory && sortedHistory.length > 0">
<NCard
v-for="chain in sortedHistory"
v-for="chain in filteredHistory"
:key="chain.chainId"
hoverable
>
Expand Down Expand Up @@ -185,7 +198,7 @@ import { ref, watch, computed, type PropType } from 'vue'
import { useI18n } from 'vue-i18n'
import {
NModal, NScrollbar, NSpace, NCard, NText, NTag, NButton,
NDivider, NCollapse, NCollapseItem, NEmpty
NDivider, NCollapse, NCollapseItem, NEmpty, NInput
} from 'naive-ui'
import type { PromptRecord, PromptRecordChain } from '@prompt-optimizer/core'
import { useToast } from '../composables/ui/useToast'
Expand Down Expand Up @@ -215,6 +228,7 @@ const emit = defineEmits<{
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
const _toast = useToast()
const expandedVersions = ref<Record<string, boolean>>({})
const searchQuery = ref('')

// --- Close Logic ---
const close = () => {
Expand All @@ -227,6 +241,23 @@ const sortedHistory = computed(() => {
return props.history.sort((a, b) => b.currentRecord.timestamp - a.currentRecord.timestamp)
})

const filteredHistory = computed(() => {
if (!searchQuery.value) return sortedHistory.value

const query = searchQuery.value.toLowerCase()
return sortedHistory.value.filter(chain => {
// 匹配原始提示词
if (chain.rootRecord.originalPrompt.toLowerCase().includes(query)) return true

// 匹配版本中的内容
return chain.versions.some(record => {
if (record.optimizedPrompt.toLowerCase().includes(query)) return true
if (record.iterationNote && record.iterationNote.toLowerCase().includes(query)) return true
return false
})
})
})

// 切换版本展开/收起状态
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
const _toggleVersion = (recordId: string) => {
Expand All @@ -247,8 +278,9 @@ const handleClear = async () => {
// 监听显示状态变化
watch(() => props.show, (newShow) => {
if (!newShow) {
// 关闭时重置所有展开状态
// 关闭时重置所有展开状态和搜索词
expandedVersions.value = {}
searchQuery.value = ''
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/i18n/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ export default {
title: "History",
iterationNote: "Iteration Note",
optimizedPrompt: "Optimized Prompt",
searchPlaceholder: "Search history...",
confirmClear:
"Are you sure you want to clear all history records? This action cannot be undone.",
confirmDeleteChain:
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/i18n/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ export default {
title: "历史记录",
iterationNote: "迭代说明",
optimizedPrompt: "优化后",
searchPlaceholder: "搜索历史记录...",
confirmClear: "确定要清空所有历史记录吗?此操作不可恢复。",
confirmDeleteChain: "确定要删除此条历史记录吗?此操作不可恢复。",
cleared: "历史记录已清空",
Expand Down