Skip to content

Commit 3517019

Browse files
feat(data_collection): adds data collection info to calls (#77)
* feat(data_collection): adds data collection info to calls * make init calls in parallel
1 parent e4a1808 commit 3517019

File tree

12 files changed

+169
-11
lines changed

12 files changed

+169
-11
lines changed

src/App.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ const { getSourcesList, getInfoPerCorpus } = useSourcesStore();
1616
const userStore = useUserStore();
1717
const screenWidth = computed(() => window.innerWidth);
1818
const fetchError = ref(false);
19+
20+
async function initCalls() {
21+
await Promise.all([
22+
getInfoPerCorpus(),
23+
getSourcesList(),
24+
userStore.setUserIdAndSessionId(getQueryParamValue('referer') || '')
25+
]);
26+
}
27+
1928
onMounted(async () => {
2029
try {
21-
await getInfoPerCorpus();
22-
await userStore.setUserIdAndSessionId(getQueryParamValue('referer'));
23-
await getSourcesList();
30+
await initCalls();
2431
} catch (error) {
2532
fetchError.value = true;
2633
}

src/components/CardComponent.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const props = defineProps<{
2424
isBookmarked: boolean;
2525
hasFullDescription?: boolean;
2626
slice?: string;
27+
id?: string;
28+
docMetrics?: (docId?: string | undefined) => Promise<void>;
2729
}>();
2830
2931
const toggleShowMoreAuthors = () => {
@@ -49,7 +51,7 @@ const corpusDetails = computed(() => props.details.journal || props.details.publ
4951
<p class="doc-number">{{ number }}</p>
5052
</div>
5153
<p class="card-header-title">
52-
<a target="_blank" :href="url">
54+
<a target="_blank" :href="url" @click.stop @click="docMetrics && docMetrics(id)">
5355
{{ title }}
5456
</a>
5557
</p>

src/components/CardSimpleComponent.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ defineProps<{
1212
title: string;
1313
corpus: string;
1414
url: string;
15+
id?: string;
1516
sdg: number[];
1617
details: DocumentDetails;
1718
hideRefIndicator?: boolean;
1819
shouldDisplayScore?: boolean;
1920
score?: number;
2021
toggleBookmark?: () => void;
2122
isBookmarked?: boolean;
23+
docMetrics?: (docId?: string | undefined) => Promise<void>;
2224
}>();
2325
2426
const isModalActive = ref(false);
@@ -78,7 +80,13 @@ const handleModalOpen = () => {
7880
:isBookmarked="!!isBookmarked"
7981
:toggleBookmark="toggleBookmark"
8082
/>
81-
<a class="icon-wrapper" target="_blank" :href="url" @click.stop>
83+
<a
84+
class="icon-wrapper"
85+
target="_blank"
86+
:href="url"
87+
@click.stop
88+
@click="docMetrics && docMetrics(id)"
89+
>
8290
<OpenUrlIcon class="icon is-small" />
8391
<TooltipComponent class="tltip" :tooltipText="$t('cardArticle.openArticle')" isLeft />
8492
</a>

src/components/NavComponent.vue

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import i18n from '@/localisation/i18n';
1010
import BookIcon from '@/components/icons/BookIcon.vue';
1111
import NavBookmarkIcon from '@/components/icons/NavBookmarkIcon.vue';
1212
import { useFeatureFlipStore } from '@/stores/featureFlip';
13+
import { useMetricsStore } from '@/stores/metrics';
1314
1415
const featureFlip = useFeatureFlipStore();
16+
const metricStore = useMetricsStore();
1517
const isFeatureEnabled = featureFlip.isFeatureEnabled('tutor');
1618
const isFeatureEnabledMicrolearning = featureFlip.isFeatureEnabled('microlearning');
19+
const isWorkshopFeatureEnabled = featureFlip.isWorkshopFeatureEnabled();
1720
1821
const isNavOpened = ref<boolean>(false);
1922
@@ -120,6 +123,17 @@ const handle_nav_bookmarks = () => {
120123
}}</span>
121124
</router-link>
122125
</div>
126+
<a
127+
class="mx-0 px-0"
128+
v-if="isWorkshopFeatureEnabled"
129+
target="_blank"
130+
:href="metricStore.getWorkshopFormUrl"
131+
>
132+
<span class="item-name router-link-form has-text-success mx-1 px-1 pr-4 is-size-6">{{
133+
$t('nav.workshopForm')
134+
}}</span>
135+
</a>
136+
123137
<div class="nav-langs" :class="isNavOpened && 'open'">
124138
<a
125139
class="nav-lang"
@@ -228,10 +242,27 @@ const handle_nav_bookmarks = () => {
228242
display: flex;
229243
align-items: center;
230244
justify-content: flex-start;
231-
gap: 0.5rem;
245+
gap: 0.2rem;
232246
cursor: pointer;
233247
padding: 0.75rem 1rem;
234248
width: calc(100% - 2rem);
249+
flex-wrap: nowrap;
250+
white-space: nowrap;
251+
}
252+
253+
.router-link-form {
254+
all: unset;
255+
display: flex;
256+
align-items: center;
257+
justify-content: flex-start;
258+
gap: 0.2rem;
259+
cursor: pointer;
260+
width: calc(100% - 2rem);
261+
flex-wrap: nowrap;
262+
white-space: nowrap;
263+
&:hover {
264+
background-color: var(--neutral-15);
265+
}
235266
}
236267
237268
.router-link-active {
@@ -244,6 +275,7 @@ const handle_nav_bookmarks = () => {
244275
white-space: nowrap;
245276
opacity: 0;
246277
transition: opacity 0.5s ease-in-out;
278+
flex-wrap: nowrap;
247279
}
248280
249281
.item-name.visible-name {
@@ -256,7 +288,7 @@ const handle_nav_bookmarks = () => {
256288
@media screen and (min-width: 992px) {
257289
.nav {
258290
flex-grow: 1;
259-
gap: 0.75rem;
291+
gap: 0.2rem;
260292
padding: 0rem;
261293
display: flex;
262294
flex-direction: row;
@@ -291,6 +323,8 @@ const handle_nav_bookmarks = () => {
291323
visibility: visible;
292324
opacity: 1;
293325
width: auto;
326+
white-space: nowrap;
327+
flex-wrap: nowrap;
294328
}
295329
296330
.link-wrapper {

src/components/SourcesListComponent.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import Card from '@/components/CardComponent.vue';
44
import SimpleCard from '@/components/CardSimpleComponent.vue';
55
import ToasterComponentVue from '@/components/ToasterComponent.vue';
66
import { useSourcesStore } from '@/stores/sources';
7+
import { useMetricsStore } from '@/stores/metrics';
78
import { useBookmarksStore } from '@/stores/bookmarks';
89
import ModalWrapper from '@/components/ModalWrapper.vue';
910
import i18n from '@/localisation/i18n';
1011
1112
const sourcesStore = useSourcesStore();
13+
const metricsStore = useMetricsStore();
1214
const store = useBookmarksStore();
1315
1416
const props = defineProps<{
@@ -70,6 +72,8 @@ const ChosenCard = Cards[props.cardType || 'default'];
7072
:toggleBookmark="() => store.toggleBookmark(doc)"
7173
:isBookmarked="store.isBookmarked(doc.payload.document_id)"
7274
:slice="doc.payload.slice_content"
75+
:id="doc.payload.document_id"
76+
:docMetrics="metricsStore.recordClickedDocumentFromchat"
7377
>
7478
<template #modal="scope">
7579
<ModalWrapper :key="`modal-${doc.id}`" :isOpen="scope.isOpen" :onClose="scope.onClose">

src/localisation/en.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ export const en = {
231231
syllabus: 'Create a syllabus',
232232
about: 'About',
233233
help: 'Help',
234-
microlearning: 'Micro-learning'
234+
microlearning: 'Micro-learning',
235+
workshopForm: 'Workshop Form'
235236
},
236237

237238
next: 'Next',

src/localisation/fr.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ export const fr = {
234234
syllabus: 'Créer un syllabus',
235235
about: 'À propos',
236236
help: 'Aide',
237-
microlearning: 'Micro-learning'
237+
microlearning: 'Micro-learning',
238+
workshopForm: "Formulaire d'atelier"
238239
},
239240

240241
next: 'Suivant',

src/stores/chat.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const useChatStore = defineStore('chat', () => {
3131
const sourcesList: Ref<Document[] | null> = ref(getFromStorage('chatSources') || []);
3232
const reformulatedQuery: Ref<string | null> = ref(getFromStorage('reformulatedQuery'));
3333
const queryToSearch: Ref<string | null> = ref(null);
34+
const storedConversationId: Ref<string | null> = ref(localStorage.getItem('chatConversationId'));
35+
const storedMessageId: Ref<string | null> = ref(localStorage.getItem('chatMessageId'));
3436

3537
const isChatEmpty: ComputedRef<Boolean> = computed(() => chatMessagesList.value.length === 0);
3638
const chatStatus: Ref<CHAT_STATUSES_TYPE> = ref(
@@ -208,9 +210,25 @@ export const useChatStore = defineStore('chat', () => {
208210
}
209211
}
210212

213+
function storeConversationId(conversationId: string) {
214+
if (conversationId !== storedConversationId.value) {
215+
localStorage.setItem('chatConversationId', conversationId);
216+
storedConversationId.value = conversationId;
217+
}
218+
}
219+
220+
function storeMessageId(messageId: string) {
221+
if (messageId !== storedMessageId.value) {
222+
console.log('Storing message ID:', messageId);
223+
localStorage.setItem('chatMessageId', messageId);
224+
storedMessageId.value = messageId;
225+
}
226+
}
227+
211228
async function getNoStreamAnswer(userMsg: string) {
212229
chatStatus.value = CHAT_STATUS.FORMULATING_ANSWER;
213230
const bodyContent = {
231+
conversation_id: storedConversationId.value,
214232
sources: sourcesList.value || [],
215233
history: getMessageHistory.value,
216234
query: userMsg,
@@ -221,8 +239,10 @@ export const useChatStore = defineStore('chat', () => {
221239

222240
chatStatus.value = CHAT_STATUS.FORMULATED_ANSWER;
223241

224-
chatMessagesList.value.push({ role: 'assistant', content: respBody.data });
242+
chatMessagesList.value.push({ role: 'assistant', content: respBody.data.answer });
225243
saveToStorage('chat', chatMessagesList.value);
244+
storeConversationId(respBody.data.conversation_id);
245+
storeMessageId(respBody.data.message_id);
226246

227247
const newQuestions: AxiosResponse<{ NEW_QUESTIONS: string[] }> = await postAxios(
228248
'/qna/reformulate/questions',
@@ -322,11 +342,15 @@ export const useChatStore = defineStore('chat', () => {
322342
reformulatedQuery.value = null;
323343
shouldFetchNewDocuments.value = true;
324344
storedSubject.value = undefined;
345+
storedConversationId.value = null;
346+
storedMessageId.value = null;
325347
clearFromStorage('chat');
326348
clearFromStorage('chatSources');
327349
clearFromStorage('questionQueues');
328350
clearFromStorage('reformulatedQuery');
329351
clearFromStorage('chatSubject');
352+
clearFromStorage('chatConversationId');
353+
clearFromStorage('chatMessageId');
330354
}
331355

332356
return {

src/stores/featureFlip.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ export const useFeatureFlipStore = defineStore('featureFlip', () => {
1313
return featureFlip[feature] || false;
1414
};
1515

16+
const isWorkshopFeatureEnabled = () => {
17+
// it should be active if url includes 'workshop'
18+
return isDevEnvironment || window.location.href.includes('workshop');
19+
};
20+
1621
return {
1722
featureFlip,
18-
isFeatureEnabled
23+
isFeatureEnabled,
24+
isWorkshopFeatureEnabled
1925
};
2026
});

src/stores/metrics.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { updateClickedDocument } from '@/utils/metrics';
2+
import { isInPage } from '@/utils/urlsUtils';
3+
import { defineStore } from 'pinia';
4+
import { ref, computed } from 'vue';
5+
6+
export const useMetricsStore = defineStore('metrics', () => {
7+
const userId = ref<string | null>(localStorage.getItem('userId'));
8+
9+
const getUserId = computed(() => userId.value);
10+
const getWorkshopFormUrl = computed(() => {
11+
return `https://docs.google.com/forms/d/e/1FAIpQLSeUf3GQXt3LsZD24Z3fGkwUE-qhAXF2jkem9zbPnAbnOrReDQ/viewform?usp=pp_url&entry.736499817=${userId.value}`;
12+
});
13+
14+
const getCampaignStatus = async () => {
15+
// Logic to get campaign status
16+
return await true;
17+
};
18+
19+
const recordClickedDocumentFromchat = async (docId: string) => {
20+
// check if in campaign
21+
if (await !getCampaignStatus()) {
22+
return;
23+
}
24+
25+
if (!isInPage('q-and-a')) {
26+
return;
27+
}
28+
// get message id from storage
29+
const messageId = localStorage.getItem('chatMessageId');
30+
31+
if (!messageId || !docId) {
32+
return;
33+
}
34+
35+
// Logic to add clicked document
36+
await updateClickedDocument(docId, messageId);
37+
};
38+
39+
return {
40+
getUserId,
41+
recordClickedDocumentFromchat,
42+
getWorkshopFormUrl
43+
};
44+
});

0 commit comments

Comments
 (0)