Sanoopsn's picture
remove Filters option and filter from UI
c83d1e4 verified
Raw History Blame Contribute Delete
17 kB
// Sample data - in a real app this would come from an API
const sampleLogs = [
{
id: 1,
status: 500,
method: 'POST',
time: '2025-10-18 14:32:45',
url: 'https://api.example.com/v1/users',
errorMessage: 'Internal Server Error: Database connection timeout',
errorCode: 'DB_CONN_TIMEOUT',
errorType: 'Database',
resolution: 'Check database connection pool. Verify database server is running and accessible. Consider increasing connection timeout setting.'
},
{
id: 2,
status: 404,
method: 'GET',
time: '2023-05-15 14:30:12',
url: 'https://api.example.com/v1/products/12345',
errorMessage: 'Product not found with ID 12345',
errorCode: 'RESOURCE_NOT_FOUND',
errorType: 'Validation',
resolution: 'Verify the product ID exists in the database. Check if the product was deleted. Validate the request parameters.'
},
{
id: 3,
status: 400,
method: 'PUT',
time: '2023-05-15 14:25:33',
url: 'https://api.example.com/v1/orders/678',
errorMessage: 'Invalid request body: Missing required field "quantity"',
errorCode: 'VALIDATION_ERROR',
errorType: 'Validation',
resolution: 'Check the API documentation for required fields. Validate the request body before sending. Ensure all required fields are included.'
},
{
id: 4,
status: 401,
method: 'GET',
time: '2023-05-15 14:20:18',
url: 'https://api.example.com/v1/users/me',
errorMessage: 'Unauthorized: Invalid or expired access token',
errorCode: 'INVALID_TOKEN',
errorType: 'Authentication',
resolution: 'Check if the access token is valid and not expired. Verify the token signature. Refresh the token if needed.'
},
{
id: 5,
status: 503,
method: 'POST',
time: '2023-05-15 14:15:42',
url: 'https://api.example.com/v1/payments',
errorMessage: 'Service Unavailable: Payment gateway not responding',
errorCode: 'GATEWAY_TIMEOUT',
errorType: 'Integration',
resolution: 'Check the payment gateway status. Verify network connectivity. Implement retry logic with exponential backoff.'
}
];
// DOM elements
const logsTable = document.getElementById('logsTable');
const searchInput = document.querySelector('input[type="text"]');
let errorModal;
let closeModal;
let closeModalBtn;
let submitTicket;
// Current selected log
let currentLog = null;
// Function to render logs table with optional filter
function renderLogsTableWithFilter(filteredLogs) {
logsTable.innerHTML = '';
filteredLogs.forEach(log => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
<td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
<td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
<i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
</button>
</td>
`;
logsTable.appendChild(row);
});
// Add event listeners to new view buttons
document.querySelectorAll('.view-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const id = parseInt(e.currentTarget.getAttribute('data-id'));
currentLog = sampleLogs.find(log => log.id === id);
showErrorDetails(currentLog);
});
});
feather.replace();
}
function renderLogsTable(filter = '') {
logsTable.innerHTML = '';
const filteredLogs = filter
? sampleLogs.filter(log =>
log.url.toLowerCase().includes(filter.toLowerCase()) ||
log.errorMessage.toLowerCase().includes(filter.toLowerCase()) ||
log.status.toString().includes(filter) ||
log.method.toLowerCase().includes(filter.toLowerCase())
)
: sampleLogs;
filteredLogs.forEach(log => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.id}</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="status-badge ${getStatusClass(log.status)}">${log.status}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="status-badge ${getMethodClass(log.method)}">${log.method}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${log.time}</td>
<td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">${log.url}</td>
<td class="px-6 py-4 text-sm text-gray-500 truncate max-w-xs">${log.errorMessage}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button class="view-btn p-1 rounded hover:bg-gray-200" data-id="${log.id}">
<i data-feather="eye" class="w-4 h-4 text-primary-500"></i>
</button>
</td>
`;
logsTable.appendChild(row);
});
// Add event listeners to view buttons
document.querySelectorAll('.view-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const id = parseInt(e.currentTarget.getAttribute('data-id'));
currentLog = sampleLogs.find(log => log.id === id);
showErrorDetails(currentLog);
});
});
feather.replace();
}
// Helper function to get status badge class
function getStatusClass(status) {
if (status >= 200 && status < 300) return 'status-2xx';
if (status >= 400 && status < 500) return 'status-4xx';
if (status >= 500) return 'status-5xx';
return '';
}
// Helper function to get method badge class
function getMethodClass(method) {
return `method-${method.toLowerCase()}`;
}
// Sample error details data
const errorDetails = {
1: {
requestHeaders: {
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
'X-Request-ID': 'req_123456'
},
requestBody: {
"username": "testuser",
"email": "test@example.com"
},
stackTrace: "Error: Database connection timeout\n at Query._callback (/app/src/db.js:45:15)\n at Query.Sequence.end (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)"
},
2: {
requestHeaders: {
'Accept': 'application/json',
'X-API-Version': '1.0'
},
requestBody: null,
stackTrace: "Error: Product not found\n at ProductService.find (/app/src/services/product.js:32:11)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)"
},
3: {
requestHeaders: {
'Content-Type': 'application/json',
'X-Client-ID': 'web_app_v2'
},
requestBody: {
"order_id": 678,
"status": "processing"
},
stackTrace: "ValidationError: Missing required field 'quantity'\n at validateOrderUpdate (/app/src/validators/order.js:15:15)"
}
};
// Function to create modal elements
function createModalElements() {
const modal = document.getElementById('errorModal');
if (modal.innerHTML) return modal; // Already created
modal.innerHTML = `
<div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-bold text-gray-800">Error Details</h2>
<button id="closeModal" class="text-gray-500 hover:text-gray-700 p-2">
<i data-feather="x" class="w-5 h-5"></i>
</button>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
<div>
<h3 class="font-medium text-gray-700 mb-2">Request Information</h3>
<div class="space-y-2">
<p><span class="font-medium">Status:</span> <span id="modalStatus" class="px-2 py-1 rounded text-xs"></span></p>
<p><span class="font-medium">Method:</span> <span id="modalMethod" class="px-2 py-1 rounded text-xs"></span></p>
<p><span class="font-medium">Endpoint:</span> <span id="modalEndpoint" class="break-all"></span></p>
<p><span class="font-medium">Timestamp:</span> <span id="modalTime" class="font-mono"></span></p>
<p><span class="font-medium">Request Duration:</span> <span id="modalDuration" class="font-mono">-</span></p>
</div>
</div>
<div>
<h3 class="font-medium text-gray-700 mb-2">Error Information</h3>
<div class="space-y-2">
<p><span class="font-medium">Error Code:</span> <span id="modalErrorCode" class="font-mono"></span></p>
<p><span class="font-medium">Error Type:</span> <span id="modalErrorType" class="px-2 py-1 rounded text-xs"></span></p>
<p><span class="font-medium">Occurrences:</span> <span id="modalOccurrences" class="font-mono">1</span></p>
<p><span class="font-medium">First Occurred:</span> <span id="modalFirstOccurred" class="font-mono">-</span></p>
<p><span class="font-medium">Last Occurred:</span> <span id="modalLastOccurred" class="font-mono">-</span></p>
</div>
</div>
</div>
<div class="mb-6">
<h3 class="font-medium text-gray-700 mb-2">Full Error Message</h3>
<div class="bg-gray-50 p-4 rounded">
<pre id="modalErrorMessage" class="text-sm whitespace-pre-wrap overflow-x-auto font-mono"></pre>
</div>
</div>
<div class="mb-6 hidden" id="requestDetails">
<h3 class="font-medium text-gray-700 mb-2">Request Details</h3>
<div class="bg-gray-50 p-4 rounded">
<pre id="modalRequestDetails" class="text-sm whitespace-pre-wrap overflow-x-auto font-mono"></pre>
</div>
</div>
<div class="mb-6">
<h3 class="font-medium text-gray-700 mb-2">Resolution Steps</h3>
<div id="modalResolution" class="bg-blue-50 p-4 rounded text-sm"></div>
</div>
<div class="flex justify-end space-x-3">
<button id="submitTicket" class="px-4 py-2 bg-secondary-500 text-white rounded-md hover:bg-secondary-600 transition flex items-center">
<i data-feather="plus" class="mr-2 w-4 h-4"></i> Submit Ticket
</button>
<button id="closeModalBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition">
Close
</button>
</div>
</div>
</div>
`;
return modal;
}
// Function to show error details in modal
function showErrorDetails(log) {
if (!errorModal) {
errorModal = createModalElements();
closeModal = document.getElementById('closeModal');
closeModalBtn = document.getElementById('closeModalBtn');
submitTicket = document.getElementById('submitTicket');
// Setup event listeners for modal
closeModal.addEventListener('click', closeErrorModal);
closeModalBtn.addEventListener('click', closeErrorModal);
submitTicket.addEventListener('click', () => {
alert(`Ticket submitted for error: ${currentLog.errorCode}\nAn engineer will review this issue shortly.`);
closeErrorModal();
});
// Close when clicking outside modal
errorModal.addEventListener('click', (e) => {
if (e.target === errorModal) {
closeErrorModal();
}
});
}
// Request Info
document.getElementById('modalStatus').textContent = log.status;
document.getElementById('modalStatus').className = `status-badge ${getStatusClass(log.status)}`;
document.getElementById('modalMethod').textContent = log.method;
document.getElementById('modalMethod').className = `status-badge ${getMethodClass(log.method)}`;
document.getElementById('modalEndpoint').textContent = log.url;
document.getElementById('modalTime').textContent = log.time;
// Error Info
document.getElementById('modalErrorCode').textContent = log.errorCode;
document.getElementById('modalErrorType').textContent = log.errorType;
document.getElementById('modalErrorType').className = 'status-badge status-4xx';
// Mock additional data
document.getElementById('modalDuration').textContent = `${Math.floor(Math.random() * 500) + 100}ms`;
document.getElementById('modalOccurrences').textContent = Math.floor(Math.random() * 10) + 1;
const firstDate = new Date(log.time);
const lastDate = new Date(log.time);
firstDate.setDate(firstDate.getDate() - Math.floor(Math.random() * 3));
document.getElementById('modalFirstOccurred').textContent = firstDate.toLocaleString();
document.getElementById('modalLastOccurred').textContent = lastDate.toLocaleString();
// Error details
document.getElementById('modalErrorMessage').textContent = log.errorMessage;
document.getElementById('modalResolution').textContent = log.resolution;
// Show request details if available
const requestDetailsSection = document.getElementById('requestDetails');
const requestDetailsContent = document.getElementById('modalRequestDetails');
if (errorDetails[log.id]) {
const details = errorDetails[log.id];
// Format the request details more cleanly
let detailsStr = '=== Request Headers ===\n';
detailsStr += JSON.stringify(details.requestHeaders, null, 2) + '\n\n';
if (details.requestBody) {
detailsStr += '=== Request Body ===\n';
detailsStr += JSON.stringify(details.requestBody, null, 2) + '\n\n';
}
if (details.stackTrace) {
detailsStr += '=== Stack Trace ===\n';
detailsStr += details.stackTrace + '\n';
}
requestDetailsContent.textContent = detailsStr;
requestDetailsSection.classList.remove('hidden');
} else {
requestDetailsSection.classList.add('hidden');
}
errorModal.classList.remove('hidden');
document.body.style.overflow = 'hidden';
errorModal.style.display = 'flex';
}
// Function to close modal
function closeErrorModal() {
if (errorModal) {
errorModal.classList.add('hidden');
errorModal.style.display = 'none';
document.body.style.overflow = 'auto';
currentLog = null;
}
}
// Initialize the page
document.addEventListener('DOMContentLoaded', () => {
renderLogsTable();
// Search functionality
searchInput.addEventListener('input', (e) => {
renderLogsTable(e.target.value);
});
// Initialize modal (but don't show it yet)
errorModal = createModalElements();
// Setup event listeners for modal
errorModal.addEventListener('click', (e) => {
if (e.target === errorModal) {
closeErrorModal();
}
});
});
// Global event delegation for modal buttons
document.addEventListener('click', (e) => {
if (e.target.closest('#closeModal, #closeModalBtn')) {
closeErrorModal();
} else if (e.target.closest('#submitTicket')) {
if (currentLog) {
alert(`Ticket submitted for error: ${currentLog.errorCode}\nAn engineer will review this issue shortly.`);
closeErrorModal();
}
}
});