mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	 2f3b4ad215
			
		
	
	2f3b4ad215
	
	
	
		
			
			Linked PR https://github.com/chatwoot/chatwoot/pull/12113 ## Linear Link https://linear.app/chatwoot/issue/CW-4515/upload-pdfs-to-captain ## Description This PR adds support for PDF file uploads to the Captain document knowledge base system. The feature enables users to upload PDF files directly to the knowledge base for FAQ generation and document processing, expanding beyond the existing URL-based document ingestion. ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Unit Tests - Manually via UI ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com>
		
			
				
	
	
		
			134 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			134 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <script setup>
 | |
| import { ref, computed, watch, nextTick } from 'vue';
 | |
| import { OnClickOutside } from '@vueuse/components';
 | |
| import { useI18n } from 'vue-i18n';
 | |
| 
 | |
| import Button from 'dashboard/components-next/button/Button.vue';
 | |
| import ComboBoxDropdown from 'dashboard/components-next/combobox/ComboBoxDropdown.vue';
 | |
| 
 | |
| const props = defineProps({
 | |
|   options: {
 | |
|     type: Array,
 | |
|     required: true,
 | |
|     validator: value =>
 | |
|       value.every(option => 'value' in option && 'label' in option),
 | |
|   },
 | |
|   placeholder: { type: String, default: '' },
 | |
|   modelValue: { type: [String, Number], default: '' },
 | |
|   disabled: { type: Boolean, default: false },
 | |
|   searchPlaceholder: { type: String, default: '' },
 | |
|   emptyState: { type: String, default: '' },
 | |
|   message: { type: String, default: '' },
 | |
|   hasError: { type: Boolean, default: false },
 | |
|   useApiResults: { type: Boolean, default: false }, // useApiResults prop to determine if search is handled by API
 | |
| });
 | |
| 
 | |
| const emit = defineEmits(['update:modelValue', 'search']);
 | |
| 
 | |
| const { t } = useI18n();
 | |
| 
 | |
| const selectedValue = ref(props.modelValue);
 | |
| const open = ref(false);
 | |
| const search = ref('');
 | |
| const dropdownRef = ref(null);
 | |
| const comboboxRef = ref(null);
 | |
| 
 | |
| const filteredOptions = computed(() => {
 | |
|   // For API search, don't filter options locally
 | |
|   if (props.useApiResults && search.value) {
 | |
|     return props.options;
 | |
|   }
 | |
| 
 | |
|   // For local search, filter options based on search term
 | |
|   const searchTerm = search.value.toLowerCase();
 | |
|   return props.options.filter(option =>
 | |
|     option.label.toLowerCase().includes(searchTerm)
 | |
|   );
 | |
| });
 | |
| const selectPlaceholder = computed(() => {
 | |
|   return props.placeholder || t('COMBOBOX.PLACEHOLDER');
 | |
| });
 | |
| const selectedLabel = computed(() => {
 | |
|   const selected = props.options.find(
 | |
|     option => option.value === selectedValue.value
 | |
|   );
 | |
|   return selected?.label ?? selectPlaceholder.value;
 | |
| });
 | |
| 
 | |
| const selectOption = option => {
 | |
|   selectedValue.value = option.value;
 | |
|   emit('update:modelValue', option.value);
 | |
|   open.value = false;
 | |
|   search.value = '';
 | |
| };
 | |
| 
 | |
| const toggleDropdown = () => {
 | |
|   if (props.disabled) return;
 | |
|   open.value = !open.value;
 | |
|   if (open.value) {
 | |
|     search.value = '';
 | |
|     nextTick(() => dropdownRef.value?.focus());
 | |
|   }
 | |
| };
 | |
| 
 | |
| watch(
 | |
|   () => props.modelValue,
 | |
|   newValue => {
 | |
|     selectedValue.value = newValue;
 | |
|   }
 | |
| );
 | |
| </script>
 | |
| 
 | |
| <template>
 | |
|   <div
 | |
|     ref="comboboxRef"
 | |
|     class="relative w-full min-w-0"
 | |
|     :class="{
 | |
|       'cursor-not-allowed': disabled,
 | |
|       'group/combobox': !disabled,
 | |
|     }"
 | |
|     @click.prevent
 | |
|   >
 | |
|     <OnClickOutside @trigger="open = false">
 | |
|       <Button
 | |
|         variant="outline"
 | |
|         :color="hasError && !open ? 'ruby' : open ? 'blue' : 'slate'"
 | |
|         :label="selectedLabel"
 | |
|         trailing-icon
 | |
|         :disabled="disabled"
 | |
|         class="justify-between w-full !px-3 !py-2.5 text-n-slate-12 font-normal group-hover/combobox:border-n-slate-6 focus:outline-n-brand"
 | |
|         :class="{
 | |
|           focused: open,
 | |
|           '[&:not(.focused)]:dark:outline-n-weak [&:not(.focused)]:hover:enabled:outline-n-slate-6 [&:not(.focused)]:dark:hover:enabled:outline-n-slate-6':
 | |
|             !hasError,
 | |
|         }"
 | |
|         :icon="open ? 'i-lucide-chevron-up' : 'i-lucide-chevron-down'"
 | |
|         @click="toggleDropdown"
 | |
|       />
 | |
| 
 | |
|       <ComboBoxDropdown
 | |
|         ref="dropdownRef"
 | |
|         v-model:search-value="search"
 | |
|         :open="open"
 | |
|         :options="filteredOptions"
 | |
|         :search-placeholder="searchPlaceholder"
 | |
|         :empty-state="emptyState"
 | |
|         :selected-values="selectedValue"
 | |
|         @search="emit('search', $event)"
 | |
|         @select="selectOption"
 | |
|       />
 | |
| 
 | |
|       <p
 | |
|         v-if="message"
 | |
|         class="mt-2 mb-0 text-xs truncate transition-all duration-500 ease-in-out"
 | |
|         :class="{
 | |
|           'text-n-ruby-9': hasError,
 | |
|           'text-n-slate-11': !hasError,
 | |
|         }"
 | |
|       >
 | |
|         {{ message }}
 | |
|       </p>
 | |
|     </OnClickOutside>
 | |
|   </div>
 | |
| </template>
 |