Repository: kestra-io/kestra
Issue: Collapse all is displayed on logs while there is no logs open
Labels: bug
enhancement
frontend

### Expected Behavior

_No response_

### Actual Behaviour

If settings -> failed task logs open only and there is no failed task, nothing is opened and still the button is "Collapse all" while it should be expand all (only if no failed task).

For now we have to click on "Collapse all" which does nothing then the button goes to "Expand all" which then works

### Steps To Reproduce

_No response_

### Environment Information

- Kestra Version:
- Operating System (OS / Docker / Kubernetes):
- Java Version (If not docker):


### Example flow

_No response_

Issue comments:
I think a simple fix would be to show Collapse all if there is any taskRun expanded and Expand all in any other case

Pull request review comments:

Patch that resolved the issue:
diff --git a/ui/src/components/executions/Logs.vue b/ui/src/components/executions/Logs.vue
index 1597cc6222..70fb3bcfc6 100644
--- a/ui/src/components/executions/Logs.vue
+++ b/ui/src/components/executions/Logs.vue
@@ -40,6 +40,7 @@
             :exclude-metas="['namespace', 'flowId', 'taskId', 'executionId']"
             :filter="filter"
             @follow="forwardEvent('follow', $event)"
+            @opened-taskruns-count="openedTaskrunsCounts[taskRun.id] = $event"
             :logs-to-open-parent="logsToOpen"
         />
         <div v-else-if="execution.state.current !== State.RUNNING">
@@ -52,6 +53,7 @@
                 :exclude-metas="['namespace', 'flowId', 'taskId', 'executionId']"
                 :filter="filter"
                 @follow="forwardEvent('follow', $event)"
+                @opened-taskruns-count="openedTaskrunsCounts[taskRun.id] = $event"
                 :logs-to-open-parent="logsToOpen"
             />
         </div>
@@ -67,7 +69,6 @@
     import LogLevelSelector from "../logs/LogLevelSelector.vue";
     import Collapse from "../layout/Collapse.vue";
     import State from "../../utils/state";
-    import {logDisplayTypes} from "../../utils/constants";
 
     export default {
         components: {
@@ -83,7 +84,8 @@
                 fullscreen: false,
                 level: undefined,
                 filter: undefined,
-                logsToOpen: undefined
+                logsToOpen: undefined,
+                openedTaskrunsCounts: {}
             };
         },
         created() {
@@ -110,14 +112,12 @@
                 }
                 return fullList
             },
-            logDisplayButtonText() {
-                if (this.logsToOpen) {
-                    return this.logsToOpen.length !== 0 ? this.$t("collapse all") : this.$t("expand all")
-                } else {
-                    const logDisplay =  localStorage.getItem("logDisplay") || logDisplayTypes.DEFAULT;
-                    return logDisplay === logDisplayTypes.HIDDEN ? this.$t("expand all") : this.$t("collapse all")
-                }
+            openedTaskrunsTotal() {
+                return Object.values(this.openedTaskrunsCounts).reduce((prev, count) => prev + count, 0);
             },
+            logDisplayButtonText() {
+                return this.openedTaskrunsTotal === 0 ? this.$t("expand all") : this.$t("collapse all")
+            }
         },
         methods: {
             downloadContent() {
@@ -145,12 +145,7 @@
                 this.$router.push({query: {...this.$route.query, q: this.filter, level: this.level, page: 1}});
             },
             handleLogDisplay() {
-                const logDisplay =  localStorage.getItem("logDisplay") || logDisplayTypes.DEFAULT;
-                if (this.logsToOpen) {
-                    this.logsToOpen.length === 0 ? this.logsToOpen = State.arrayAllStates().map(s => s.name) : this.logsToOpen = []
-                    return;
-                }
-                if (logDisplay === logDisplayTypes.HIDDEN ) {
+                if(this.openedTaskrunsTotal === 0) {
                     this.logsToOpen = State.arrayAllStates().map(s => s.name)
                 } else {
                     this.logsToOpen = []
diff --git a/ui/src/components/logs/LogList.vue b/ui/src/components/logs/LogList.vue
index 3a28a6ca38..5e741d4c86 100644
--- a/ui/src/components/logs/LogList.vue
+++ b/ui/src/components/logs/LogList.vue
@@ -197,6 +197,7 @@
             Duration,
             TaskIcon,
         },
+        emits: ["opened-taskruns-count"],
         props: {
             level: {
                 type: String,
@@ -254,6 +255,9 @@
             };
         },
         watch: {
+            "showLogs.length": function(openedTaskrunsCount) {
+                this.$emit("opened-taskruns-count", openedTaskrunsCount);
+            },
             level: function () {
                 this.page = 1;
                 this.logsList = [];


Test patch: