Skip to content

Commit c807a78

Browse files
committed
fix: create chat from datasource card
1 parent d69002d commit c807a78

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

frontend/src/router/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const router = createRouter({
3636
path: 'index',
3737
name: 'chat',
3838
component: chat,
39+
props: (route) => {
40+
return { startChatDsId: route.query.start_chat }
41+
},
3942
meta: { title: t('menu.Data Q&A'), icon: 'chat' },
4043
},
4144
],

frontend/src/views/chat/ChatCreator.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import { chatApi, ChatInfo } from '@/api/chat.ts'
33
import { onMounted, ref } from 'vue'
44
import { datasourceApi } from '@/api/datasource.ts'
55
import DatasourceItemCard from '../ds/DatasourceItemCard.vue'
6-
import { useRoute } from 'vue-router'
6+
7+
const props = withDefaults(
8+
defineProps<{
9+
hidden?: boolean
10+
}>(),
11+
{
12+
hidden: false,
13+
}
14+
)
715
816
const dsList = ref<Array<any>>([])
917
@@ -14,7 +22,6 @@ function listDs() {
1422
dsList.value = res
1523
})
1624
}
17-
const route = useRoute()
1825
1926
const dialogVisible = ref(false)
2027
@@ -67,20 +74,21 @@ function createChat(datasource: number) {
6774
}
6875
6976
onMounted(() => {
77+
if (props.hidden) {
78+
return
79+
}
7080
listDs()
71-
const id = route.query.id as unknown as number
72-
if (!id) return
73-
createChat(id)
7481
})
7582
7683
defineExpose({
7784
showDs,
7885
hideDs,
86+
createChat,
7987
})
8088
</script>
8189

8290
<template>
83-
<div>
91+
<div v-if="!hidden">
8492
<el-drawer
8593
ref="DatasourceListRef"
8694
v-model="dialogVisible"

frontend/src/views/chat/index.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
</el-container>
286286

287287
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
288+
<ChatCreator ref="hiddenChatCreatorRef" hidden @on-chat-created="onChatCreatedQuick" />
288289
</el-container>
289290
</template>
290291

@@ -313,6 +314,11 @@ import logo from '@/assets/LOGO.svg'
313314
import icon_send_filled from '@/assets/svg/icon_send_filled.svg'
314315
315316
import { useAssistantStore } from '@/stores/assistant'
317+
318+
const props = defineProps<{
319+
startChatDsId?: number
320+
}>()
321+
316322
const assistantStore = useAssistantStore()
317323
318324
const isAssistant = computed(() => assistantStore.getAssistant)
@@ -367,7 +373,6 @@ const computedMessages = computed<Array<ChatMessage>>(() => {
367373
})
368374
}
369375
370-
console.log(messages)
371376
return messages
372377
})
373378
@@ -390,7 +395,6 @@ const createNewChat = async () => {
390395
}
391396
return
392397
}
393-
console.log(chatCreatorRef.value)
394398
chatCreatorRef.value?.showDs()
395399
}
396400
@@ -745,6 +749,18 @@ defineExpose({
745749
getCurrentChatId,
746750
createNewChat,
747751
})
752+
753+
const hiddenChatCreatorRef = ref()
754+
755+
onMounted(() => {
756+
if (props.startChatDsId) {
757+
const _id = props.startChatDsId
758+
nextTick(() => {
759+
hiddenChatCreatorRef.value?.createChat(_id)
760+
})
761+
// todo remove 'start_chat' in url
762+
}
763+
})
748764
</script>
749765

750766
<style lang="less" scoped>

frontend/src/views/ds/Datasource.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const handleQuestion = (id: string) => {
9797
router.push({
9898
path: '/chat/index',
9999
query: {
100-
id,
100+
start_chat: id,
101101
},
102102
})
103103
}

0 commit comments

Comments
 (0)