Skip to content

Commit 8f0d4e2

Browse files
committed
feat: added Logs component.
1 parent 6014106 commit 8f0d4e2

File tree

8 files changed

+126
-2
lines changed

8 files changed

+126
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { ComponentProps } from "svelte";
2+
import Logs from "./Logs.svelte";
3+
4+
export default {
5+
title: "UI/Logs",
6+
component: Logs,
7+
tags: ["autodocs"],
8+
render: (args: {
9+
Component: Logs;
10+
props: ComponentProps<typeof Logs>;
11+
}) => ({
12+
Component: Logs,
13+
props: args,
14+
}),
15+
};
16+
17+
export const Default = {
18+
args: {
19+
events: [
20+
{
21+
timestamp: new Date(),
22+
action: "upload",
23+
message: "msg_123",
24+
to: "alice.vault.dev",
25+
},
26+
{
27+
timestamp: new Date(),
28+
action: "fetch",
29+
message: "msg_124",
30+
from: "bob.vault.dev",
31+
},
32+
{
33+
timestamp: new Date(),
34+
action: "webhook",
35+
to: "Alice",
36+
from: "Pic",
37+
},
38+
],
39+
},
40+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<script lang="ts">
2+
import type { LogEvent } from '$lib/types';
3+
import { capitalizeFirstLetter, cn, parseTimestamp } from '$lib/utils';
4+
5+
let {
6+
events,
7+
activeEventIndex = $bindable(),
8+
...restProps
9+
}: { events: LogEvent[]; activeEventIndex: number } = $props();
10+
11+
const commonClasses = 'w-full h-full bg-white';
12+
const commonLogClasses =
13+
'flex cursor-pointer gap-2 rounded-md p-2 transition-colors hover:bg-gray-100';
14+
const activeLogClass = 'bg-gray-100';
15+
const actionClasses = {
16+
upload: 'text-green-600',
17+
fetch: 'text-blue-800',
18+
webhook: 'text-red-500'
19+
};
20+
</script>
21+
22+
<section class={cn(commonClasses, restProps.class)}>
23+
<h2 class="pb-4 pl-8 text-xl">Logs</h2>
24+
{#each events as event, i}
25+
<article
26+
{...restProps}
27+
class={cn(commonLogClasses, i === activeEventIndex && activeLogClass)}
28+
onclick={() => {
29+
activeEventIndex = i;
30+
}}
31+
>
32+
<p class="font-light text-black/60">[{parseTimestamp(event.timestamp)}]</p>
33+
<div>
34+
<span class={actionClasses[event.action]}>
35+
{capitalizeFirstLetter(event.action)}
36+
{event.action === 'webhook' ? 'triggered' : ''}
37+
</span>
38+
{#if event.action === 'upload'}
39+
→ {event.to}
40+
{:else if event.action === 'fetch'}
41+
← {event.from}
42+
{:else if event.action === 'webhook'}
43+
({event.from} → {event.to})
44+
{/if}
45+
{#if event.action === 'upload' || event.action === 'fetch'}
46+
<br />
47+
({event.message})
48+
{/if}
49+
</div>
50+
</article>
51+
{/each}
52+
</section>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { default as LiveDataFlow } from "./LiveDataFlow/LiveDataFlow.svelte";
1+
export { default as LiveDataFlow } from "./LiveDataFlow/LiveDataFlow.svelte";
2+
export { default as Logs } from "./Logs/Logs.svelte";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./log.types";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export interface UploadEvent {
2+
timestamp: Date;
3+
action: "upload";
4+
message: string;
5+
to: string;
6+
}
7+
8+
export interface FetchEvent {
9+
timestamp: Date;
10+
action: "fetch";
11+
message: string;
12+
from: string;
13+
}
14+
15+
export interface WebhookEvent {
16+
timestamp: Date;
17+
action: "webhook";
18+
from: string;
19+
to: string;
20+
}
21+
22+
export type LogEvent = UploadEvent | FetchEvent | WebhookEvent;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export * from './mergeClasses';
1+
export * from "./mergeClasses";
2+
export * from "./parseDates";
3+
export * from "./typography";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const parseTimestamp = (timestamp: Date) => {
2+
return `${timestamp.getHours().toString().padStart(2, "0")}:${timestamp.getMinutes().toString().padStart(2, "0")}:${timestamp.getSeconds().toString().padStart(2, "0")}`;
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const capitalizeFirstLetter = (val: string) => {
2+
return String(val).charAt(0).toUpperCase() + String(val).slice(1);
3+
};

0 commit comments

Comments
 (0)