Skip to content

Commit 7cc0468

Browse files
authored
Merge pull request #1418 from nextcloud-libraries/chore/only-registered-views
refactor!(navigation): pass `id` of view to `setActive`
2 parents a362b02 + 55ab07f commit 7cc0468

4 files changed

Lines changed: 63 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ All notable changes to this project will be documented in this file.
88

99
## 4.0.0 (UNRELEASED)
1010
### 📝 Notes
11-
* The support for Nextcloud versions below 30 has been removed,
12-
this means some functions like filename validation will now only
13-
work with the capabilities provided by Nextcloud 30 or newer.
11+
* Due to breaking changes this major version is only compatible with
12+
the files app of Nextcloud 33 or later.
1413
* The Node API was changed, the `root` property of any node,
1514
including `File` or `Folder`, is now required.
15+
* All methods now also accept the interface of the provided classes,
16+
meaning instead of accepting `View` they accept the more generic
17+
`IView` interface. This allows better integration with frameworks
18+
and custom implementations of the interface where needed.
1619

1720
#### DAV related export
1821
The DAV related exports from the main entry point were deprecated
@@ -34,10 +37,10 @@ For example:
3437

3538
```diff
3639
type ActionContext = {
37-
nodes: Node[],
38-
view: View,
39-
folder: Folder,
40-
contents: Node[],
40+
nodes: INode[],
41+
view: IView,
42+
folder: IFolder,
43+
contents: INode[],
4144
}
4245

4346
- action.exec(view: View, folder: Folder, dir: string): Promise<boolean>
@@ -102,20 +105,24 @@ type ActionContext = {
102105
* chore(deps): Bump @nextcloud/sharing from 0.2.4 to 0.3.0
103106
* chore(deps): Bump brace-expansion
104107
* chore(deps): Bump is-svg from 6.0.0 to 6.1.0
105-
* chore(deps-dev): Bump @nextcloud/event-bus from 3.3.2 to 3.3.3
106-
* chore(deps-dev): Bump @nextcloud/typings from 1.9.1 to 1.10.0
107-
* chore(deps-dev): Bump @nextcloud/vite-config from 2.3.5 to 2.4.0
108-
* chore(deps-dev): Bump @types/node from 24.0.3 to 24.10.0
109-
* chore(deps-dev): Bump @vitest/coverage-istanbul from 4.0.6 to 4.0.13
110-
* chore(deps-dev): Bump fast-xml-parser from 5.2.5 to 5.3.2
111-
* chore(deps-dev): Bump js-yaml from 4.1.0 to 4.1.1
112-
* chore(deps-dev): Bump jsdom from 26.1.0 to 27.2.0
113-
* chore(deps-dev): Bump sha.js from 2.4.11 to 2.4.12
114-
* chore(deps-dev): Bump typedoc from 0.28.10 to 0.28.10
115-
* chore(deps-dev): Bump typedoc-plugin-missing-exports from 4.0.0 to 4.1.2
116-
* chore(deps-dev): Bump typescript from 5.8.3 to 5.9.3
117-
* chore(deps-dev): Bump vite from 6.3.5 to 7.2.4
118-
* chore(deps-dev): Bump vitest from 3.2.4 to 4.0.6
108+
109+
## 3.12.1 - 2025-12-11
110+
### 🐛 Fixed bugs
111+
* fix(sortNodes): do not trim "extension" of folder names [\#1291](https://github.com/nextcloud-libraries/nextcloud-files/pull/1291) \([susnux](https://github.com/susnux)\)
112+
113+
### Changed
114+
* docs(View): improve documentation of `View.emptyView` [\#1290](https://github.com/nextcloud-libraries/nextcloud-files/pull/1290) \([susnux](https://github.com/susnux)\)
115+
* chore: work around bug in `corepack` blocking dependency updates [\#1292](https://github.com/nextcloud-libraries/nextcloud-files/pull/1292) \([susnux](https://github.com/susnux)\)
116+
* ci: update workflows from organization [\#1354](https://github.com/nextcloud-libraries/nextcloud-files/pull/1354) \([susnux](https://github.com/susnux)\)
117+
* chore: align devEngines with apps [\#1355](https://github.com/nextcloud-libraries/nextcloud-files/pull/1355) \([susnux](https://github.com/susnux)\)
118+
* Updated dependencies:
119+
* Bump `is-svg` to 6.1.0
120+
* Bump `@nextcloud/sharing` to to 0.3.0
121+
* Bump `@nextcloud/auth` to to 2.5.3
122+
* Bump `@nextcloud/l10n` to to 3.4.1
123+
* Bump `@nextcloud/capabilities` to to 1.2.1
124+
* Bump `@nextcloud/router` to to 3.1.0
125+
* Bump `@nextcloud/paths` to to 2.3.0
119126

120127
## 3.12.0 - 2025-07-24
121128
### 🚀 Enhancements

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ This library provides three kinds of utils:
1717

1818
| `@nextcloud/files` version | Supported | Nextcloud version |
1919
|----------------------------|-----------|-------------------|
20-
| 4.x || 30+ |
21-
| 3.x || 26+ |
20+
| 4.x || 33+ |
21+
| 3.x || 26-32 |
2222
| 2.x || 23-25 |
2323
| 1.x || 20-22 |
2424

__tests__/navigation.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Navigation', () => {
109109

110110
expect(navigation.active).toBe(null)
111111

112-
navigation.setActive(view)
112+
navigation.setActive(view.id)
113113
expect(navigation.active).toEqual(view)
114114
})
115115

@@ -122,9 +122,25 @@ describe('Navigation', () => {
122122
const listener = vi.fn()
123123
navigation.addEventListener('updateActive', listener)
124124

125-
navigation.setActive(view)
125+
navigation.setActive(view.id)
126126
expect(listener).toHaveBeenCalledOnce()
127127
// So it was called, we then expect the first argument of the first call to be the event with the view as the detail
128128
expect(listener.mock.calls[0][0].detail).toBe(view)
129129
})
130+
131+
it('Can unset the active view', async () => {
132+
const navigation = new Navigation()
133+
const { view } = mockView()
134+
navigation.register(view)
135+
navigation.setActive(view.id)
136+
expect(navigation.active).toEqual(view)
137+
138+
navigation.setActive(null)
139+
expect(navigation.active).toBeNull()
140+
})
141+
142+
it('Throws when there is no view to set active', () => {
143+
const navigation = new Navigation()
144+
expect(() => navigation.setActive('does not exist')).toThrowError()
145+
})
130146
})

lib/navigation/navigation.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,23 @@ export class Navigation extends TypedEventTarget<{ updateActive: UpdateActiveVie
8181

8282
/**
8383
* Set the currently active view
84+
*
85+
* @param id - The id of the view to set as active
86+
* @throws {Error} If no view with the given id was registered
8487
* @fires UpdateActiveViewEvent
85-
* @param view New active view
8688
*/
87-
setActive(view: IView | null): void {
88-
this._currentView = view
89-
const event = new CustomEvent<IView | null>('updateActive', { detail: view })
89+
setActive(id: string | null): void {
90+
if (id === null) {
91+
this._currentView = null
92+
} else {
93+
const view = this._views.find(({ id: viewId }) => viewId === id)
94+
if (!view) {
95+
throw new Error(`No view with ${id} registered`)
96+
}
97+
this._currentView = view
98+
}
99+
100+
const event = new CustomEvent<IView | null>('updateActive', { detail: this._currentView })
90101
this.dispatchTypedEvent('updateActive', event as UpdateActiveViewEvent)
91102
}
92103

0 commit comments

Comments
 (0)