@alepha/devtools 0.11.5 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +1,14 @@
1
- import { t } from "@alepha/core";
1
+ import { type Page, t } from "@alepha/core";
2
2
  import { type LogEntry, logEntrySchema } from "@alepha/logger";
3
- import { useAction, useInject } from "@alepha/react";
3
+ import { useInject } from "@alepha/react";
4
4
  import { useI18n } from "@alepha/react-i18n";
5
5
  import { HttpClient } from "@alepha/server";
6
6
  import { DataTable, Flex, Text } from "@alepha/ui";
7
- import { useState } from "react";
8
7
 
9
8
  const DevLogs = () => {
10
9
  const http = useInject(HttpClient);
11
- const [logs, setLog] = useState<LogEntry[]>([]);
12
10
  const { l } = useI18n();
13
11
 
14
- useAction(
15
- {
16
- runOnInit: true,
17
- runEvery: [10, "seconds"],
18
- handler: async () => {
19
- setLog(
20
- await http
21
- .fetch("/devtools/api/logs", {
22
- schema: {
23
- response: t.array(logEntrySchema),
24
- },
25
- })
26
- .then(({ data }) => data),
27
- );
28
- },
29
- },
30
- [],
31
- );
32
-
33
12
  const renderLevel = (level: string) => {
34
13
  switch (level.toLowerCase()) {
35
14
  case "error":
@@ -68,12 +47,24 @@ const DevLogs = () => {
68
47
  };
69
48
 
70
49
  return (
71
- <Flex>
72
- <DataTable
50
+ <Flex flex={1}>
51
+ <DataTable<LogEntry>
52
+ submitOnInit
53
+ submitEvery={[10, "seconds"]}
54
+ defaultSize={20}
73
55
  tableProps={{
74
56
  horizontalSpacing: "xs",
75
57
  verticalSpacing: 0,
76
58
  }}
59
+ filters={t.object({
60
+ search: t.optional(
61
+ t.string({
62
+ $control: {
63
+ query: logEntrySchema,
64
+ },
65
+ }),
66
+ ),
67
+ })}
77
68
  tableTrProps={(item) => {
78
69
  if (item.level.toLowerCase() === "error") {
79
70
  return {
@@ -87,7 +78,18 @@ const DevLogs = () => {
87
78
  }
88
79
  return {};
89
80
  }}
90
- items={logs}
81
+ items={async (filters) => {
82
+ const response = await http.fetch(
83
+ `/devtools/api/logs?${new URLSearchParams(filters as any).toString()}`,
84
+ {
85
+ schema: {
86
+ response: t.page(logEntrySchema),
87
+ },
88
+ },
89
+ );
90
+
91
+ return response.data as Page<LogEntry>;
92
+ }}
91
93
  columns={{
92
94
  timestamp: {
93
95
  label: "Tme",
@@ -0,0 +1,10 @@
1
+ import { Alepha, run } from "@alepha/core";
2
+ import { AlephaDevtools } from "../index.ts";
3
+ import { AppRouter } from "./AppRouter.tsx";
4
+
5
+ const alepha = Alepha.create();
6
+
7
+ alepha.with(AppRouter);
8
+ alepha.with(AlephaDevtools);
9
+
10
+ run(alepha);