perf(bulk-api-tester): resolve collections search lag with pre-indexing, debouncing, and token matching
This commit is contained in:
+415
-105
@@ -136,9 +136,9 @@ const App = {
|
||||
</div>
|
||||
<div class="sidebar-search-container" id="search-wrap">
|
||||
<i class="fa-solid fa-magnifying-glass" style="position:absolute;left:22px;top:17px;transform:translateY(-50%);color:var(--text-4);font-size:10px;pointer-events:none;z-index:1;"></i>
|
||||
<input type="text" id="search-input" class="sidebar-search-input" placeholder="Search collections & endpoints…" value="" oninput="App.filterSidebarCollections(this.value)" style="padding-left:30px;padding-right:48px;">
|
||||
<input type="text" id="search-input" class="sidebar-search-input" placeholder="Search collections & endpoints…" value="" oninput="App.onSearchInput(this.value)" onkeydown="App.onSearchKeydown(event)" style="padding-left:30px;padding-right:48px;" autocomplete="off" spellcheck="false">
|
||||
<span class="search-kbd-badge" id="search-kbd-badge" style="position:absolute;right:22px;top:17px;transform:translateY(-50%);font-size:10px;font-family:var(--font-mono);font-weight:700;color:var(--text-4);background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.08);padding:1px 5px;border-radius:4px;pointer-events:none;">⌘K</span>
|
||||
<button id="search-clear-btn" class="search-clear-btn" style="display:none;top:17px;" onclick="document.getElementById('search-input').value=''; App.filterSidebarCollections('');" title="Clear search"><i class="fa-solid fa-xmark"></i></button>
|
||||
<button id="search-clear-btn" class="search-clear-btn" style="display:none;top:17px;" onclick="App.clearSearch();" title="Clear search"><i class="fa-solid fa-xmark"></i></button>
|
||||
</div>
|
||||
<div class="history-list" id="collections-list"></div>
|
||||
<div class="sidebar-footer">
|
||||
@@ -608,6 +608,7 @@ const App = {
|
||||
} else if (data.length > 0) {
|
||||
this.state.spaces = data;
|
||||
}
|
||||
this.invalidateSearchIndex();
|
||||
|
||||
// Validate activeSpaceId
|
||||
if (this.state.activeSpaceId) {
|
||||
@@ -625,6 +626,7 @@ const App = {
|
||||
},
|
||||
|
||||
async saveSpacesToServer() {
|
||||
this.invalidateSearchIndex();
|
||||
try {
|
||||
await fetch('/api/spaces', {
|
||||
method: 'POST',
|
||||
@@ -1850,6 +1852,7 @@ const App = {
|
||||
},
|
||||
|
||||
_debouncedSaveSpaces() {
|
||||
this.invalidateSearchIndex();
|
||||
if (this._saveSpacesTimer) clearTimeout(this._saveSpacesTimer);
|
||||
this._saveSpacesTimer = setTimeout(() => this.saveSpacesToServer(), 1000);
|
||||
},
|
||||
@@ -3376,149 +3379,455 @@ const App = {
|
||||
}
|
||||
},
|
||||
|
||||
invalidateSearchIndex() {
|
||||
this._searchIndex = null;
|
||||
},
|
||||
|
||||
getSearchIndex() {
|
||||
if (this._searchIndex) return this._searchIndex;
|
||||
|
||||
const spaces = this.state.spaces || [];
|
||||
const index = [];
|
||||
|
||||
for (let sIdx = 0; sIdx < spaces.length; sIdx++) {
|
||||
const space = spaces[sIdx];
|
||||
const spaceName = space.name || 'Workspace';
|
||||
const cols = space.collections || [];
|
||||
|
||||
for (let cIdx = 0; cIdx < cols.length; cIdx++) {
|
||||
const col = cols[cIdx];
|
||||
const colName = col.name || 'Untitled';
|
||||
const normalizedColName = colName.replace(/[^a-zA-Z0-9]+/g, ' ');
|
||||
const colHaystack = `${colName} ${normalizedColName} ${spaceName}`.toLowerCase();
|
||||
|
||||
const reqs = col.requests || [];
|
||||
const indexedReqs = new Array(reqs.length);
|
||||
|
||||
for (let rIdx = 0; rIdx < reqs.length; rIdx++) {
|
||||
const r = reqs[rIdx];
|
||||
const rName = r.name || 'Untitled';
|
||||
const rUrl = r.url || '';
|
||||
const rDesc = r.description || '';
|
||||
const rMethod = r.method || 'GET';
|
||||
const normalizedReqName = rName.replace(/[^a-zA-Z0-9]+/g, ' ');
|
||||
const normalizedUrl = rUrl.replace(/[^a-zA-Z0-9]+/g, ' ');
|
||||
|
||||
indexedReqs[rIdx] = {
|
||||
id: r.id,
|
||||
name: rName,
|
||||
method: rMethod,
|
||||
url: rUrl,
|
||||
description: rDesc,
|
||||
raw: r,
|
||||
haystack: `${rName} ${normalizedReqName} ${rMethod} ${rUrl} ${normalizedUrl} ${rDesc}`.toLowerCase()
|
||||
};
|
||||
}
|
||||
|
||||
index.push({
|
||||
colId: col.id,
|
||||
colName: colName,
|
||||
spaceId: space.id,
|
||||
spaceName: spaceName,
|
||||
col: col,
|
||||
colHaystack: colHaystack,
|
||||
requests: indexedReqs
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this._searchIndex = index;
|
||||
return index;
|
||||
},
|
||||
|
||||
highlightSearchMatch(text, tokens) {
|
||||
if (!text) return '';
|
||||
if (!tokens || tokens.length === 0) return this.escapeHTML(String(text));
|
||||
|
||||
const cleanTokens = tokens
|
||||
.filter(t => t && t.trim().length > 0)
|
||||
.map(t => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
||||
|
||||
if (cleanTokens.length === 0) return this.escapeHTML(String(text));
|
||||
|
||||
const str = String(text);
|
||||
const regex = new RegExp(`(${cleanTokens.join('|')})`, 'gi');
|
||||
let result = '';
|
||||
let lastIndex = 0;
|
||||
let match;
|
||||
|
||||
while ((match = regex.exec(str)) !== null) {
|
||||
result += this.escapeHTML(str.slice(lastIndex, match.index));
|
||||
result += `<mark class="search-highlight">${this.escapeHTML(match[0])}</mark>`;
|
||||
lastIndex = regex.lastIndex;
|
||||
}
|
||||
result += this.escapeHTML(str.slice(lastIndex));
|
||||
return result;
|
||||
},
|
||||
|
||||
onSearchInput(val) {
|
||||
this._searchExpandedAll = {};
|
||||
const clearBtn = document.getElementById('search-clear-btn');
|
||||
const kbdBadge = document.getElementById('search-kbd-badge');
|
||||
const hasVal = Boolean(val && val.trim().length > 0);
|
||||
if (clearBtn) clearBtn.style.display = hasVal ? 'block' : 'none';
|
||||
if (kbdBadge) kbdBadge.style.display = hasVal ? 'none' : 'block';
|
||||
|
||||
if (this._searchDebounceTimer) {
|
||||
clearTimeout(this._searchDebounceTimer);
|
||||
this._searchDebounceTimer = null;
|
||||
}
|
||||
|
||||
if (!hasVal) {
|
||||
this.filterSidebarCollections('');
|
||||
return;
|
||||
}
|
||||
|
||||
// Micro-debounce (60ms) to guarantee smooth typing and 0 frame drops
|
||||
this._searchDebounceTimer = setTimeout(() => {
|
||||
this._searchDebounceTimer = null;
|
||||
requestAnimationFrame(() => {
|
||||
this.filterSidebarCollections(val);
|
||||
});
|
||||
}, 60);
|
||||
},
|
||||
|
||||
onSearchKeydown(event) {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
this.clearSearch();
|
||||
} else if (event.key === 'Enter') {
|
||||
if (this._searchDebounceTimer) {
|
||||
clearTimeout(this._searchDebounceTimer);
|
||||
this._searchDebounceTimer = null;
|
||||
}
|
||||
const val = event.target ? event.target.value : '';
|
||||
this.filterSidebarCollections(val);
|
||||
}
|
||||
},
|
||||
|
||||
clearSearch() {
|
||||
this._searchExpandedAll = {};
|
||||
const input = document.getElementById('search-input');
|
||||
if (input) {
|
||||
input.value = '';
|
||||
input.focus();
|
||||
}
|
||||
const clearBtn = document.getElementById('search-clear-btn');
|
||||
const kbdBadge = document.getElementById('search-kbd-badge');
|
||||
if (clearBtn) clearBtn.style.display = 'none';
|
||||
if (kbdBadge) kbdBadge.style.display = 'block';
|
||||
|
||||
if (this._searchDebounceTimer) {
|
||||
clearTimeout(this._searchDebounceTimer);
|
||||
this._searchDebounceTimer = null;
|
||||
}
|
||||
this.filterSidebarCollections('');
|
||||
},
|
||||
|
||||
expandAllRequestsInCol(colId) {
|
||||
this._searchExpandedAll = this._searchExpandedAll || {};
|
||||
this._searchExpandedAll[colId] = true;
|
||||
const listEl = this.dom.collectionsList || document.getElementById('collections-list');
|
||||
if (listEl) {
|
||||
listEl.innerHTML = this.getCollectionsHTML();
|
||||
}
|
||||
},
|
||||
|
||||
getCollectionsHTML() {
|
||||
const query = (this.state.searchQuery || '').toLowerCase().trim();
|
||||
let colsToRender = [];
|
||||
let isShowingAll = false;
|
||||
const rawQuery = (this.state.searchQuery || '').trim();
|
||||
const tokens = rawQuery.toLowerCase().split(/[^a-zA-Z0-9]+/).filter(Boolean);
|
||||
|
||||
if (this.state.showAllCollections) {
|
||||
colsToRender = this.getAllCollections();
|
||||
isShowingAll = true;
|
||||
} else if (this.state.activeSpaceId) {
|
||||
const currentCols = this.collections || [];
|
||||
const meaningful = currentCols.filter(c => (c.requests && c.requests.length > 0) || (c.id !== 'default' && c.name !== 'My Requests'));
|
||||
if (meaningful.length > 0) {
|
||||
colsToRender = currentCols.map(c => ({ ...c, _spaceId: this.state.activeSpaceId }));
|
||||
// --- 1. NORMAL VIEW (NO SEARCH QUERY) ---
|
||||
if (tokens.length === 0) {
|
||||
let colsToRender = [];
|
||||
let isShowingAll = false;
|
||||
|
||||
if (this.state.showAllCollections) {
|
||||
colsToRender = this.getAllCollections();
|
||||
isShowingAll = true;
|
||||
} else if (this.state.activeSpaceId) {
|
||||
const currentCols = this.collections || [];
|
||||
const meaningful = currentCols.filter(c => (c.requests && c.requests.length > 0) || (c.id !== 'default' && c.name !== 'My Requests'));
|
||||
if (meaningful.length > 0) {
|
||||
colsToRender = currentCols.map(c => ({ ...c, _spaceId: this.state.activeSpaceId }));
|
||||
} else {
|
||||
colsToRender = this.getAllCollections();
|
||||
isShowingAll = true;
|
||||
}
|
||||
} else {
|
||||
// Nothing in current workspace sidebar -> Show all collections!
|
||||
colsToRender = this.getAllCollections();
|
||||
isShowingAll = true;
|
||||
}
|
||||
} else {
|
||||
// No active workspace (dashboard) -> Show all collections!
|
||||
colsToRender = this.getAllCollections();
|
||||
isShowingAll = true;
|
||||
|
||||
let collectionsHTML = '';
|
||||
for (let i = 0; i < colsToRender.length; i++) {
|
||||
const col = colsToRender[i];
|
||||
const isColActive = this.state.activeCollectionId === col.id;
|
||||
const isExplicitlyCollapsed = Boolean(this.state.collapsedCollections && this.state.collapsedCollections[col.id] === true);
|
||||
const isExpanded = !isExplicitlyCollapsed;
|
||||
const reqCount = (col.requests || []).length;
|
||||
|
||||
const reqsHTML = (col.requests || []).map(r => `
|
||||
<div class="history-item ${this.state.activeRequestId === r.id ? 'active-request' : ''}" onclick="App.loadRequest('${col.id}', '${r.id}', '${col._spaceId || ''}')">
|
||||
<span class="method-badge m-${r.method}">${r.method}</span>
|
||||
<div class="history-item-content">
|
||||
<div class="history-item-name" title="${this.escapeHTML(r.name || 'Untitled')}">
|
||||
${this.escapeHTML(r.name || 'Untitled')}
|
||||
</div>
|
||||
<div class="history-item-url" title="${this.escapeHTML(r.url || 'No URL')}">
|
||||
${this.escapeHTML(r.url || 'No URL')}
|
||||
</div>
|
||||
</div>
|
||||
<div class="history-item-actions" onclick="event.stopPropagation();">
|
||||
<button class="col-action-btn" onclick="App.renameRequest('${col.id}', '${r.id}', '${col._spaceId || ''}');" title="Rename Request">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</button>
|
||||
<button class="col-action-btn danger" onclick="App.deleteRequest('${col.id}', '${r.id}', '${col._spaceId || ''}');" title="Delete Request">
|
||||
<i class="fa-solid fa-xmark"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
const spaceBadgeHTML = (isShowingAll && col._spaceName) ? `
|
||||
<span class="collection-space-badge" title="Workspace: ${this.escapeHTML(col._spaceName)}">
|
||||
${this.escapeHTML(col._spaceName)}
|
||||
</span>
|
||||
` : '';
|
||||
|
||||
collectionsHTML += `
|
||||
<div class="collection-group ${isExpanded ? 'expanded' : ''} ${isColActive ? 'active-col' : ''}">
|
||||
<div class="collection-header" onclick="App.selectCollection('${col.id}', '${col._spaceId || ''}');">
|
||||
<i class="fa-solid fa-chevron-right col-chevron ${isExpanded ? 'rotated' : ''}"></i>
|
||||
<i class="fa-solid ${isExpanded ? 'fa-folder-open' : 'fa-folder'} col-folder"></i>
|
||||
<span class="col-title" title="${this.escapeHTML(col.name)}">${this.escapeHTML(col.name)}</span>
|
||||
<span class="col-count-pill" title="${reqCount} requests">${reqCount}</span>
|
||||
${spaceBadgeHTML}
|
||||
<div class="col-actions-bar" onclick="event.stopPropagation();">
|
||||
<button class="col-action-btn" onclick="App.addRequestToCollection('${col.id}', '${col._spaceId || ''}')" title="Add Request">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</button>
|
||||
<button class="col-action-btn" onclick="App.openImportFromDocModal('${col.id}', '${col._spaceId || ''}')" title="Import API from Docs">
|
||||
<i class="fa-solid fa-book-bookmark"></i>
|
||||
</button>
|
||||
<button class="col-action-btn" onclick="App.shareCollection('${col.id}', '${col._spaceId || ''}')" title="Share Collection">
|
||||
<i class="fa-solid fa-share-nodes"></i>
|
||||
</button>
|
||||
<button class="col-action-btn" onclick="App.renameCollection('${col.id}', '${col._spaceId || ''}')" title="Rename Collection">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</button>
|
||||
<button class="col-action-btn danger" onclick="App.deleteCollection('${col.id}', '${col._spaceId || ''}')" title="Delete Collection">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
${isExpanded ? `<div class="collection-items">${reqsHTML || `
|
||||
<div class="empty-collection-box">
|
||||
<div class="empty-col-text">Empty Collection</div>
|
||||
<div style="display:flex; gap:6px;">
|
||||
<button class="btn btn-sm btn-primary" style="font-size:10px; padding:4px 8px; flex:1; justify-content:center; gap:4px;" onclick="event.stopPropagation(); App.openImportFromDocModal('${col.id}', '${col._spaceId || ''}')">
|
||||
<i class="fa-solid fa-book-bookmark"></i> Docs
|
||||
</button>
|
||||
<button class="btn btn-sm btn-ghost" style="font-size:10px; padding:4px 8px; flex:1; justify-content:center; gap:4px;" onclick="event.stopPropagation(); App.addRequestToCollection('${col.id}', '${col._spaceId || ''}')">
|
||||
<i class="fa-solid fa-plus"></i> Request
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`}</div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
return collectionsHTML;
|
||||
}
|
||||
|
||||
// If user searched for something, and current space produced 0 matches, search all collections!
|
||||
if (query && !isShowingAll) {
|
||||
const hasMatch = colsToRender.some(col => {
|
||||
if ((col.name || '').toLowerCase().includes(query)) return true;
|
||||
return (col.requests || []).some(r =>
|
||||
(r.name || '').toLowerCase().includes(query) ||
|
||||
(r.url || '').toLowerCase().includes(query) ||
|
||||
(r.description || '').toLowerCase().includes(query)
|
||||
);
|
||||
});
|
||||
if (!hasMatch) {
|
||||
colsToRender = this.getAllCollections();
|
||||
isShowingAll = true;
|
||||
// --- 2. ULTRA-FAST PRE-INDEXED TOKENIZED SEARCH VIEW ---
|
||||
const searchIndex = this.getSearchIndex();
|
||||
const currentSpaceId = this.state.activeSpaceId;
|
||||
const matches = [];
|
||||
let totalMatchingEndpoints = 0;
|
||||
|
||||
for (let i = 0; i < searchIndex.length; i++) {
|
||||
const item = searchIndex[i];
|
||||
const colMatches = tokens.every(tok => item.colHaystack.includes(tok));
|
||||
const matchingReqs = [];
|
||||
|
||||
for (let j = 0; j < item.requests.length; j++) {
|
||||
const req = item.requests[j];
|
||||
if (tokens.every(tok => req.haystack.includes(tok))) {
|
||||
matchingReqs.push(req);
|
||||
}
|
||||
}
|
||||
|
||||
if (!colMatches && matchingReqs.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
totalMatchingEndpoints += matchingReqs.length;
|
||||
matches.push({
|
||||
item,
|
||||
colMatches,
|
||||
matchingReqs,
|
||||
isCurrentSpace: item.spaceId === currentSpaceId
|
||||
});
|
||||
}
|
||||
|
||||
let collectionsHTML = '';
|
||||
colsToRender.forEach(col => {
|
||||
const isColActive = this.state.activeCollectionId === col.id;
|
||||
|
||||
// Filter requests
|
||||
const filteredRequests = (col.requests || []).filter(r => {
|
||||
if (!query) return true;
|
||||
return (
|
||||
(r.name || '').toLowerCase().includes(query) ||
|
||||
(r.url || '').toLowerCase().includes(query) ||
|
||||
(r.description || '').toLowerCase().includes(query)
|
||||
);
|
||||
});
|
||||
// Zero matches -> Render Obsidian Glass Empty State
|
||||
if (matches.length === 0) {
|
||||
return `
|
||||
<div class="search-empty-state">
|
||||
<div class="search-empty-icon-wrap">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
</div>
|
||||
<div class="search-empty-title">No matching collections</div>
|
||||
<div class="search-empty-desc">
|
||||
No collections or endpoints match “<span class="search-empty-query">${this.escapeHTML(rawQuery)}</span>”
|
||||
</div>
|
||||
<button class="btn btn-ghost btn-sm search-empty-clear-btn" onclick="App.clearSearch()">
|
||||
<i class="fa-solid fa-xmark"></i> Clear Search
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// Decide if the collection itself matches
|
||||
const colMatches = (col.name || '').toLowerCase().includes(query);
|
||||
|
||||
// If neither collection matches nor has matching requests, skip rendering it
|
||||
if (query && !colMatches && filteredRequests.length === 0) {
|
||||
return;
|
||||
}
|
||||
// Sort matches: current workspace matches first, then other workspaces
|
||||
matches.sort((a, b) => {
|
||||
if (a.isCurrentSpace && !b.isCurrentSpace) return -1;
|
||||
if (!a.isCurrentSpace && b.isCurrentSpace) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
// If nothing is searched, show every request in the collection (all expanded by default)
|
||||
const isExplicitlyCollapsed = Boolean(this.state.collapsedCollections && this.state.collapsedCollections[col.id] === true);
|
||||
const isExpanded = query ? true : !isExplicitlyCollapsed;
|
||||
// Summary Bar
|
||||
let searchHTML = `
|
||||
<div class="search-results-bar">
|
||||
<span class="search-results-count">
|
||||
<i class="fa-solid fa-filter" style="color:var(--primary); font-size:10px;"></i>
|
||||
${matches.length} collection${matches.length > 1 ? 's' : ''} • ${totalMatchingEndpoints} endpoint${totalMatchingEndpoints !== 1 ? 's' : ''}
|
||||
</span>
|
||||
<button class="search-results-clear" onclick="App.clearSearch()" title="Clear search">Clear</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
this._searchExpandedAll = this._searchExpandedAll || {};
|
||||
|
||||
for (let i = 0; i < matches.length; i++) {
|
||||
const m = matches[i];
|
||||
const item = m.item;
|
||||
const col = item.col;
|
||||
const isColActive = this.state.activeCollectionId === item.colId;
|
||||
const isExpanded = true;
|
||||
const reqCount = (col.requests || []).length;
|
||||
|
||||
const reqsHTML = (query && colMatches ? (col.requests || []) : filteredRequests).map(r => `
|
||||
<div class="history-item ${this.state.activeRequestId === r.id ? 'active-request' : ''}" onclick="App.loadRequest('${col.id}', '${r.id}', '${col._spaceId || ''}')">
|
||||
<span class="method-badge m-${r.method}">${r.method}</span>
|
||||
<div class="history-item-content">
|
||||
<div class="history-item-name" title="${this.escapeHTML(r.name || 'Untitled')}">
|
||||
${this.escapeHTML(r.name || 'Untitled')}
|
||||
</div>
|
||||
<div class="history-item-url" title="${this.escapeHTML(r.url || 'No URL')}">
|
||||
${this.escapeHTML(r.url || 'No URL')}
|
||||
</div>
|
||||
</div>
|
||||
<div class="history-item-actions" onclick="event.stopPropagation();">
|
||||
<button class="col-action-btn" onclick="App.renameRequest('${col.id}', '${r.id}', '${col._spaceId || ''}');" title="Rename Request">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</button>
|
||||
<button class="col-action-btn danger" onclick="App.deleteRequest('${col.id}', '${r.id}', '${col._spaceId || ''}');" title="Delete Request">
|
||||
<i class="fa-solid fa-xmark"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
const spaceBadgeHTML = (isShowingAll && col._spaceName) ? `
|
||||
<span class="collection-space-badge" title="Workspace: ${this.escapeHTML(col._spaceName)}">
|
||||
${this.escapeHTML(col._spaceName)}
|
||||
const highlightedColName = this.highlightSearchMatch(item.colName, tokens);
|
||||
const showSpaceBadge = !m.isCurrentSpace || this.state.showAllCollections || !currentSpaceId;
|
||||
const spaceBadgeHTML = (showSpaceBadge && item.spaceName) ? `
|
||||
<span class="collection-space-badge" title="Workspace: ${this.escapeHTML(item.spaceName)}">
|
||||
${this.escapeHTML(item.spaceName)}
|
||||
</span>
|
||||
` : '';
|
||||
|
||||
collectionsHTML += `
|
||||
let reqsToRender = [];
|
||||
let hasMoreRequests = false;
|
||||
let hiddenCount = 0;
|
||||
|
||||
const isForceExpanded = Boolean(this._searchExpandedAll[item.colId]);
|
||||
|
||||
if (m.matchingReqs.length > 0 && !isForceExpanded) {
|
||||
reqsToRender = m.matchingReqs;
|
||||
if (m.colMatches && reqCount > reqsToRender.length) {
|
||||
hasMoreRequests = true;
|
||||
hiddenCount = reqCount - reqsToRender.length;
|
||||
}
|
||||
} else {
|
||||
const allReqs = item.requests;
|
||||
if (allReqs.length > 15 && !isForceExpanded) {
|
||||
reqsToRender = allReqs.slice(0, 15);
|
||||
hasMoreRequests = true;
|
||||
hiddenCount = allReqs.length - 15;
|
||||
} else {
|
||||
reqsToRender = allReqs;
|
||||
}
|
||||
}
|
||||
|
||||
const reqsHTML = reqsToRender.map(r => {
|
||||
const highlightedName = this.highlightSearchMatch(r.name, tokens);
|
||||
const highlightedUrl = this.highlightSearchMatch(r.url, tokens);
|
||||
return `
|
||||
<div class="history-item ${this.state.activeRequestId === r.id ? 'active-request' : ''}" onclick="App.loadRequest('${item.colId}', '${r.id}', '${item.spaceId}')">
|
||||
<span class="method-badge m-${r.method}">${r.method}</span>
|
||||
<div class="history-item-content">
|
||||
<div class="history-item-name" title="${this.escapeHTML(r.name || 'Untitled')}">
|
||||
${highlightedName}
|
||||
</div>
|
||||
<div class="history-item-url" title="${this.escapeHTML(r.url || 'No URL')}">
|
||||
${highlightedUrl}
|
||||
</div>
|
||||
</div>
|
||||
<div class="history-item-actions" onclick="event.stopPropagation();">
|
||||
<button class="col-action-btn" onclick="App.renameRequest('${item.colId}', '${r.id}', '${item.spaceId}');" title="Rename Request">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</button>
|
||||
<button class="col-action-btn danger" onclick="App.deleteRequest('${item.colId}', '${r.id}', '${item.spaceId}');" title="Delete Request">
|
||||
<i class="fa-solid fa-xmark"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
const moreReqsHTML = hasMoreRequests ? `
|
||||
<div class="search-more-reqs" onclick="event.stopPropagation(); App.expandAllRequestsInCol('${item.colId}');">
|
||||
<i class="fa-solid fa-chevron-down" style="font-size:9px; margin-right:4px;"></i>
|
||||
+ ${hiddenCount} more endpoint${hiddenCount > 1 ? 's' : ''} in collection
|
||||
</div>
|
||||
` : '';
|
||||
|
||||
searchHTML += `
|
||||
<div class="collection-group ${isExpanded ? 'expanded' : ''} ${isColActive ? 'active-col' : ''}">
|
||||
<div class="collection-header" onclick="App.selectCollection('${col.id}', '${col._spaceId || ''}');">
|
||||
<i class="fa-solid fa-chevron-right col-chevron ${isExpanded ? 'rotated' : ''}"></i>
|
||||
<div class="collection-header" onclick="App.selectCollection('${item.colId}', '${item.spaceId}');">
|
||||
<i class="fa-solid fa-chevron-right col-chevron rotated"></i>
|
||||
<i class="fa-solid ${isExpanded ? 'fa-folder-open' : 'fa-folder'} col-folder"></i>
|
||||
<span class="col-title" title="${this.escapeHTML(col.name)}">${this.escapeHTML(col.name)}</span>
|
||||
<span class="col-title" title="${this.escapeHTML(item.colName)}">${highlightedColName}</span>
|
||||
<span class="col-count-pill" title="${reqCount} requests">${reqCount}</span>
|
||||
${spaceBadgeHTML}
|
||||
<div class="col-actions-bar" onclick="event.stopPropagation();">
|
||||
<button class="col-action-btn" onclick="App.addRequestToCollection('${col.id}', '${col._spaceId || ''}')" title="Add Request">
|
||||
<button class="col-action-btn" onclick="App.addRequestToCollection('${item.colId}', '${item.spaceId}')" title="Add Request">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</button>
|
||||
<button class="col-action-btn" onclick="App.openImportFromDocModal('${col.id}', '${col._spaceId || ''}')" title="Import API from Docs">
|
||||
<button class="col-action-btn" onclick="App.openImportFromDocModal('${item.colId}', '${item.spaceId}')" title="Import API from Docs">
|
||||
<i class="fa-solid fa-book-bookmark"></i>
|
||||
</button>
|
||||
<button class="col-action-btn" onclick="App.shareCollection('${col.id}', '${col._spaceId || ''}')" title="Share Collection">
|
||||
<button class="col-action-btn" onclick="App.shareCollection('${item.colId}', '${item.spaceId}')" title="Share Collection">
|
||||
<i class="fa-solid fa-share-nodes"></i>
|
||||
</button>
|
||||
<button class="col-action-btn" onclick="App.renameCollection('${col.id}', '${col._spaceId || ''}')" title="Rename Collection">
|
||||
<button class="col-action-btn" onclick="App.renameCollection('${item.colId}', '${item.spaceId}')" title="Rename Collection">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</button>
|
||||
<button class="col-action-btn danger" onclick="App.deleteCollection('${col.id}', '${col._spaceId || ''}')" title="Delete Collection">
|
||||
<button class="col-action-btn danger" onclick="App.deleteCollection('${item.colId}', '${item.spaceId}')" title="Delete Collection">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
${isExpanded ? `<div class="collection-items">${reqsHTML || `
|
||||
<div class="empty-collection-box">
|
||||
<div class="empty-col-text">Empty Collection</div>
|
||||
<div style="display:flex; gap:6px;">
|
||||
<button class="btn btn-sm btn-primary" style="font-size:10px; padding:4px 8px; flex:1; justify-content:center; gap:4px;" onclick="event.stopPropagation(); App.openImportFromDocModal('${col.id}', '${col._spaceId || ''}')">
|
||||
<i class="fa-solid fa-book-bookmark"></i> Docs
|
||||
</button>
|
||||
<button class="btn btn-sm btn-ghost" style="font-size:10px; padding:4px 8px; flex:1; justify-content:center; gap:4px;" onclick="event.stopPropagation(); App.addRequestToCollection('${col.id}', '${col._spaceId || ''}')">
|
||||
<i class="fa-solid fa-plus"></i> Request
|
||||
</button>
|
||||
<div class="collection-items">
|
||||
${reqsHTML || `
|
||||
<div class="empty-collection-box">
|
||||
<div class="empty-col-text">Empty Collection</div>
|
||||
</div>
|
||||
</div>
|
||||
`}</div>` : ''}
|
||||
`}
|
||||
${moreReqsHTML}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
}
|
||||
|
||||
return collectionsHTML;
|
||||
return searchHTML;
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
filterSidebarCollections(query) {
|
||||
this.state.searchQuery = query;
|
||||
this.state.searchQuery = query || '';
|
||||
const listEl = this.dom.collectionsList || document.getElementById('collections-list');
|
||||
if (listEl) {
|
||||
listEl.innerHTML = this.getCollectionsHTML();
|
||||
@@ -3527,8 +3836,9 @@ const App = {
|
||||
// Also update clear button and shortcut hint badge visibility
|
||||
const clearBtn = document.getElementById('search-clear-btn');
|
||||
const kbdBadge = document.getElementById('search-kbd-badge');
|
||||
if (clearBtn) clearBtn.style.display = query ? 'block' : 'none';
|
||||
if (kbdBadge) kbdBadge.style.display = query ? 'none' : 'block';
|
||||
const hasVal = Boolean(query && query.trim().length > 0);
|
||||
if (clearBtn) clearBtn.style.display = hasVal ? 'block' : 'none';
|
||||
if (kbdBadge) kbdBadge.style.display = hasVal ? 'none' : 'block';
|
||||
},
|
||||
|
||||
renderSidebar() {
|
||||
|
||||
Reference in New Issue
Block a user