Skip to content

Commit 07c1738

Browse files
committed
refactor(NcAppContent): clarify props documentation and use capabilities over initial state
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent a89c60e commit 07c1738

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

src/components/NcAppContent/NcAppContent.vue

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,20 @@ export default {
145145

146146
<script>
147147
import { getBuilder } from '@nextcloud/browser-storage'
148+
import { getCapabilities } from '@nextcloud/capabilities'
148149
import { emit } from '@nextcloud/event-bus'
149150
import { loadState } from '@nextcloud/initial-state'
150151
import { useSwipe } from '@vueuse/core'
151152
import { Splitpanes, Pane } from 'splitpanes'
153+
import NcAppContentDetailsToggle from './NcAppContentDetailsToggle.vue'
152154
import { useIsMobile } from '../../composables/useIsMobile/index.js'
155+
import { logger } from '../../utils/logger.ts'
153156
import { isRtl } from '../../utils/rtl.ts'
154157
155-
import NcAppContentDetailsToggle from './NcAppContentDetailsToggle.vue'
156-
157158
import 'splitpanes/dist/splitpanes.css'
158159
159160
const browserStorage = getBuilder('nextcloud').persist().build()
160-
const { name: productName } = loadState('theming', 'data', { name: 'Nextcloud' })
161+
const instanceName = getCapabilities().theming?.name ?? 'Nextcloud'
161162
const activeApp = loadState('core', 'active-app', appName)
162163
const localizedAppNameState = loadState('core', 'apps', {})
163164
const localizedAppName = (Array.isArray(localizedAppNameState)
@@ -197,8 +198,9 @@ export default {
197198
198199
/**
199200
* Allows you to set the default width of the resizable list in % on vertical-split
200-
* Allows you to set the default height of the resizable list in % on horizontal-split
201-
* Must be between listMinWidth and listMaxWidth
201+
* or respectively the default height on horizontal-split.
202+
*
203+
* Must be between `listMinWidth` and `listMaxWidth`.
202204
*/
203205
listSize: {
204206
type: Number,
@@ -207,7 +209,7 @@ export default {
207209
208210
/**
209211
* Allows you to set the minimum width of the list column in % on vertical-split
210-
* Allows you to set the minimum height of the list column in % on horizontal-split
212+
* or respectively the minimum height on horizontal-split.
211213
*/
212214
listMinWidth: {
213215
type: Number,
@@ -216,7 +218,7 @@ export default {
216218
217219
/**
218220
* Allows you to set the maximum width of the list column in % on vertical-split
219-
* Allows you to set the maximum height of the list column in % on horizontal-split
221+
* or respectively the maximum height on horizontal-split.
220222
*/
221223
listMaxWidth: {
222224
type: Number,
@@ -245,13 +247,6 @@ export default {
245247
default: true,
246248
},
247249
248-
/**
249-
* Specify the `<h1>` page heading
250-
*/
251-
pageHeading: {
252-
type: String,
253-
default: null,
254-
},
255250
/**
256251
* Content layout used when there is a list together with content:
257252
* - `vertical-split` - a 2-column layout with list and default content separated vertically
@@ -267,12 +262,20 @@ export default {
267262
},
268263
},
269264
265+
/**
266+
* Specify the `<h1>` page heading
267+
*/
268+
pageHeading: {
269+
type: String,
270+
default: null,
271+
},
272+
270273
/**
271274
* Allow setting the page's `<title>`
272275
*
273-
* If a page heading is set it defaults to `{pageHeading} - {appName} - {productName}` e.g. `Favorites - Files - Nextcloud`.
274-
* When the page heading and the app name is the same only one is used, e.g. `Files - Files - Nextcloud` is shown as `Files - Nextcloud`.
275-
* When setting the prop then the following format will be used: `{pageTitle} - {pageHeading || appName} - {productName}`
276+
* If a page heading is set it defaults to `{pageHeading} - {appName} - {instanceName}` e.g. `Favorites - Files - MyPersonalCloud`.
277+
* When the page heading and the app name is the same only one is used, e.g. `Files - Files - MyPersonalCloud` is shown as `Files - MyPersonalCloud`.
278+
* When setting the prop then the following format will be used: `{pageTitle} - {instanceName}`
276279
*/
277280
pageTitle: {
278281
type: String,
@@ -317,7 +320,7 @@ export default {
317320
// to a global storage key
318321
return `pane-list-size-${appName}`
319322
} catch (e) {
320-
console.info('[INFO] AppContent:', 'falling back to global nextcloud pane config')
323+
logger.info('[NcAppContent]: falling back to global nextcloud pane config')
321324
return 'pane-list-size-nextcloud'
322325
}
323326
},
@@ -350,20 +353,27 @@ export default {
350353
realPageTitle() {
351354
const entries = new Set()
352355
if (this.pageTitle) {
353-
entries.add(this.pageTitle)
354-
}
355-
if (this.pageHeading) {
356-
entries.add(this.pageHeading)
357-
}
358-
if (entries.size === 0) {
356+
// when page title is set we only use that
357+
// we still split to remove duplicated instanceName
358+
for (const part of this.pageTitle.split(' - ')) {
359+
entries.add(part)
360+
}
361+
} else if (this.pageHeading) {
362+
// when the page heading is provided but not the title
363+
// then we split to remove duplicates
364+
// but also add the localized app name
365+
for (const part of this.pageHeading.split(' - ')) {
366+
entries.add(part)
367+
}
368+
369+
if (entries.size > 0) {
370+
entries.add(localizedAppName)
371+
}
372+
} else {
359373
return null
360374
}
361375
362-
if (entries.size < 2) {
363-
// Only add if not already pageHeading and pageTitle are included
364-
entries.add(localizedAppName)
365-
}
366-
entries.add(productName)
376+
entries.add(instanceName)
367377
return [...entries.values()].join(' - ')
368378
},
369379
},

tests/unit/components/NcAppContent/NcAppContent.spec.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,44 @@ describe('NcAppContent', () => {
5353
expect(document.title).toBe('nextcloud-vue - Nextcloud')
5454
})
5555

56+
it('does not duplicate the heading in the document title if already formatted', () => {
57+
mount(NcAppContent, {
58+
propsData: {
59+
pageHeading: 'My heading - nextcloud-vue',
60+
},
61+
})
62+
63+
expect(document.title).toBe('My heading - nextcloud-vue - Nextcloud')
64+
})
65+
5666
it('sets the document title if pageTitle is provided', () => {
5767
mount(NcAppContent, {
5868
propsData: {
5969
pageTitle: 'My title',
6070
},
6171
})
6272

63-
expect(document.title).toBe('My title - nextcloud-vue - Nextcloud')
73+
expect(document.title).toBe('My title - Nextcloud')
6474
})
6575

6676
it('does not duplicate the title in the document title', () => {
6777
mount(NcAppContent, {
6878
propsData: {
69-
pageTitle: 'nextcloud-vue',
79+
pageTitle: 'Nextcloud',
7080
},
7181
})
7282

73-
expect(document.title).toBe('nextcloud-vue - Nextcloud')
83+
expect(document.title).toBe('Nextcloud')
84+
})
85+
86+
it('does not duplicate the title in the document title if already formatted', () => {
87+
mount(NcAppContent, {
88+
propsData: {
89+
pageTitle: 'My title - Nextcloud',
90+
},
91+
})
92+
93+
expect(document.title).toBe('My title - Nextcloud')
7494
})
7595

7696
it('sets the document title if pageTitle and pageHeading are provided', () => {
@@ -81,6 +101,6 @@ describe('NcAppContent', () => {
81101
},
82102
})
83103

84-
expect(document.title).toBe('My title - My heading - Nextcloud')
104+
expect(document.title).toBe('My title - Nextcloud')
85105
})
86106
})

0 commit comments

Comments
 (0)