fix picklist
This commit is contained in:
@@ -229,7 +229,12 @@ const filteredInputs = computed(() => {
|
||||
const filtered = {};
|
||||
for (const [key, value] of Object.entries(inputs.value)) {
|
||||
// Escludi tutti i campi che contengono "input_multiselect" e finiscono con "_id"
|
||||
if (!(key.includes('input_multiselect') && key.endsWith('_id'))) {
|
||||
// Escludi anche i campi "SelectedFolders_Name" e "SelectedFolders_Id"
|
||||
const shouldExclude = (key.includes('input_multiselect') && key.endsWith('_id')) ||
|
||||
key === 'selectedFolders_id' ||
|
||||
key === 'selectedFolders_name';
|
||||
|
||||
if (!shouldExclude) {
|
||||
filtered[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
:loading="loadingOptionsFor[input.dataSource] || false"
|
||||
:show-status="input.dataSource === 'ksDocuments'"
|
||||
no-margin
|
||||
@change="onDynamicPickerChange(input.name, $event)"
|
||||
@change="onDynamicPickerChange(input.name, $event, input.dataSource)"
|
||||
/>
|
||||
</div>
|
||||
<div v-else>
|
||||
@@ -432,12 +432,48 @@ const extractFoldersFromItems = (items) => {
|
||||
const folderSet = new Set();
|
||||
|
||||
items.forEach((item) => {
|
||||
// Filtra solo gli items che hanno il campo ingestionStatusV2
|
||||
if (!item.ingestionStatusV2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const path = item.ingestionInfo?.metadata?.ksKnowledgePath;
|
||||
if (!path) return;
|
||||
|
||||
// Gestisci item nella root (senza path o con path vuoto o "/")
|
||||
if (!path || path === '/' || path.trim() === '') {
|
||||
const rootPath = '/';
|
||||
folderSet.add(rootPath);
|
||||
|
||||
if (!folderMap[rootPath]) {
|
||||
folderMap[rootPath] = [];
|
||||
}
|
||||
|
||||
folderMap[rootPath].push({
|
||||
id: item.id,
|
||||
type: item.fileName ? 'document' : 'video',
|
||||
name: item.fileName || item.name
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Rimuovi il leading slash se presente
|
||||
const cleanPath = path.startsWith('/') ? path.substring(1) : path;
|
||||
if (!cleanPath) return;
|
||||
if (!cleanPath) {
|
||||
// Se dopo la pulizia il path è vuoto, è un item root
|
||||
const rootPath = '/';
|
||||
folderSet.add(rootPath);
|
||||
|
||||
if (!folderMap[rootPath]) {
|
||||
folderMap[rootPath] = [];
|
||||
}
|
||||
|
||||
folderMap[rootPath].push({
|
||||
id: item.id,
|
||||
type: item.fileName ? 'document' : 'video',
|
||||
name: item.fileName || item.name
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Dividi il path in parti
|
||||
const parts = cleanPath.split('/');
|
||||
@@ -481,12 +517,33 @@ const loadKsFolders = async () => {
|
||||
// Estrai folder e crea la mappa
|
||||
const { folders, folderMap } = extractFoldersFromItems(allItems);
|
||||
|
||||
// Calcola il numero di subfolder per ogni folder
|
||||
const subfolderCounts = {};
|
||||
folders.forEach((folderPath) => {
|
||||
// Conta quante folder hanno questo path come parent
|
||||
const subfolderCount = folders.filter((otherPath) => {
|
||||
if (otherPath === folderPath) return false;
|
||||
|
||||
// Gestione speciale per la root: conta solo le folder di primo livello
|
||||
if (folderPath === '/') {
|
||||
// Una folder è di primo livello se non contiene altri "/" dopo il primo
|
||||
return otherPath !== '/' && otherPath.substring(1).indexOf('/') === -1;
|
||||
}
|
||||
|
||||
// Verifica se otherPath è una sottocartella diretta di folderPath
|
||||
const relativePath = otherPath.substring(folderPath.length);
|
||||
return relativePath.startsWith('/') && relativePath.substring(1).split('/').length === 1;
|
||||
}).length;
|
||||
subfolderCounts[folderPath] = subfolderCount;
|
||||
});
|
||||
|
||||
// Crea la struttura per la picklist
|
||||
ksFolders.value = folders.map((path) => ({
|
||||
id: path,
|
||||
name: path,
|
||||
name: path === '/' ? '/ (Root)' : path, // Nome più chiaro per la root
|
||||
path: path,
|
||||
itemCount: folderMap[path]?.length || 0
|
||||
itemCount: folderMap[path]?.length || 0,
|
||||
subfolderCount: subfolderCounts[path] || 0
|
||||
}));
|
||||
|
||||
// Salva la mappa folder->items per uso successivo
|
||||
@@ -996,9 +1053,38 @@ const getOptionsForInput = (input) => {
|
||||
}
|
||||
};
|
||||
|
||||
const onDynamicPickerChange = (inputName, value) => {
|
||||
const onDynamicPickerChange = (inputName, value, dataSource) => {
|
||||
console.log(`Dynamic picker changed for ${inputName}:`, value);
|
||||
formData.value[inputName] = value;
|
||||
|
||||
// Gestione speciale per ksFolders: se seleziono una folder padre, seleziono anche tutte le subfolder
|
||||
if (dataSource === 'ksFolders' && Array.isArray(value)) {
|
||||
const expandedSelection = new Set();
|
||||
|
||||
// Aggiungi tutte le folder selezionate dall'utente
|
||||
value.forEach(folder => {
|
||||
const folderPath = folder.path || folder.id || folder;
|
||||
expandedSelection.add(folderPath);
|
||||
|
||||
// Trova e aggiungi tutte le subfolder (ricorsivamente)
|
||||
ksFolders.value.forEach(subfolder => {
|
||||
const subfolderPath = subfolder.path;
|
||||
// Una subfolder ha come prefisso il path della folder padre seguito da '/'
|
||||
if (subfolderPath !== folderPath && subfolderPath.startsWith(folderPath + '/')) {
|
||||
expandedSelection.add(subfolderPath);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Converti il Set in un array di oggetti folder completi
|
||||
const expandedFolders = Array.from(expandedSelection).map(path =>
|
||||
ksFolders.value.find(f => f.path === path)
|
||||
).filter(f => f !== undefined);
|
||||
|
||||
console.log(`Expanded selection from ${value.length} to ${expandedFolders.length} folders`);
|
||||
formData.value[inputName] = expandedFolders;
|
||||
} else {
|
||||
formData.value[inputName] = value;
|
||||
}
|
||||
};
|
||||
|
||||
// Carica le opzioni necessarie basate sui dataSource presenti negli inputs dello scenario
|
||||
|
||||
Reference in New Issue
Block a user