Skip to content

Commit c3f6ff9

Browse files
authored
feat: adds a short delay while waiting for logs to show (#3409)
1 parent 95de5a8 commit c3f6ff9

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

assets/components/LogViewer/EventSource.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe("<ContainerEventSource />", () => {
103103

104104
test("renders loading correctly", async () => {
105105
const wrapper = createLogEventSource();
106-
expect(wrapper.html()).toMatchSnapshot();
106+
expect(wrapper.find("ul.animate-pulse").exists()).toBe(true);
107107
});
108108

109109
test("should connect to EventSource", async () => {

assets/components/LogViewer/EventSource.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<template>
22
<InfiniteLoader :onLoadMore="fetchMore" :enabled="!loadingMore && messages.length > 10" />
3-
<ul role="status" class="flex animate-pulse flex-col gap-4 p-4" v-if="loading || noLogs">
4-
<div class="flex flex-row gap-2" v-for="size in ['w-3/5', 'w-2/3', 'w-9/12', 'w-1/2']">
3+
<ul class="flex animate-pulse flex-col gap-4 p-4" v-if="loading || (noLogs && waitingForMoreLog)">
4+
<div class="flex flex-row gap-2" v-for="size in shuffle(['w-3/5', 'w-2/3', 'w-9/12', 'w-1/2', 'w-1/3', 'w-3/4'])">
55
<div class="h-3 w-40 shrink-0 rounded-full bg-base-content/50 opacity-50"></div>
66
<div class="h-3 rounded-full bg-base-content/50 opacity-50" :class="size"></div>
77
</div>
88
<span class="sr-only">Loading...</span>
99
</ul>
10+
<div v-else-if="noLogs && !waitingForMoreLog" class="p-4">Container has no logs yet</div>
1011
<slot :messages="messages" v-else></slot>
1112
<IndeterminateBar :color />
1213
</template>
@@ -29,6 +30,8 @@ const color = computed(() => {
2930
});
3031
3132
const noLogs = computed(() => messages.value.length === 0);
33+
const waitingForMoreLog = refAutoReset(false, 3000);
34+
watchImmediate(loading, () => (waitingForMoreLog.value = true));
3235
3336
defineExpose({
3437
clear: () => (messages.value = []),
@@ -41,4 +44,8 @@ const fetchMore = async () => {
4144
loadingMore.value = false;
4245
}
4346
};
47+
48+
const shuffle = (items: any[]) => {
49+
return items.sort(() => Math.random() - 0.5);
50+
};
4451
</script>

assets/components/LogViewer/__snapshots__/EventSource.spec.ts.snap

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,6 @@ exports[`<ContainerEventSource /> > render html correctly > should render messag
6060
</ul>"
6161
`;
6262

63-
exports[`<ContainerEventSource /> > renders loading correctly 1`] = `
64-
"<div class="flex min-h-[1px] justify-center"><span class="loading loading-bars loading-md mt-4 text-primary" style="display: none;"></span></div>
65-
<ul role="status" class="flex animate-pulse flex-col gap-4 p-4">
66-
<div class="flex flex-row gap-2">
67-
<div class="h-3 w-40 shrink-0 rounded-full bg-base-content/50 opacity-50"></div>
68-
<div class="h-3 rounded-full bg-base-content/50 opacity-50 w-3/5"></div>
69-
</div>
70-
<div class="flex flex-row gap-2">
71-
<div class="h-3 w-40 shrink-0 rounded-full bg-base-content/50 opacity-50"></div>
72-
<div class="h-3 rounded-full bg-base-content/50 opacity-50 w-2/3"></div>
73-
</div>
74-
<div class="flex flex-row gap-2">
75-
<div class="h-3 w-40 shrink-0 rounded-full bg-base-content/50 opacity-50"></div>
76-
<div class="h-3 rounded-full bg-base-content/50 opacity-50 w-9/12"></div>
77-
</div>
78-
<div class="flex flex-row gap-2">
79-
<div class="h-3 w-40 shrink-0 rounded-full bg-base-content/50 opacity-50"></div>
80-
<div class="h-3 rounded-full bg-base-content/50 opacity-50 w-1/2"></div>
81-
</div><span class="sr-only">Loading...</span>
82-
</ul>
83-
<div data-v-2dbf2928="" class="animate-background h-1 w-1/2 bg-gradient-radial to-transparent to-75% from-secondary"></div>"
84-
`;
85-
8663
exports[`<ContainerEventSource /> > should parse messages 1`] = `
8764
SimpleLogEntry {
8865
"_message": "This is a message.",

0 commit comments

Comments
 (0)