Skip to content

Commit d437f9d

Browse files
committed
feat(contact chat search): display result sources as a readable link
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent f0ccd27 commit d437f9d

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

src/components/ContextChat/ContextChatSearchOutputForm.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@
77
<label class="cc-output__sources__label">
88
{{ outputShape.sources.description }}
99
</label>
10-
<NcRichText v-for="(source, i) in sources"
11-
:key="'source-' + i"
12-
:text="source.url"
13-
:use-markdown="false"
14-
:reference-limit="1"
15-
:autolink="true" />
10+
<ContextChatSource v-for="(source, i) in sources"
11+
:key="'source-' + i + '-' + source.url"
12+
:source="source" />
1613
</div>
1714
</template>
1815

1916
<script>
20-
import { NcRichText } from '@nextcloud/vue/dist/Components/NcRichText.js'
17+
import ContextChatSource from './ContextChatSource.vue'
2118
2219
export default {
2320
name: 'ContextChatSearchOutputForm',
2421
2522
components: {
26-
NcRichText,
23+
ContextChatSource,
2724
},
2825
2926
props: {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
<template>
6+
<NcRichText
7+
:text="text"
8+
:use-markdown="true"
9+
:reference-limit="1"
10+
:references="references"
11+
:autolink="true" />
12+
</template>
13+
14+
<script>
15+
import { NcRichText } from '@nextcloud/vue/dist/Components/NcRichText.js'
16+
17+
import { generateOcsUrl } from '@nextcloud/router'
18+
import axios from '@nextcloud/axios'
19+
20+
export default {
21+
name: 'ContextChatSource',
22+
23+
components: {
24+
NcRichText,
25+
},
26+
27+
props: {
28+
source: {
29+
type: Object,
30+
required: true,
31+
},
32+
},
33+
34+
data: () => {
35+
return {
36+
// we could initialize this with undefined but then NcRichText will try to find links
37+
// and resolve them before we had a chance to do so, resulting in unnecessary requests to references/resolve
38+
// with [] we inhibit the extract+resolve mechanism on NcRichText
39+
// TODO This can be removed (and all the custom extract+resolve logic) when fixed in NcRichText
40+
references: [],
41+
}
42+
},
43+
44+
computed: {
45+
text() {
46+
return '[' + this.source.label + '](' + this.source.url + ')'
47+
},
48+
},
49+
50+
mounted() {
51+
this.fetch()
52+
},
53+
54+
methods: {
55+
fetch() {
56+
axios.get(generateOcsUrl('references/resolve') + `?reference=${encodeURIComponent(this.source.url)}`)
57+
.then((response) => {
58+
this.references = Object.values(response.data.ocs.data.references)
59+
})
60+
.catch((error) => {
61+
console.error('Failed to extract references', error)
62+
})
63+
},
64+
},
65+
}
66+
</script>
67+
68+
<style lang="scss" scoped>
69+
// nothing yet
70+
</style>

0 commit comments

Comments
 (0)