Skip to content

Commit

Permalink
feat: adds a toggle for all levels (#3321)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 authored Oct 11, 2024
1 parent 853a5d4 commit 5e33094
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
18 changes: 17 additions & 1 deletion assets/components/ContainerViewer/ContainerActionsToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@
</details>
</li>
<li>
<details>
<details class="group/details">
<summary>
<mdi:gauge />
Levels
<Toggle
class="toggle-xs invisible group-open/details:visible"
v-model="toggleAllLevels"
title="Toggle all levels"
/>
</summary>
<ul class="menu">
<li v-for="level in allLevels">
Expand Down Expand Up @@ -169,6 +174,17 @@ const downloadUrl = computed(() =>
);
const disableRestart = computed(() => actionStates.stop || actionStates.start || actionStates.restart);
const toggleAllLevels = computed({
get: () => levels.value.size === allLevels.length,
set: (value) => {
if (value) {
allLevels.forEach((level) => levels.value.add(level));
} else {
levels.value.clear();
}
},
});
</script>

<style scoped lang="postcss">
Expand Down
2 changes: 1 addition & 1 deletion assets/components/common/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<slot />
</template>
<template #input>
<input type="checkbox" class="toggle toggle-primary" v-model="modelValue" />
<input type="checkbox" class="toggle toggle-primary" v-model="modelValue" v-bind="$attrs" />
</template>
</LabeledInput>
</template>
Expand Down
16 changes: 4 additions & 12 deletions internal/web/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ func (h *handler) fetchLogsBetweenDates(w http.ResponseWriter, r *http.Request)
}

levels := make(map[string]struct{})
if r.URL.Query().Has("levels") {
for _, level := range r.URL.Query()["levels"] {
levels[level] = struct{}{}
}
} else {
levels = docker.SupportedLogLevels
for _, level := range r.URL.Query()["levels"] {
levels[level] = struct{}{}
}

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

levels := make(map[string]struct{})
if r.URL.Query().Has("levels") {
for _, level := range r.URL.Query()["levels"] {
levels[level] = struct{}{}
}
} else {
levels = docker.SupportedLogLevels
for _, level := range r.URL.Query()["levels"] {
levels[level] = struct{}{}
}

if r.URL.Query().Has("filter") {
Expand Down
4 changes: 4 additions & 0 deletions internal/web/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Test_handler_streamLogs_happy(t *testing.T) {
q := req.URL.Query()
q.Add("stdout", "true")
q.Add("stderr", "true")
q.Add("levels", "info")

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

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

req.URL.RawQuery = q.Encode()

Expand Down Expand Up @@ -258,6 +261,7 @@ func Test_handler_between_dates_with_fill(t *testing.T) {
q.Add("stdout", "true")
q.Add("stderr", "true")
q.Add("fill", "true")
q.Add("levels", "info")

req.URL.RawQuery = q.Encode()

Expand Down

0 comments on commit 5e33094

Please sign in to comment.