Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

feat: Implement time range restrictions for showcase mode stats, allow backend switching in showcase mode, and enhance rule chain flow visualization with zero-traffic chain merging.

luoleic9da9d7c3b9a
diff --git a/apps/collector/src/modules/backend/backend.controller.ts b/apps/collector/src/modules/backend/backend.controller.ts
index bd647b8..b8b9f5e 100644
--- a/apps/collector/src/modules/backend/backend.controller.ts
+++ b/apps/collector/src/modules/backend/backend.controller.ts
@@ -104,9 +104,7 @@ const backendController: FastifyPluginAsync = async (fastify: FastifyInstance):
// Set active backend
fastify.post<{ Params: BackendParams }>('/:id/activate', async (request, reply) => {
- if (fastify.authService.isShowcaseMode()) {
- return reply.status(403).send({ error: 'Forbidden' });
- }
+ // fastify.authService.isShowcaseMode() check removed to allow switching in demo mode
const { id } = request.params;
const backendId = parseInt(id);
diff --git a/apps/collector/src/modules/stats/stats.controller.ts b/apps/collector/src/modules/stats/stats.controller.ts
index 47812f2..4124c5e 100644
--- a/apps/collector/src/modules/stats/stats.controller.ts
+++ b/apps/collector/src/modules/stats/stats.controller.ts
@@ -27,10 +27,56 @@ function getBackendId(request: FastifyRequest, service: StatsService): number |
}
// Helper function to parse time range
-function getTimeRange(request: FastifyRequest, reply: FastifyReply): TimeRange | null {
+function getTimeRange(request: FastifyRequest, reply: FastifyReply, isShowcaseMode = false): TimeRange | null {
const query = request.query as Record<string, string | undefined>;
- const { start, end } = query;
-
+ let { start, end } = query;
+
+ if (isShowcaseMode) {
+ // In showcase mode, we clamp the start time to be no older than 24 hours ago
+ const now = new Date();
+ const minStart = new Date(now.getTime() - 24 * 60 * 60 * 1000);
+
+ // Default to last 24h if no params
+ if (!start) {
+ return {
+ start: minStart.toISOString(),
+ end: now.toISOString(),
+ active: true,
+ };
+ }
+
+ // Parse provided start/end
+ let startDate = new Date(start);
+ let endDate = end ? new Date(end) : now;
+
+ if (Number.isNaN(startDate.getTime())) {
+ // If invalid start, default to 24h
+ startDate = minStart;
+ endDate = now;
+ }
+
+ if (Number.isNaN(endDate.getTime())) {
+ endDate = now;
+ }
+
+ // Clamp start
+ if (startDate < minStart) {
+ startDate = minStart;
+ }
+
+ // Ensure start <= end
+ if (startDate > endDate) {
+ startDate = minStart;
+ endDate = now;
+ }
+
+ return {
+ start: startDate.toISOString(),
+ end: endDate.toISOString(),
+ active: true,
+ };
+ }
+
if (!start && !end) {
return { active: false };
}
@@ -63,7 +109,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get summary statistics for a specific backend
fastify.get('/summary', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -92,7 +138,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get domain statistics for a specific backend (paginated)
fastify.get('/domains', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -119,7 +165,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get IP statistics for a specific backend (paginated)
fastify.get('/ips', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -146,7 +192,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get per-proxy traffic breakdown for a specific domain
fastify.get('/domains/proxy-stats', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -168,7 +214,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get IP details for a specific domain
fastify.get('/domains/ip-details', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -191,7 +237,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get per-proxy traffic breakdown for a specific IP
fastify.get('/ips/proxy-stats', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -213,7 +259,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get domain details for a specific IP
fastify.get('/ips/domain-details', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -236,7 +282,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get domains for a specific proxy/chain
fastify.get('/proxies/domains', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -259,7 +305,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get IPs for a specific proxy/chain
fastify.get('/proxies/ips', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -282,7 +328,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get proxy/chain statistics for a specific backend
fastify.get('/proxies', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -298,7 +344,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get rule statistics for a specific backend
fastify.get('/rules', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -314,7 +360,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get domains for a specific rule
fastify.get('/rules/domains', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -337,7 +383,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get IPs for a specific rule
fastify.get('/rules/ips', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -360,7 +406,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get per-proxy traffic breakdown for a specific domain under a specific rule
fastify.get('/rules/domains/proxy-stats', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -382,7 +428,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get IP details for a specific domain under a specific rule
fastify.get('/rules/domains/ip-details', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -405,7 +451,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get per-proxy traffic breakdown for a specific IP under a specific rule
fastify.get('/rules/ips/proxy-stats', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -427,7 +473,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get domain details for a specific IP under a specific rule
fastify.get('/rules/ips/domain-details', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -450,7 +496,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get rule chain flow for a specific rule
fastify.get('/rules/chain-flow', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -472,7 +518,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get all rule chain flows merged into unified DAG
fastify.get('/rules/chain-flow-all', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -499,7 +545,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get country traffic statistics for a specific backend
fastify.get('/countries', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -519,7 +565,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get device statistics for a specific backend
fastify.get('/devices', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (backendId === null) {
return reply.status(404).send({ error: 'No backend specified or active' });
@@ -538,7 +584,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get domains for a specific device
fastify.get('/devices/domains', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -557,7 +603,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get IPs for a specific device
fastify.get('/devices/ips', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -576,7 +622,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get hourly statistics for a specific backend
fastify.get('/hourly', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -595,7 +641,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get traffic trend for a specific backend
fastify.get('/trend', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -614,7 +660,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
// Get traffic trend aggregated by time buckets for chart display
fastify.get('/trend/aggregated', async (request, reply) => {
const backendId = getBackendId(request, service);
- const timeRange = getTimeRange(request, reply);
+ const timeRange = getTimeRange(request, reply, fastify.authService.isShowcaseMode());
if (timeRange === null) {
return;
@@ -644,6 +690,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
const limitNum = service.parseLimit(limit, 100, 2000);
return service.getRecentConnections(backendId, limitNum);
});
+
};
export default statsController;
diff --git a/apps/web/app/[locale]/dashboard/components/header/index.tsx b/apps/web/app/[locale]/dashboard/components/header/index.tsx
index 0b7e164..28f41c3 100644
--- a/apps/web/app/[locale]/dashboard/components/header/index.tsx
+++ b/apps/web/app/[locale]/dashboard/components/header/index.tsx
@@ -285,6 +285,7 @@ export function Header({
<TimeRangePicker
value={timeRange}
onChange={onTimeRangeChange}
+ showcaseMode={isShowcase}
/>
<LanguageSwitcher />
@@ -308,6 +309,7 @@ export function Header({
value={timeRange}
onChange={onTimeRangeChange}
className="w-[122px]"
+ showcaseMode={isShowcase}
/>
</div>
diff --git a/apps/web/components/common/time-range-picker.tsx b/apps/web/components/common/time-range-picker.tsx
index 2f024d8..a96894e 100644
--- a/apps/web/components/common/time-range-picker.tsx
+++ b/apps/web/components/common/time-range-picker.tsx
@@ -36,6 +36,7 @@ interface TimeRangePickerProps {
value: TimeRange;
onChange: (range: TimeRange, preset: PresetType) => void;
className?: string;
+ showcaseMode?: boolean;
}
function toLocalTimeInputValue(date: Date): string {
@@ -131,6 +132,7 @@ export function TimeRangePicker({
value,
onChange,
className,
+ showcaseMode,
}: TimeRangePickerProps) {
const locale = useLocale();
const t = useTranslations("timeRangePicker");
@@ -263,6 +265,8 @@ export function TimeRangePicker({
setOpen(false);
};
+ const [lockIcon, setLockIcon] = useState(false);
+
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
@@ -283,151 +287,157 @@ export function TimeRangePicker({
<ChevronDown className="w-4 h-4 text-muted-foreground" />
</Button>
</PopoverTrigger>
-
+
<PopoverContent
- className="w-[calc(100vw-2rem)] sm:w-[352px] max-w-[calc(100vw-1rem)] rounded-xl border border-border/60 bg-popover text-popover-foreground p-4 shadow-xs space-y-4"
- align={isMobile ? "center" : "end"}
- sideOffset={8}
- collisionPadding={12}>
- <div className="space-y-2">
- <Label className="text-xs text-muted-foreground ">
- {t("quickRange")}
- </Label>
- <div className="grid grid-cols-4 gap-2 mt-3">
- {quickPresets.map((preset) => {
- const active = selectedPreset === preset.value;
- return (
- <Button
- key={preset.value}
- size="sm"
- variant="outline"
- className={cn(
- "rounded-full transition-colors",
- active
- ? "bg-emerald-500 text-white border-emerald-500 hover:bg-emerald-500/90 hover:text-white"
- : "bg-secondary/50 border-border/70 text-muted-foreground hover:bg-secondary hover:text-foreground",
- )}
- onClick={() => applyQuickPreset(preset.value)}>
- {preset.label}
- </Button>
- );
- })}
- </div>
- </div>
-
- <div className="space-y-3 border-t border-border pt-3">
- <div className="text-xs text-muted-foreground">
- {t("customRange")}
- </div>
-
- <div className="grid grid-cols-[1fr_auto] gap-2">
- <div className="space-y-2">
- <Label htmlFor="time-range-from-date" className="text-xs">
- {t("startDate")}
- </Label>
- <Popover open={openFromDate} onOpenChange={setOpenFromDate}>
- <PopoverTrigger asChild>
- <Button
- id="time-range-from-date"
- variant="outline"
- className="w-full justify-between font-normal">
- {formatDateButton(fromDate, localeCode, t("pickDate"))}
- <CalendarIcon className="w-4 h-4 text-muted-foreground" />
- </Button>
- </PopoverTrigger>
- <PopoverContent
- className="w-auto overflow-hidden rounded-xl border border-border/60 bg-popover text-popover-foreground p-0 shadow-xs z-[90]"
- align="start"
- sideOffset={6}
- collisionPadding={12}>
- <Calendar
- locale={calendarLocale}
- mode="single"
- selected={fromDate}
- onSelect={(date) => {
- setFromDate(date);
- setOpenFromDate(false);
- }}
- />
- </PopoverContent>
- </Popover>
- </div>
- <div className="space-y-2">
- <Label htmlFor="time-range-from-time" className="text-xs">
- {t("time")}
- </Label>
- <Input
- id="time-range-from-time"
- type="time"
- step={60}
- value={fromTime}
- onChange={(e) => setFromTime(e.target.value)}
- className="bg-background appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none"
- />
- </div>
- </div>
-
- <div className="grid grid-cols-[1fr_auto] gap-2">
- <div className="space-y-2">
- <Label htmlFor="time-range-to-date" className="text-xs">
- {t("endDate")}
- </Label>
- <Popover open={openToDate} onOpenChange={setOpenToDate}>
- <PopoverTrigger asChild>
- <Button
- id="time-range-to-date"
- variant="outline"
- className="w-full justify-between font-normal">
- {formatDateButton(toDate, localeCode, t("pickDate"))}
- <CalendarIcon className="w-4 h-4 text-muted-foreground" />
- </Button>
- </PopoverTrigger>
- <PopoverContent
- className="w-auto overflow-hidden rounded-xl border border-border/60 bg-popover text-popover-foreground p-0 shadow-xs z-[90]"
- align="start"
- sideOffset={6}
- collisionPadding={12}>
- <Calendar
- locale={calendarLocale}
- mode="single"
- selected={toDate}
- disabled={fromDate ? { before: fromDate } : undefined}
- onSelect={(date) => {
- setToDate(date);
- setOpenToDate(false);
- }}
- />
- </PopoverContent>
- </Popover>
- </div>
- <div className="space-y-2">
- <Label htmlFor="time-range-to-time" className="text-xs">
- {t("time")}
- </Label>
- <Input
- id="time-range-to-time"
- type="time"
- step={60}
- value={toTime}
- onChange={(e) => setToTime(e.target.value)}
- className="bg-background appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none"
- />
- </div>
- </div>
-
- <div className="flex gap-2 pt-1">
- <Button
- size="sm"
- className="flex-1 bg-blue-600 hover:bg-blue-600/90 text-white"
- onClick={applyCustom}>
- {t("applyCustom")}
- </Button>
- <Button size="sm" variant="outline" onClick={resetToDefault}>
- <RotateCcw className="w-4 h-4" />
- </Button>
- </div>
- </div>
- </PopoverContent>
+ className="w-[calc(100vw-2rem)] sm:w-[352px] max-w-[calc(100vw-1rem)] rounded-xl border border-border/60 bg-popover text-popover-foreground p-4 shadow-xs space-y-4"
+ align={isMobile ? "center" : "end"}
+ sideOffset={8}
+ collisionPadding={12}>
+ <div className="space-y-2">
+ <Label className="text-xs text-muted-foreground ">
+ {t("quickRange")}
+ </Label>
+ <div className="grid grid-cols-4 gap-2 mt-3">
+ {quickPresets.map((preset) => {
+ const active = selectedPreset === preset.value;
+ // In showcase mode, disable presets larger than 24h (7d, 30d)
+ // We allow "today" as it is within 24h context usually, or at least acceptable
+ const isDisabled = showcaseMode && (preset.value === "7d" || preset.value === "30d");
+
+ return (
+ <Button
+ key={preset.value}
+ size="sm"
+ variant="outline"
+ disabled={isDisabled}
+ className={cn(
+ "rounded-full transition-colors",
+ active
+ ? "bg-emerald-500 text-white border-emerald-500 hover:bg-emerald-500/90 hover:text-white"
+ : "bg-secondary/50 border-border/70 text-muted-foreground hover:bg-secondary hover:text-foreground",
+ isDisabled && "opacity-50 cursor-not-allowed"
+ )}
+ onClick={() => applyQuickPreset(preset.value)}>
+ {preset.label}
+ </Button>
+ );
+ })}
+ </div>
+ </div>
+
+ <div className="space-y-3 border-t border-border pt-3">
+ <div className="text-xs text-muted-foreground">
+ {t("customRange")}
+ </div>
+
+ <div className="grid grid-cols-[1fr_auto] gap-2">
+ <div className="space-y-2">
+ <Label htmlFor="time-range-from-date" className="text-xs">
+ {t("startDate")}
+ </Label>
+ <Popover open={openFromDate} onOpenChange={setOpenFromDate}>
+ <PopoverTrigger asChild>
+ <Button
+ id="time-range-from-date"
+ variant="outline"
+ className="w-full justify-between font-normal">
+ {formatDateButton(fromDate, localeCode, t("pickDate"))}
+ <CalendarIcon className="w-4 h-4 text-muted-foreground" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ className="w-auto overflow-hidden rounded-xl border border-border/60 bg-popover text-popover-foreground p-0 shadow-xs z-[90]"
+ align="start"
+ sideOffset={6}
+ collisionPadding={12}>
+ <Calendar
+ locale={calendarLocale}
+ mode="single"
+ selected={fromDate}
+ onSelect={(date) => {
+ setFromDate(date);
+ setOpenFromDate(false);
+ }}
+ />
+ </PopoverContent>
+ </Popover>
+ </div>
+ <div className="space-y-2">
+ <Label htmlFor="time-range-from-time" className="text-xs">
+ {t("time")}
+ </Label>
+ <Input
+ id="time-range-from-time"
+ type="time"
+ step={60}
+ value={fromTime}
+ onChange={(e) => setFromTime(e.target.value)}
+ className="bg-background appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none"
+ />
+ </div>
+ </div>
+
+ <div className="grid grid-cols-[1fr_auto] gap-2">
+ <div className="space-y-2">
+ <Label htmlFor="time-range-to-date" className="text-xs">
+ {t("endDate")}
+ </Label>
+ <Popover open={openToDate} onOpenChange={setOpenToDate}>
+ <PopoverTrigger asChild>
+ <Button
+ id="time-range-to-date"
+ variant="outline"
+ className="w-full justify-between font-normal">
+ {formatDateButton(toDate, localeCode, t("pickDate"))}
+ <CalendarIcon className="w-4 h-4 text-muted-foreground" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ className="w-auto overflow-hidden rounded-xl border border-border/60 bg-popover text-popover-foreground p-0 shadow-xs z-[90]"
+ align="start"
+ sideOffset={6}
+ collisionPadding={12}>
+ <Calendar
+ locale={calendarLocale}
+ mode="single"
+ selected={toDate}
+ disabled={fromDate ? { before: fromDate } : undefined}
+ onSelect={(date) => {
+ setToDate(date);
+ setOpenToDate(false);
+ }}
+ />
+ </PopoverContent>
+ </Popover>
+ </div>
+ <div className="space-y-2">
+ <Label htmlFor="time-range-to-time" className="text-xs">
+ {t("time")}
+ </Label>
+ <Input
+ id="time-range-to-time"
+ type="time"
+ step={60}
+ value={toTime}
+ onChange={(e) => setToTime(e.target.value)}
+ className="bg-background appearance-none [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none"
+ />
+ </div>
+ </div>
+
+ <div className="flex gap-2 pt-1">
+ <Button
+ size="sm"
+ className="flex-1 bg-blue-600 hover:bg-blue-600/90 text-white"
+ onClick={applyCustom}>
+ {t("applyCustom")}
+ </Button>
+ <Button size="sm" variant="outline" onClick={resetToDefault}>
+ <RotateCcw className="w-4 h-4" />
+ </Button>
+ </div>
+ </div>
+ </PopoverContent>
</Popover>
);
}
diff --git a/apps/web/components/features/proxies/interactive-proxy-stats.tsx b/apps/web/components/features/proxies/interactive-proxy-stats.tsx
index 626319b..a6ce933 100644
--- a/apps/web/components/features/proxies/interactive-proxy-stats.tsx
+++ b/apps/web/components/features/proxies/interactive-proxy-stats.tsx
@@ -338,7 +338,9 @@ export function InteractiveProxyStats({
<button key={item.rawName} onClick={() => handleProxyClick(item.rawName)} className={cn("w-full p-2.5 rounded-xl border text-left transition-all duration-200", isSelected ? "border-primary bg-primary/5 ring-1 ring-primary/20" : "border-border/50 bg-card/50 hover:bg-card hover:border-primary/30")}>
<div className="flex items-center gap-2 mb-1.5">
<span className={cn("w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0", badgeColor)}>{item.rank + 1}</span>
- <span className="flex-1 text-sm font-medium truncate" title={rawDisplayName}>{rawDisplayName}</span>
+ <span className="flex-1 text-sm font-medium truncate" title={rawDisplayName}>
+ {rawDisplayName.length > 24 ? rawDisplayName.slice(0, 24) + "..." : rawDisplayName}
+ </span>
<span className="text-sm font-bold tabular-nums shrink-0 whitespace-nowrap">{formatBytes(item.value)}</span>
</div>
<div className="pl-7 space-y-1">
diff --git a/apps/web/components/features/rules/interactive-rule-stats.tsx b/apps/web/components/features/rules/interactive-rule-stats.tsx
index 1815203..28c9568 100644
--- a/apps/web/components/features/rules/interactive-rule-stats.tsx
+++ b/apps/web/components/features/rules/interactive-rule-stats.tsx
@@ -879,7 +879,7 @@ export function InteractiveRuleStats({
</span>
<span className="flex-1 text-sm font-medium truncate" title={item.name}>
- {item.name}
+ {item.name.length > 24 ? item.name.slice(0, 24) + "..." : item.name}
</span>
<span className="text-sm font-bold tabular-nums shrink-0 whitespace-nowrap">
diff --git a/apps/web/components/features/rules/rule-chain-flow.tsx b/apps/web/components/features/rules/rule-chain-flow.tsx
index 2f638a0..5b7baa6 100644
--- a/apps/web/components/features/rules/rule-chain-flow.tsx
+++ b/apps/web/components/features/rules/rule-chain-flow.tsx
@@ -997,12 +997,9 @@ function UnifiedRuleChainFlowInner({
}
}, [activeBackendId, wsEnabled]);
- // Fetch active chain info when activePolicyOnly is ON
+ // Fetch active chain info for zero-traffic chain merge.
useEffect(() => {
- if (!activePolicyOnly) {
- setActiveChainInfo(null);
- return;
- }
+ setActiveChainInfo(null);
let cancelled = false;
async function fetchActiveChains() {
@@ -1014,8 +1011,8 @@ function UnifiedRuleChainFlowInner({
if (cancelled) return;
- const { activeNodeNames, activeLinkKeys, activeChains } =
- resolveActiveChains(gatewayProviders, gatewayRules);
+ const resolved = resolveActiveChains(gatewayProviders, gatewayRules);
+ setActiveChainInfo(resolved);
} catch {
if (!cancelled) setActivePolicyOnly(false);
}
@@ -1032,7 +1029,7 @@ function UnifiedRuleChainFlowInner({
cancelled = true;
clearInterval(interval);
};
- }, [activePolicyOnly, activeBackendId, autoRefresh]);
+ }, [activeBackendId, autoRefresh]);
// When user selects a different rule, auto-disable showAll
useEffect(() => {
@@ -1042,10 +1039,10 @@ function UnifiedRuleChainFlowInner({
}
}, [selectedRule]);
- // Filter DAG when activePolicyOnly is ON
+ // Filter/Merge DAG
const filteredData = useMemo((): AllChainFlowData | null => {
if (!data) return null;
- if (!activePolicyOnly || !activeChainInfo) return data;
+ if (!activeChainInfo) return data;
const { activeNodeNames, activeLinkKeys, activeChains } = activeChainInfo;
@@ -1053,19 +1050,25 @@ function UnifiedRuleChainFlowInner({
const existingNodeMap = new Map<string, number>();
data.nodes.forEach((n, i) => existingNodeMap.set(n.name, i));
- // Determine which existing nodes are active
+ // Determine which existing nodes to keep
const keepNodeIndices = new Set<number>();
- for (const [, idx] of existingNodeMap) {
- if (activeNodeNames.has(data.nodes[idx].name)) {
- keepNodeIndices.add(idx);
+ if (!activePolicyOnly) {
+ // Keep ALL existing nodes if not filtering
+ data.nodes.forEach((_, i) => keepNodeIndices.add(i));
+ } else {
+ // Keep only active nodes from existing data
+ for (const [, idx] of existingNodeMap) {
+ if (activeNodeNames.has(data.nodes[idx].name)) {
+ keepNodeIndices.add(idx);
+ }
}
}
- // Build new nodes array (existing active + zero-traffic for missing)
+ // Build new nodes array (existing kept + zero-traffic for missing active)
const newNodes: MergedChainNode[] = [];
const nameToNewIdx = new Map<string, number>();
- // First: existing active nodes
+ // First: existing kept nodes
for (const idx of keepNodeIndices) {
const node = data.nodes[idx];
nameToNewIdx.set(node.name, newNodes.length);
@@ -1099,13 +1102,20 @@ function UnifiedRuleChainFlowInner({
[];
const linkKeySet = new Set<string>();
- // Existing active links
+ // Existing links from data (filtered if needed)
for (const link of data.links) {
const srcName = data.nodes[link.source]?.name;
const tgtName = data.nodes[link.target]?.name;
- if (srcName && tgtName && activeLinkKeys.has(`${srcName}|${tgtName}`)) {
+
+ // If filtering, check if link is in active keys. If not filtering, keep it.
+ const shouldKeepLink =
+ !activePolicyOnly ||
+ (srcName && tgtName && activeLinkKeys.has(`${srcName}|${tgtName}`));
+
+ if (shouldKeepLink && srcName && tgtName) {
const newSrc = nameToNewIdx.get(srcName);
const newTgt = nameToNewIdx.get(tgtName);
+ // Ensure both endpoints exist in our new node set
if (newSrc !== undefined && newTgt !== undefined) {
const key = `${newSrc}-${newTgt}`;
if (!linkKeySet.has(key)) {
diff --git a/apps/web/lib/active-chain.ts b/apps/web/lib/active-chain.ts
index 2b91565..964e87f 100644
--- a/apps/web/lib/active-chain.ts
+++ b/apps/web/lib/active-chain.ts
@@ -48,11 +48,6 @@ function followChain(startGroup: string, groupNowMap: Map<string, string>): stri
/**
* Resolve active policy chains from Gateway providers and rules data.
- *
- * Uses the target proxy group name (rule.proxy) as the chain start,
- * NOT the internal rule type+payload (e.g. "RuleSet,netflix").
- * This matches how traffic data stores rule names (by proxy group).
- * Multiple low-level rules can target the same proxy group, so we deduplicate.
*/
export function resolveActiveChains(
providers: GatewayProvidersResponse,
@@ -70,9 +65,7 @@ export function resolveActiveChains(
if (processedGroups.has(targetGroup)) continue;
processedGroups.add(targetGroup);
- // Build chain from the target proxy group: [group, now, now, ..., terminal]
const chain = followChain(targetGroup, groupNowMap);
-
activeChains.set(targetGroup, chain);
for (const name of chain) {
diff --git a/package.json b/package.json
index 3ae5d4d..2c1052a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "neko-master",
- "version": "1.2.2",
+ "version": "1.2.3",
"description": "Modern traffic analytics for edge gateways",
"private": true,
"workspaces": [