Skip to content

Commit

Permalink
fix: ratelimits ui filters and logs ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
chronark committed Jan 13, 2025
1 parent f71b3ba commit a8c978a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/filter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { ArrayInput } from "@/components/array-input";
import { cn } from "@/lib/utils";
import { Button } from "@unkey/ui";
import { Button, buttonVariants } from "@unkey/ui";
import {
CalendarIcon,
CalendarRange,
Expand Down Expand Up @@ -193,20 +193,22 @@ export const Filters: React.FC = () => {
}
timeInputLabel="Select Time"
calendarProps={{
disabled: { before: new Date() },
disabled: { after: new Date() },
showOutsideDays: true,
}}
timeInputProps={{
className: "w-[100px]",
}}
>
<Button className="text-xs font-medium w-full justify-start gap-0">
<span className="mr-1 text-xs font-medium">From:</span>
<div
className={cn("text-xs font-medium w-full items-center gap-0", buttonVariants())}
>
<span className="mr-1 font-medium">From:</span>

{after ? format(after, "PPp") : format(new Date(), "PPp")}

<CalendarIcon className="mr-2 h-4 w-4 ml-auto" />
</Button>
</div>
</DateTimePicker>
<div className="flex items-center w-full gap-2">
<DateTimePicker
Expand All @@ -225,13 +227,15 @@ export const Filters: React.FC = () => {
className: "w-[130px]",
}}
>
<Button className="text-xs font-medium w-full justify-start gap-0">
<span className="mr-1 text-xs font-medium">Until:</span>
<div
className={cn("text-xs font-medium w-full items-center gap-0", buttonVariants())}
>
<span className="mr-1 font-medium">Until:</span>

{before ? format(before, "PPp") : format(new Date(), "PPp")}

<CalendarIcon className="mr-2 h-4 w-4 ml-auto" />
</Button>
</div>
</DateTimePicker>
</div>

Expand Down
3 changes: 3 additions & 0 deletions internal/clickhouse/src/ratelimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const getRatelimitLogsParameters = z.object({
.optional()
.default(() => Date.now()),
limit: z.number().optional().default(100),
passed: z.boolean().optional(),
});

export function getRatelimitLogs(ch: Querier) {
Expand All @@ -180,6 +181,8 @@ export function getRatelimitLogs(ch: Querier) {
${args.identifier ? "AND multiSearchAny(identifier, {identifier: Array(String)}) > 0" : ""}
AND time >= {start: Int64}
AND time <= {end: Int64}
${typeof args.passed !== "undefined" ? "passed = {passed:Boolean}" : ""}
ORDER BY time DESC
LIMIT {limit: Int64}
;`,
params: getRatelimitLogsParameters,
Expand Down

0 comments on commit a8c978a

Please sign in to comment.