From 68ac81a6adc49d4ebc0ae7f7e2f68248ff4afbb2 Mon Sep 17 00:00:00 2001
From: Jannik Stehle <jannik.stehle@gmail.com>
Date: Wed, 19 Oct 2022 10:40:15 +0200
Subject: [PATCH] Fix sidebar when no highlighted resource is present

---
 .../bugfix-sidebar-without-highlighted-resource |  6 ++++++
 .../src/components/SideBar/SideBar.vue          |  2 +-
 packages/web-app-files/src/fileSideBars.ts      | 17 ++++++++++-------
 3 files changed, 17 insertions(+), 8 deletions(-)
 create mode 100644 changelog/unreleased/bugfix-sidebar-without-highlighted-resource

diff --git a/changelog/unreleased/bugfix-sidebar-without-highlighted-resource b/changelog/unreleased/bugfix-sidebar-without-highlighted-resource
new file mode 100644
index 00000000000..88225407e52
--- /dev/null
+++ b/changelog/unreleased/bugfix-sidebar-without-highlighted-resource
@@ -0,0 +1,6 @@
+Bugfix: Sidebar without highlighted resource
+
+Sidebar panels that require a resource now won't be loaded without such. This fixes a bug where navigating with an open sidebar would break it.
+
+https://github.com/owncloud/web/issues/7781
+https://github.com/owncloud/web/pull/7826
diff --git a/packages/web-app-files/src/components/SideBar/SideBar.vue b/packages/web-app-files/src/components/SideBar/SideBar.vue
index f0ec4fa052b..1e7a149121f 100644
--- a/packages/web-app-files/src/components/SideBar/SideBar.vue
+++ b/packages/web-app-files/src/components/SideBar/SideBar.vue
@@ -22,7 +22,7 @@
   >
     <template #header>
       <file-info
-        v-if="isSingleResource && !highlightedFileIsSpace"
+        v-if="highlightedFile && isSingleResource && !highlightedFileIsSpace"
         class="sidebar-panel__file_info"
         :is-sub-panel-active="!!activePanel"
       />
diff --git a/packages/web-app-files/src/fileSideBars.ts b/packages/web-app-files/src/fileSideBars.ts
index 2de70a4cf5f..6b11c5beee7 100644
--- a/packages/web-app-files/src/fileSideBars.ts
+++ b/packages/web-app-files/src/fileSideBars.ts
@@ -47,10 +47,10 @@ const panelGenerators: (({
     component: NoSelection,
     default: () => true,
     get enabled() {
-      return rootFolder && highlightedFile?.type !== 'space'
+      return !highlightedFile || (rootFolder && highlightedFile?.type !== 'space')
     }
   }),
-  ({ router, multipleSelection, rootFolder }) => ({
+  ({ router, multipleSelection, rootFolder, highlightedFile }) => ({
     app: 'details-item',
     icon: 'questionnaire-line',
     title: $gettext('Details'),
@@ -58,7 +58,10 @@ const panelGenerators: (({
     default: !isLocationTrashActive(router, 'files-trash-generic'),
     get enabled() {
       return (
-        !isLocationTrashActive(router, 'files-trash-generic') && !multipleSelection && !rootFolder
+        !isLocationTrashActive(router, 'files-trash-generic') &&
+        !multipleSelection &&
+        !rootFolder &&
+        highlightedFile
       )
     }
   }),
@@ -91,14 +94,14 @@ const panelGenerators: (({
       return highlightedFile?.type === 'space' && !multipleSelection
     }
   }),
-  ({ router, multipleSelection, rootFolder }) => ({
+  ({ router, multipleSelection, rootFolder, highlightedFile }) => ({
     app: 'actions-item',
     icon: 'slideshow-3',
     title: $gettext('Actions'),
     component: FileActions,
     default: isLocationTrashActive(router, 'files-trash-generic'),
     get enabled() {
-      return !multipleSelection && !rootFolder
+      return !multipleSelection && !rootFolder && highlightedFile
     }
   }),
   ({ multipleSelection, highlightedFile, user }) => ({
@@ -119,7 +122,7 @@ const panelGenerators: (({
       ].includes(user.uuid)
     }
   }),
-  ({ capabilities, router, multipleSelection, rootFolder }) => ({
+  ({ capabilities, router, multipleSelection, rootFolder, highlightedFile }) => ({
     app: 'sharing-item',
     icon: 'user-add',
     iconFillType: 'line',
@@ -135,7 +138,7 @@ const panelGenerators: (({
       }
     },
     get enabled() {
-      if (multipleSelection || rootFolder) {
+      if (multipleSelection || rootFolder || !highlightedFile) {
         return false
       }
       if (