Skip to content

Commit 6594346

Browse files
authored
Merge pull request #1281 from nextcloud-libraries/feat/hidden-view
feat(view): add `hidden` attribute to the View
2 parents 7aa839f + a7dedda commit 6594346

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

__tests__/view.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ describe('Invalid View creation', () => {
5858
} as unknown as View),
5959
).toThrowError('View icon is required and must be a valid svg string')
6060
})
61+
62+
test('Invalid hidden', () => {
63+
expect(() => new View({
64+
id: 'test',
65+
name: 'Test',
66+
order: 1,
67+
hidden: 'true',
68+
getContents: () => Promise.reject(new Error()),
69+
} as unknown as View),
70+
).toThrowError('View hidden must be a boolean')
71+
})
72+
6173
test('Invalid order', () => {
6274
expect(() => new View({
6375
id: 'test',
@@ -157,6 +169,7 @@ describe('View creation', () => {
157169
emptyTitle: 'Test empty title',
158170
emptyCaption: 'Test empty caption',
159171
getContents: () => Promise.resolve({ folder, contents: [] }),
172+
hidden: true,
160173
icon: '<svg></svg>',
161174
order: 1,
162175
params: {},
@@ -175,6 +188,7 @@ describe('View creation', () => {
175188
expect(view.emptyTitle).toBe('Test empty title')
176189
expect(view.emptyCaption).toBe('Test empty caption')
177190
await expect(view.getContents('/')).resolves.toStrictEqual({ folder, contents: [] })
191+
expect(view.hidden).toBe(true)
178192
expect(view.icon).toBe('<svg></svg>')
179193
expect(view.order).toBe(1)
180194
expect(view.params).toStrictEqual({})

lib/navigation/view.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ interface ViewData {
3535
* information alongside with its content.
3636
*/
3737
getContents: (path: string) => Promise<ContentsWithRoot>
38+
39+
/**
40+
* If set then the view will be hidden from the navigation unless its the active view.
41+
*/
42+
hidden?: true
43+
3844
/** The view icon as an inline svg */
3945
icon: string
4046

@@ -115,6 +121,10 @@ export class View implements ViewData {
115121
return this._view.getContents
116122
}
117123

124+
get hidden() {
125+
return this._view.hidden
126+
}
127+
118128
get icon() {
119129
return this._view.icon
120130
}
@@ -198,6 +208,10 @@ const isValidView = function(view: ViewData): boolean {
198208
throw new Error('View getContents is required and must be a function')
199209
}
200210

211+
if ('hidden' in view && typeof view.hidden !== 'boolean') {
212+
throw new Error('View hidden must be a boolean')
213+
}
214+
201215
if (!view.icon || typeof view.icon !== 'string' || !isSvg(view.icon)) {
202216
throw new Error('View icon is required and must be a valid svg string')
203217
}

vitest.config.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: CC0-1.0
44
*/
5+
56
import config from './vite.config'
67

78
export default async (env) => {
89
const cfg = await config(env)
9-
// Node externals does not work when testing
10-
cfg.plugins = cfg.plugins!.filter((plugin) => plugin && plugin.name !== 'node-externals')
10+
delete cfg.define
1111

12-
cfg.test = {
13-
environment: 'jsdom',
14-
coverage: {
15-
include: ['lib/**'],
16-
exclude: ['lib/utils/logger.ts'],
17-
provider: 'istanbul',
18-
reporter: ['lcov', 'text'],
12+
return {
13+
...cfg,
14+
test: {
15+
env: {
16+
LANG: 'en-US',
17+
},
18+
environment: 'jsdom',
19+
coverage: {
20+
include: ['lib/**'],
21+
exclude: ['lib/utils/logger.ts'],
22+
provider: 'istanbul',
23+
reporter: ['lcov', 'text'],
24+
},
25+
globalSetup: '__tests__/test-global-setup.ts',
1926
},
20-
globalSetup: '__tests__/test-global-setup.ts',
2127
}
22-
delete cfg.define
23-
return cfg
2428
}

0 commit comments

Comments
 (0)