Skip to content

The only tool you need to know what is happening and how to fix it.

sorting progress

dduxc758a9887faa
diff --git a/backend/app/controllers/transaction.controller.go b/backend/app/controllers/transaction.controller.go
index 35b57d7f..951ca811 100644
--- a/backend/app/controllers/transaction.controller.go
+++ b/backend/app/controllers/transaction.controller.go
@@ -13,19 +13,21 @@ import (
type transactionController struct{}
type TransactionSearchRequest struct {
- ProjectId string `json:"projectId"`
- FromDate time.Time `json:"fromDate"`
- ToDate time.Time `json:"toDate"`
- OrderBy string `json:"orderBy"`
- Pagination PaginationParams `json:"pagination"`
+ ProjectId string `json:"projectId"`
+ FromDate time.Time `json:"fromDate"`
+ ToDate time.Time `json:"toDate"`
+ OrderBy string `json:"orderBy"`
+ SortDirection string `json:"sortDirection"`
+ Pagination PaginationParams `json:"pagination"`
}
type EndpointTransactionsRequest struct {
- ProjectId string `json:"projectId"`
- FromDate time.Time `json:"fromDate"`
- ToDate time.Time `json:"toDate"`
- OrderBy string `json:"orderBy"`
- Pagination PaginationParams `json:"pagination"`
+ ProjectId string `json:"projectId"`
+ FromDate time.Time `json:"fromDate"`
+ ToDate time.Time `json:"toDate"`
+ OrderBy string `json:"orderBy"`
+ SortDirection string `json:"sortDirection"`
+ Pagination PaginationParams `json:"pagination"`
}
func (e transactionController) FindAllTransactions(c *gin.Context) {
@@ -58,7 +60,7 @@ func (e transactionController) FindGroupedByEndpoint(c *gin.Context) {
return
}
- stats, total, err := repositories.TransactionRepository.FindGroupedByEndpoint(c, request.ProjectId, request.FromDate, request.ToDate, request.Pagination.Page, request.Pagination.PageSize, request.OrderBy)
+ stats, total, err := repositories.TransactionRepository.FindGroupedByEndpoint(c, request.ProjectId, request.FromDate, request.ToDate, request.Pagination.Page, request.Pagination.PageSize, request.OrderBy, request.SortDirection)
if err != nil {
panic(err)
}
@@ -93,7 +95,7 @@ func (e transactionController) FindByEndpoint(c *gin.Context) {
return
}
- transactions, total, err := repositories.TransactionRepository.FindByEndpoint(c, request.ProjectId, endpoint, request.FromDate, request.ToDate, request.Pagination.Page, request.Pagination.PageSize, request.OrderBy)
+ transactions, total, err := repositories.TransactionRepository.FindByEndpoint(c, request.ProjectId, endpoint, request.FromDate, request.ToDate, request.Pagination.Page, request.Pagination.PageSize, request.OrderBy, request.SortDirection)
if err != nil {
panic(err)
}
diff --git a/backend/app/repositories/transaction.repository.go b/backend/app/repositories/transaction.repository.go
index 3aec7c20..0ec43515 100644
--- a/backend/app/repositories/transaction.repository.go
+++ b/backend/app/repositories/transaction.repository.go
@@ -81,7 +81,7 @@ func (e *transactionRepository) FindAll(ctx context.Context, projectId string, f
return transactions, int64(count), nil
}
-func (e *transactionRepository) FindGroupedByEndpoint(ctx context.Context, projectId string, fromDate, toDate time.Time, page, pageSize int, orderBy string) ([]models.EndpointStats, int64, error) {
+func (e *transactionRepository) FindGroupedByEndpoint(ctx context.Context, projectId string, fromDate, toDate time.Time, page, pageSize int, orderBy string, sortDirection string) ([]models.EndpointStats, int64, error) {
// Count unique endpoints
var count uint64
err := (*chdb.Conn).QueryRow(ctx, "SELECT uniq(endpoint) FROM transactions WHERE project_id = ? AND recorded_at >= ? AND recorded_at <= ?", projectId, fromDate, toDate).Scan(&count)
@@ -103,7 +103,13 @@ func (e *transactionRepository) FindGroupedByEndpoint(ctx context.Context, proje
orderExpr, ok := orderByMap[orderBy]
if !ok {
- orderExpr = "impact" // Default to impact
+ orderExpr = orderByMap["impact"] // Default to impact expression
+ }
+
+ // Validate sort direction
+ sortDir := "DESC"
+ if sortDirection == "asc" {
+ sortDir = "ASC"
}
query := `SELECT
@@ -116,7 +122,7 @@ func (e *transactionRepository) FindGroupedByEndpoint(ctx context.Context, proje
FROM transactions
WHERE project_id = ? AND recorded_at >= ? AND recorded_at <= ?
GROUP BY endpoint
- ORDER BY ` + orderExpr + ` DESC
+ ORDER BY ` + orderExpr + ` ` + sortDir + `
LIMIT ? OFFSET ?`
rows, err := (*chdb.Conn).Query(ctx, query, projectId, fromDate, toDate, pageSize, offset)
@@ -141,7 +147,7 @@ func (e *transactionRepository) FindGroupedByEndpoint(ctx context.Context, proje
return stats, int64(count), nil
}
-func (e *transactionRepository) FindByEndpoint(ctx context.Context, projectId string, endpoint string, fromDate, toDate time.Time, page, pageSize int, orderBy string) ([]models.Transaction, int64, error) {
+func (e *transactionRepository) FindByEndpoint(ctx context.Context, projectId string, endpoint string, fromDate, toDate time.Time, page, pageSize int, orderBy string, sortDirection string) ([]models.Transaction, int64, error) {
var count uint64
err := (*chdb.Conn).QueryRow(ctx, "SELECT count() FROM transactions WHERE project_id = ? AND endpoint = ? AND recorded_at >= ? AND recorded_at <= ?", projectId, endpoint, fromDate, toDate).Scan(&count)
if err != nil {
@@ -161,7 +167,13 @@ func (e *transactionRepository) FindByEndpoint(ctx context.Context, projectId st
orderBy = "recorded_at"
}
- query := "SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, scope FROM transactions WHERE project_id = ? AND endpoint = ? AND recorded_at >= ? AND recorded_at <= ? ORDER BY " + orderBy + " DESC LIMIT ? OFFSET ?"
+ // Validate sort direction
+ sortDir := "DESC"
+ if sortDirection == "asc" {
+ sortDir = "ASC"
+ }
+
+ query := "SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, scope FROM transactions WHERE project_id = ? AND endpoint = ? AND recorded_at >= ? AND recorded_at <= ? ORDER BY " + orderBy + " " + sortDir + " LIMIT ? OFFSET ?"
rows, err := (*chdb.Conn).Query(ctx, query, projectId, endpoint, fromDate, toDate, pageSize, offset)
if err != nil {
return nil, 0, err
diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte
index 5466b8ed..00f46703 100644
--- a/frontend/src/routes/+page.svelte
+++ b/frontend/src/routes/+page.svelte
@@ -150,6 +150,7 @@
</div>
<div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if loading || (data?.worstEndpoints && data.worstEndpoints.length > 0)}
<Table.Header>
<Table.Row class="hover:bg-transparent">
<Table.Head class="h-10 text-sm">
@@ -219,6 +220,7 @@
</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if loading}
{#each Array(4) as _}
@@ -292,6 +294,7 @@
</div>
<div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if loading || (data?.recentIssues && data.recentIssues.length > 0)}
<Table.Header>
<Table.Row class="hover:bg-transparent">
<Table.Head class="h-10 text-sm">
@@ -335,6 +338,7 @@
</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if loading}
{#each Array(4) as _}
diff --git a/frontend/src/routes/issues/+page.svelte b/frontend/src/routes/issues/+page.svelte
index d1b8ec64..a92830f8 100644
--- a/frontend/src/routes/issues/+page.svelte
+++ b/frontend/src/routes/issues/+page.svelte
@@ -237,6 +237,7 @@
<div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if loading || exceptions.length > 0}
<Table.Header>
<Table.Row>
<Table.Head class="w-[40px] pl-4">
@@ -252,6 +253,7 @@
<Table.Head class="w-[180px]">Last Seen</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if loading}
{#each Array(5) as _}
diff --git a/frontend/src/routes/issues/[exceptionHash]/+page.svelte b/frontend/src/routes/issues/[exceptionHash]/+page.svelte
index 01aa64d4..cda622cd 100644
--- a/frontend/src/routes/issues/[exceptionHash]/+page.svelte
+++ b/frontend/src/routes/issues/[exceptionHash]/+page.svelte
@@ -173,14 +173,16 @@
<Card.Description>When this exception happened ({total} total)</Card.Description>
</Card.Header>
<Card.Content>
- <div class="rounded-md border">
+ <div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if occurrences.length > 0}
<Table.Header>
<Table.Row>
<Table.Head>Recorded At</Table.Head>
<Table.Head>Transaction ID</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if occurrences.length === 0}
<Table.Row>
diff --git a/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte b/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte
index db085994..30f80f0f 100644
--- a/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte
+++ b/frontend/src/routes/issues/[exceptionHash]/events/+page.svelte
@@ -159,12 +159,14 @@
<!-- Events Table -->
<div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if loading || occurrences.length > 0}
<Table.Header>
<Table.Row>
<Table.Head>Recorded At</Table.Head>
<Table.Head>Transaction ID</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if loading}
{#each Array(5) as _}
diff --git a/frontend/src/routes/transactions/+page.svelte b/frontend/src/routes/transactions/+page.svelte
index 01be6818..3fd77497 100644
--- a/frontend/src/routes/transactions/+page.svelte
+++ b/frontend/src/routes/transactions/+page.svelte
@@ -6,7 +6,7 @@
import { Button } from "$lib/components/ui/button";
import { Skeleton } from "$lib/components/ui/skeleton";
import * as Select from "$lib/components/ui/select";
- import { ArrowUpDown, ArrowDown } from "@lucide/svelte";
+ import { ArrowUpDown, ArrowDown, ArrowUp } from "@lucide/svelte";
import { TimeRangePicker } from "$lib/components/ui/time-range-picker";
import { CalendarDate, getLocalTimeZone, today } from "@internationalized/date";
import { projectsState } from '$lib/state/projects.svelte';
@@ -21,6 +21,7 @@
};
type SortField = 'count' | 'p50_duration' | 'p95_duration' | 'last_seen' | 'impact';
+ type SortDirection = 'asc' | 'desc';
let endpoints = $state<EndpointStats[]>([]);
let loading = $state(true);
@@ -38,8 +39,9 @@
let fromTime = $state('00:00');
let toTime = $state('23:59');
- // Sorting - default to impact
+ // Sorting - default to impact descending
let orderBy = $state<SortField>('impact');
+ let sortDirection = $state<SortDirection>('desc');
// Page size options
const pageSizeOptions = [
@@ -82,6 +84,16 @@
}
}
+ // Format count with k/m suffixes
+ function formatCount(count: number): string {
+ if (count >= 1_000_000) {
+ return `${(count / 1_000_000).toFixed(1)}m`;
+ } else if (count >= 1_000) {
+ return `${(count / 1_000).toFixed(1)}k`;
+ }
+ return count.toLocaleString();
+ }
+
// Calculate impact score based on call volume and response time variance
function calculateImpact(count: number, p50: number, p95: number): { score: number; level: 'critical' | 'high' | 'medium' | 'low' } {
const varianceMs = (p95 - p50) / 1_000_000;
@@ -111,6 +123,7 @@
fromDate: new Date(getFromDateTime()).toISOString(),
toDate: new Date(getToDateTime()).toISOString(),
orderBy: orderBy,
+ sortDirection: sortDirection,
pagination: {
page: page,
pageSize: pageSize
@@ -144,7 +157,14 @@
}
function handleSort(field: SortField) {
- orderBy = field;
+ if (orderBy === field) {
+ // Toggle direction if clicking the same field
+ sortDirection = sortDirection === 'desc' ? 'asc' : 'desc';
+ } else {
+ // New field, default to descending
+ orderBy = field;
+ sortDirection = 'desc';
+ }
page = 1;
loadData();
}
@@ -178,6 +198,7 @@
<!-- Endpoints Table -->
<div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if loading || endpoints.length > 0}
<Table.Header>
<Table.Row>
<Table.Head>Endpoint</Table.Head>
@@ -190,7 +211,11 @@
>
Calls
{#if orderBy === 'count'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -205,7 +230,11 @@
>
Typical
{#if orderBy === 'p50_duration'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -220,7 +249,11 @@
>
Slow
{#if orderBy === 'p95_duration'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -235,7 +268,11 @@
>
Impact
{#if orderBy === 'impact'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -243,6 +280,7 @@
</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if loading}
{#each Array(5) as _}
@@ -277,7 +315,7 @@
{endpoint.endpoint}
</Table.Cell>
<Table.Cell class="tabular-nums">
- {endpoint.count.toLocaleString()}
+ {formatCount(endpoint.count)}
</Table.Cell>
<Table.Cell class="font-mono text-sm tabular-nums">
{formatDuration(endpoint.p50Duration)}
diff --git a/frontend/src/routes/transactions/[endpoint]/+page.svelte b/frontend/src/routes/transactions/[endpoint]/+page.svelte
index 91df61e5..3ead4156 100644
--- a/frontend/src/routes/transactions/[endpoint]/+page.svelte
+++ b/frontend/src/routes/transactions/[endpoint]/+page.svelte
@@ -6,7 +6,7 @@
import { Button } from "$lib/components/ui/button";
import { Skeleton } from "$lib/components/ui/skeleton";
import { TimeRangePicker } from "$lib/components/ui/time-range-picker";
- import { ArrowLeft, ArrowUpDown, ArrowDown } from "@lucide/svelte";
+ import { ArrowLeft, ArrowUpDown, ArrowDown, ArrowUp } from "@lucide/svelte";
import { CalendarDate, getLocalTimeZone, today } from "@internationalized/date";
import { ErrorDisplay } from "$lib/components/ui/error-display";
import { projectsState } from '$lib/state/projects.svelte';
@@ -24,6 +24,7 @@
};
type SortField = 'recorded_at' | 'duration' | 'status_code' | 'body_size';
+ type SortDirection = 'asc' | 'desc';
let { data } = $props();
@@ -47,6 +48,7 @@
// Sorting State
let orderBy = $state<SortField>('recorded_at');
+ let sortDirection = $state<SortDirection>('desc');
// Combine date and time into ISO datetime string
function getFromDateTime(): string {
@@ -112,6 +114,7 @@
fromDate: new Date(getFromDateTime()).toISOString(),
toDate: new Date(getToDateTime()).toISOString(),
orderBy: orderBy,
+ sortDirection: sortDirection,
pagination: {
page: page,
pageSize: pageSize
@@ -144,7 +147,14 @@
}
function handleSort(field: SortField) {
- orderBy = field;
+ if (orderBy === field) {
+ // Toggle direction if clicking the same field
+ sortDirection = sortDirection === 'desc' ? 'asc' : 'desc';
+ } else {
+ // New field, default to descending
+ orderBy = field;
+ sortDirection = 'desc';
+ }
page = 1;
loadData();
}
@@ -218,8 +228,9 @@
</div>
<!-- Transactions Table -->
- <div class="rounded-md border">
+ <div class="rounded-md border overflow-hidden">
<Table.Root>
+ {#if loading || transactions.length > 0}
<Table.Header>
<Table.Row>
<Table.Head class="w-[180px]">
@@ -231,7 +242,11 @@
>
Recorded At
{#if orderBy === 'recorded_at'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -246,7 +261,11 @@
>
Duration
{#if orderBy === 'duration'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -261,7 +280,11 @@
>
Status
{#if orderBy === 'status_code'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -276,7 +299,11 @@
>
Body Size
{#if orderBy === 'body_size'}
- <ArrowDown class="ml-2 h-4 w-4" />
+ {#if sortDirection === 'desc'}
+ <ArrowDown class="ml-2 h-4 w-4" />
+ {:else}
+ <ArrowUp class="ml-2 h-4 w-4" />
+ {/if}
{:else}
<ArrowUpDown class="ml-2 h-4 w-4" />
{/if}
@@ -286,6 +313,7 @@
<Table.Head>Context</Table.Head>
</Table.Row>
</Table.Header>
+ {/if}
<Table.Body>
{#if loading}
{#each Array(5) as _}