first commit
This commit is contained in:
commit
c7fa91c8ce
34 files changed
+4631
No files matched your search
@@ -0,0 +1,108 @@
|
||||
// Webhook kérések táblázata - valós időben frissülő lista
|
||||
import { formatRelativeTime, formatTimestamp, methodColor, truncatePayload } from '../utils/formatters.js';
|
||||
|
||||
// Maximum ennyi sort tartunk a táblázatban memóriakímélés miatt
|
||||
const MAX_ROWS = 100;
|
||||
|
||||
// Táblázat komponens létrehozása és visszaadása
|
||||
// onRowClick: callback amikor egy sort kattintanak
|
||||
export function createRequestTable(onRowClick) {
|
||||
let selectedId = null;
|
||||
const rows = []; // Sorok nyilvántartása a cleanup-hoz
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.className = 'overflow-x-auto';
|
||||
|
||||
wrapper.innerHTML = `
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="text-left text-gray-500 border-b border-gray-800">
|
||||
<th class="pb-3 pr-4 font-medium whitespace-nowrap">Időpont</th>
|
||||
<th class="pb-3 pr-4 font-medium">Metódus</th>
|
||||
<th class="pb-3 pr-4 font-medium">IP cím</th>
|
||||
<th class="pb-3 pr-4 font-medium hidden md:table-cell">Payload</th>
|
||||
<th class="pb-3 pr-4 font-medium text-center hidden sm:table-cell">GET</th>
|
||||
<th class="pb-3 font-medium text-center hidden sm:table-cell">POST</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="request-tbody" class="divide-y divide-gray-800/50">
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="empty-state" class="py-16 text-center text-gray-600">
|
||||
<div class="text-4xl mb-3">📡</div>
|
||||
<p class="text-lg font-medium text-gray-500">Várakozás a webhook hívásokra…</p>
|
||||
<p class="text-sm mt-1">Küldd el a webhook URL-t, és a kérések itt jelennek meg</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const tbody = wrapper.querySelector('#request-tbody');
|
||||
const emptyState = wrapper.querySelector('#empty-state');
|
||||
|
||||
// Relatív időpontok frissítése (minden 30 másodpercben)
|
||||
const timeInterval = setInterval(() => {
|
||||
wrapper.querySelectorAll('[data-timestamp]').forEach(el => {
|
||||
el.textContent = formatRelativeTime(el.dataset.timestamp);
|
||||
});
|
||||
}, 30_000);
|
||||
|
||||
// Új sor hozzáadása a táblázat elejére
|
||||
function prepend(data) {
|
||||
emptyState.classList.add('hidden');
|
||||
|
||||
const tr = document.createElement('tr');
|
||||
tr.dataset.id = data.id;
|
||||
tr.className = 'cursor-pointer hover:bg-gray-800/40 transition-colors duration-150 group';
|
||||
|
||||
tr.innerHTML = `
|
||||
<td class="py-3 pr-4 whitespace-nowrap">
|
||||
<span
|
||||
class="text-gray-400 group-hover:text-gray-200 transition-colors"
|
||||
data-timestamp="${data.timestamp}"
|
||||
title="${formatTimestamp(data.timestamp)}"
|
||||
>${formatRelativeTime(data.timestamp)}</span>
|
||||
</td>
|
||||
<td class="py-3 pr-4">
|
||||
<span class="inline-block px-2 py-0.5 rounded border text-xs font-bold ${methodColor(data.method)}">
|
||||
${data.method}
|
||||
</span>
|
||||
</td>
|
||||
<td class="py-3 pr-4 text-gray-400 font-mono text-xs whitespace-nowrap">${data.remoteIp}</td>
|
||||
<td class="py-3 pr-4 text-gray-500 hidden md:table-cell max-w-xs truncate">
|
||||
${truncatePayload(data.rawPayload)}
|
||||
</td>
|
||||
<td class="py-3 pr-4 text-center hidden sm:table-cell">
|
||||
${data.queryCount > 0 ? `<span class="text-blue-400 font-medium">${data.queryCount}</span>` : '<span class="text-gray-700">—</span>'}
|
||||
</td>
|
||||
<td class="py-3 text-center hidden sm:table-cell">
|
||||
${data.bodyCount > 0 ? `<span class="text-green-400 font-medium">${data.bodyCount}</span>` : '<span class="text-gray-700">—</span>'}
|
||||
</td>
|
||||
`;
|
||||
|
||||
// Sor kattintás esemény
|
||||
tr.addEventListener('click', () => {
|
||||
// Előző kijelölés törlése
|
||||
tbody.querySelectorAll('tr').forEach(r => r.classList.remove('bg-indigo-900/20', 'border-l-2', 'border-indigo-500'));
|
||||
// Új kijelölés
|
||||
tr.classList.add('bg-indigo-900/20', 'border-l-2', 'border-indigo-500');
|
||||
selectedId = data.id;
|
||||
onRowClick(data);
|
||||
});
|
||||
|
||||
// Sor hozzáadása az elejére + belépési animáció
|
||||
tbody.insertBefore(tr, tbody.firstChild);
|
||||
rows.unshift(tr);
|
||||
|
||||
// Maximum sorok betartása - legrégebbi törlése
|
||||
if (rows.length > MAX_ROWS) {
|
||||
const oldest = rows.pop();
|
||||
oldest.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup - időzítők leállítása
|
||||
function destroy() {
|
||||
clearInterval(timeInterval);
|
||||
}
|
||||
|
||||
return { prepend, destroy, element: wrapper };
|
||||
}
|
||||
Reference in new issue
Block a user