Skip to content

Commit 5e33094

Browse files
authoredOct 11, 2024··
feat: adds a toggle for all levels (#3321)
1 parent 853a5d4 commit 5e33094

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed
 

‎assets/components/ContainerViewer/ContainerActionsToolbar.vue

+17-1
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@
7777
</details>
7878
</li>
7979
<li>
80-
<details>
80+
<details class="group/details">
8181
<summary>
8282
<mdi:gauge />
8383
Levels
84+
<Toggle
85+
class="toggle-xs invisible group-open/details:visible"
86+
v-model="toggleAllLevels"
87+
title="Toggle all levels"
88+
/>
8489
</summary>
8590
<ul class="menu">
8691
<li v-for="level in allLevels">
@@ -169,6 +174,17 @@ const downloadUrl = computed(() =>
169174
);
170175
171176
const disableRestart = computed(() => actionStates.stop || actionStates.start || actionStates.restart);
177+
178+
const toggleAllLevels = computed({
179+
get: () => levels.value.size === allLevels.length,
180+
set: (value) => {
181+
if (value) {
182+
allLevels.forEach((level) => levels.value.add(level));
183+
} else {
184+
levels.value.clear();
185+
}
186+
},
187+
});
172188
</script>
173189

174190
<style scoped lang="postcss">

‎assets/components/common/Toggle.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<slot />
55
</template>
66
<template #input>
7-
<input type="checkbox" class="toggle toggle-primary" v-model="modelValue" />
7+
<input type="checkbox" class="toggle toggle-primary" v-model="modelValue" v-bind="$attrs" />
88
</template>
99
</LabeledInput>
1010
</template>

‎internal/web/logs.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,8 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
142142
}
143143

144144
levels := make(map[string]struct{})
145-
if r.URL.Query().Has("levels") {
146-
for _, level := range r.URL.Query()["levels"] {
147-
levels[level] = struct{}{}
148-
}
149-
} else {
150-
levels = docker.SupportedLogLevels
145+
for _, level := range r.URL.Query()["levels"] {
146+
levels[level] = struct{}{}
151147
}
152148

153149
encoder := json.NewEncoder(w)
@@ -287,12 +283,8 @@ func streamLogsForContainers(w http.ResponseWriter, r *http.Request, multiHostCl
287283
backfill := make(chan []*docker.LogEvent)
288284

289285
levels := make(map[string]struct{})
290-
if r.URL.Query().Has("levels") {
291-
for _, level := range r.URL.Query()["levels"] {
292-
levels[level] = struct{}{}
293-
}
294-
} else {
295-
levels = docker.SupportedLogLevels
286+
for _, level := range r.URL.Query()["levels"] {
287+
levels[level] = struct{}{}
296288
}
297289

298290
if r.URL.Query().Has("filter") {

‎internal/web/logs_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func Test_handler_streamLogs_happy(t *testing.T) {
2828
q := req.URL.Query()
2929
q.Add("stdout", "true")
3030
q.Add("stderr", "true")
31+
q.Add("levels", "info")
3132

3233
req.URL.RawQuery = q.Encode()
3334
require.NoError(t, err, "NewRequest should not return an error.")
@@ -70,6 +71,7 @@ func Test_handler_streamLogs_happy_with_id(t *testing.T) {
7071
q := req.URL.Query()
7172
q.Add("stdout", "true")
7273
q.Add("stderr", "true")
74+
q.Add("levels", "info")
7375

7476
req.URL.RawQuery = q.Encode()
7577
require.NoError(t, err, "NewRequest should not return an error.")
@@ -218,6 +220,7 @@ func Test_handler_between_dates(t *testing.T) {
218220
q.Add("to", to.Format(time.RFC3339))
219221
q.Add("stdout", "true")
220222
q.Add("stderr", "true")
223+
q.Add("levels", "info")
221224

222225
req.URL.RawQuery = q.Encode()
223226

@@ -258,6 +261,7 @@ func Test_handler_between_dates_with_fill(t *testing.T) {
258261
q.Add("stdout", "true")
259262
q.Add("stderr", "true")
260263
q.Add("fill", "true")
264+
q.Add("levels", "info")
261265

262266
req.URL.RawQuery = q.Encode()
263267

0 commit comments

Comments
 (0)
Please sign in to comment.