diff --git a/web/bulk-api-tester/app.js b/web/bulk-api-tester/app.js index a82147a..7edcce7 100644 --- a/web/bulk-api-tester/app.js +++ b/web/bulk-api-tester/app.js @@ -2165,15 +2165,29 @@ const App = { return; } - // Build index of APIs + // Build index of APIs with precomputed search haystack const allApis = []; (docsData.sections || []).forEach(s => { (s.eps || []).forEach(e => { + const haystack = [ + e.api_key || '', + e.title || '', + e.summary || '', + e.desc || '', + e.full_url || '', + e.path || '', + s.title || '', + ...(e.params || []).map(p => (p.n || '') + ' ' + (p.ty || '')), + ...(e.chips || []), + ...(e.endpoints || []).map(sub => (sub.title || '') + ' ' + (sub.subpath || '') + ' ' + (sub.path || '')) + ].join(' ').toLowerCase(); + allApis.push({ ...e, secId: s.id, secTitle: s.title, - secHue: s.hue + secHue: s.hue, + _searchHaystack: haystack }); }); }); @@ -2181,7 +2195,7 @@ const App = { this._docModalSections = docsData.sections || []; this._renderDocModalCategories(); - this._renderDocModalList(); + this._buildDocModalCards(); setTimeout(() => { const inp = document.getElementById('doc-api-search-input'); @@ -2216,58 +2230,82 @@ const App = { _selectDocModalCategory(catId) { this._docModalActiveCategory = catId; this._renderDocModalCategories(); - this._renderDocModalList(); + this._applyDocModalFilter(); }, _filterDocModal(query) { this._docModalSearch = (query || '').toLowerCase().trim(); const clearBtn = document.getElementById('doc-api-search-clear'); if (clearBtn) clearBtn.style.display = this._docModalSearch ? 'block' : 'none'; - this._renderDocModalList(); + + if (this._filterDocRaf) cancelAnimationFrame(this._filterDocRaf); + this._filterDocRaf = requestAnimationFrame(() => { + this._applyDocModalFilter(); + }); }, _renderDocModalList() { - const listEl = document.getElementById('doc-modal-list'); + this._applyDocModalFilter(); + }, + + _applyDocModalFilter() { const countEl = document.getElementById('doc-modal-count'); - if (!listEl || !this._docModalApis) return; + const emptyEl = document.getElementById('doc-modal-empty'); + const emptyQueryEl = document.getElementById('doc-modal-empty-query'); + if (!this._docModalApis) return; const q = this._docModalSearch || ''; const cat = this._docModalActiveCategory || 'all'; + const tokens = q ? q.split(/\s+/).filter(Boolean) : []; - const filtered = this._docModalApis.filter(api => { - if (cat !== 'all' && api.secId !== cat) return false; - if (!q) return true; + let visibleCount = 0; + const total = this._docModalApis.length; + const cards = this._docModalCardElements || (document.getElementById('doc-modal-list') ? document.getElementById('doc-modal-list').querySelectorAll('.doc-import-card') : []); - const haystack = [ - api.api_key || '', - api.title || '', - api.summary || '', - api.desc || '', - api.full_url || '', - api.path || '', - ...(api.params || []).map(p => p.n || ''), - ...(api.chips || []), - ...(api.endpoints || []).map(sub => (sub.title || '') + ' ' + (sub.subpath || '') + ' ' + (sub.path || '')) - ].join(' ').toLowerCase(); + for (let i = 0; i < total; i++) { + const api = this._docModalApis[i]; + const cardEl = cards[i]; + if (!cardEl) continue; - return haystack.includes(q); - }); + let matches = true; + if (cat !== 'all' && api.secId !== cat) { + matches = false; + } else if (tokens.length > 0) { + const hay = api._searchHaystack; + for (let j = 0; j < tokens.length; j++) { + if (!hay.includes(tokens[j])) { + matches = false; + break; + } + } + } + + if (matches) { + if (cardEl.style.display === 'none') cardEl.style.display = ''; + visibleCount++; + } else { + if (cardEl.style.display !== 'none') cardEl.style.display = 'none'; + } + } if (countEl) { - countEl.textContent = `Showing ${filtered.length} of ${this._docModalApis.length} APIs`; + countEl.textContent = `Showing ${visibleCount} of ${total} APIs`; } - - if (filtered.length === 0) { - listEl.innerHTML = ` -
- - No APIs found matching "${this.escapeHTML(q)}" -
- `; - return; + if (emptyEl) { + if (visibleCount === 0) { + if (emptyQueryEl) emptyQueryEl.textContent = q; + emptyEl.style.display = 'block'; + } else { + emptyEl.style.display = 'none'; + } } + }, - listEl.innerHTML = filtered.map(api => { + _buildDocModalCards() { + const listEl = document.getElementById('doc-modal-list'); + if (!listEl || !this._docModalApis) return; + + let html = this._docModalApis.map((api, idx) => { const subEps = (api.endpoints && api.endpoints.length) ? api.endpoints : [api]; const hasMultiple = subEps.length > 1; const targetUrl = api.full_url || ('https://apigp0006.creinnovations.in' + (api.path || '')); @@ -2275,7 +2313,7 @@ const App = { const chips = api.chips || []; return ` -
+
${api.method} @@ -2350,6 +2388,17 @@ const App = {
`; }).join(''); + + html += ` + + `; + + listEl.innerHTML = html; + this._docModalCardElements = listEl.querySelectorAll('.doc-import-card'); + this._applyDocModalFilter(); }, async importFromDoc(apiId, subEpIdx = 0, targetColId = null, customColName = null, importAll = false) {