Skip to content

Commit 8e5c85f

Browse files
committed
fix: folder tree selection after any action in main content
Signed-off-by: mykh-hailo <kristianderonta0205@gmail.com>
1 parent c61b17f commit 8e5c85f

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

apps/files/src/components/FilesNavigationListItem.vue

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ import type { IView } from '@nextcloud/files'
88
99
import { getCanonicalLocale, getLanguage } from '@nextcloud/l10n'
1010
import { computed, onMounted, ref } from 'vue'
11+
import { useRoute } from 'vue-router/composables'
1112
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
1213
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
1314
import { useVisibleViews } from '../composables/useViews.ts'
1415
import { folderTreeId } from '../services/FolderTree.ts'
1516
import { useViewConfigStore } from '../store/viewConfig.ts'
1617
18+
/**
19+
* Views whose main file list is driven by `dir`. The route often carries a `fileid` for the
20+
* selected row; many actions switch `view` between `folders`, `files`, and `personal` while
21+
* keeping the same directory — the folder tree should stay highlighted based on `dir` only.
22+
*/
23+
const PATH_BASED_LISTING_VIEW_IDS = new Set<string>([folderTreeId, 'files', 'personal'])
24+
1725
const props = withDefaults(defineProps<{
1826
view: IView
1927
level?: number
@@ -24,9 +32,22 @@ const props = withDefaults(defineProps<{
2432
const maxLevel = 6 // Limit nesting to not exceed max call stack size
2533
const viewConfigStore = useViewConfigStore()
2634
const viewConfig = computed(() => viewConfigStore.viewConfigs[props.view.id])
35+
const route = useRoute()
2736
const isExpanded = computed(() => viewConfig.value
2837
? (viewConfig.value.expanded === true)
2938
: (props.view.expanded === true))
39+
const isFolderTreeNode = computed(() => props.view.id.startsWith(`${folderTreeId}::`))
40+
const isDirectoryActive = computed(() => {
41+
if (!isFolderTreeNode.value) {
42+
return false
43+
}
44+
45+
const currentView = String(route.params?.view ?? '')
46+
const currentDir = normalizeDir(route.query?.dir)
47+
const viewDir = normalizeDir(props.view.params?.dir)
48+
49+
return PATH_BASED_LISTING_VIEW_IDS.has(currentView) && currentDir === viewDir
50+
})
3051
3152
const views = useVisibleViews()
3253
const childViews = computed(() => {
@@ -66,6 +87,16 @@ const hasChildViews = computed(() => childViews.value.length > 0)
6687
const navigationRoute = computed(() => {
6788
if (props.view.params) {
6889
const { dir } = props.view.params
90+
// Folder tree: navigate by `dir` only (no `fileid` in the path). Matches how the list
91+
// is located (`?dir=…`) even when a file row is selected (`/:fileid`).
92+
if (isFolderTreeNode.value) {
93+
const dirParam = typeof dir === 'string' ? dir : '/'
94+
return {
95+
name: 'filelist',
96+
params: { view: folderTreeId },
97+
query: { dir: dirParam },
98+
}
99+
}
69100
return { name: 'filelist', params: { ...props.view.params }, query: { dir } }
70101
}
71102
return { name: 'filelist', params: { view: props.view.id } }
@@ -121,6 +152,18 @@ async function loadChildViews() {
121152
}
122153
}
123154
}
155+
156+
/**
157+
* Normalize directory paths for route comparisons.
158+
*
159+
* @param dir - the route directory to normalize
160+
*/
161+
function normalizeDir(dir: unknown): string {
162+
if (typeof dir !== 'string' || dir.length === 0) {
163+
return '/'
164+
}
165+
return dir.replace(/^(.+)\/$/, '$1')
166+
}
124167
</script>
125168

126169
<script lang="ts">
@@ -141,7 +184,8 @@ export default {
141184
allow-collapse
142185
:loading="isLoading"
143186
:data-cy-files-navigation-item="view.id"
144-
:exact="hasChildViews /* eslint-disable-line @nextcloud/vue/no-deprecated-props */"
187+
:exact="isFolderTreeNode || hasChildViews /* eslint-disable-line @nextcloud/vue/no-deprecated-props */"
188+
:active="isDirectoryActive"
145189
:name="view.name"
146190
:open="isExpanded"
147191
:pinned="view.sticky"

0 commit comments

Comments
 (0)