From b9e11c4263356cd832147664d27dfe7ac0486da6 Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 6 Jan 2025 17:57:37 +0100 Subject: [PATCH] fix_process_id --- src/pages/process/process.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/pages/process/process.ts b/src/pages/process/process.ts index 27f9752..a942c48 100755 --- a/src/pages/process/process.ts +++ b/src/pages/process/process.ts @@ -177,9 +177,19 @@ function populateAutocompleteList(select: HTMLSelectElement, query: string, drop if (dropdown) { let messagingCounter = 1; + const messagingOptions = autocomplete_options.filter(option => option === 'messaging'); + options_to_show = autocomplete_options.map(option => { if (option === 'messaging') { - return `messaging ${messagingCounter++}`; + const allMessagingOptions = select.querySelectorAll('option[value="messaging"]'); + const currentMessagingOption = allMessagingOptions[messagingCounter - 1]; + const processId = currentMessagingOption?.getAttribute('data-process-id'); + const optionText = `messaging ${messagingCounter}`; + + // Stocker le processId avec son index spécifique + select.setAttribute(`data-messaging-id-${messagingCounter}`, processId || ''); + messagingCounter++; + return optionText; } return option; }); @@ -221,17 +231,30 @@ function populateAutocompleteList(select: HTMLSelectElement, query: string, drop // Listener to autocomplete results when clicked set the selected property in the select option function selectOption(e: any) { - console.log('🚀 ~ selectOption ~ e:', e); + console.log('🎯 Click event:', e); + console.log('🎯 Target value:', e.target.dataset.value); + const wrapper = e.target.parentNode.parentNode.parentNode; + const select = wrapper.querySelector('select'); const input_search = wrapper.querySelector('.selected-input'); const option = wrapper.querySelector(`select option[value="${e.target.dataset.value}"]`); + + console.log('🎯 Selected option:', option); + console.log('🎯 Process ID:', option?.getAttribute('data-process-id')); - console.log('🚀 ~ selectOption ~ option:', option); if (e.target.dataset.value.includes('messaging')) { + const messagingNumber = parseInt(e.target.dataset.value.split(' ')[1]); + const processId = select.getAttribute(`data-messaging-id-${messagingNumber}`); + + console.log('🎯 Navigating to chat with process:', { + value: e.target.dataset.value, + processId: processId + }); + const event = new CustomEvent('navigate', { detail: { page: 'chat', - processId: option?.getAttribute('data-process-id') || '' + processId: processId || '' } }); document.dispatchEvent(event);