Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Migrate jsdoc to typescript in components to typescript
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge authored and susnux committed Apr 23, 2025
commit 1040c0ad43294d4ef0d1cb486d20857a2b4bb61b
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
},
overrides: [
{
files: ['*.ts'],
files: ['*.ts', '*.vue'],
rules: {
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param': 'off',
Expand Down
26 changes: 8 additions & 18 deletions src/components/Albums/AlbumForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
import { generateRemoteUrl } from '@nextcloud/router'

import CollaboratorsSelectionForm from './CollaboratorsSelectionForm.vue'
import type { Album, Collaborator } from '../../store/albums'
import type { PropType } from 'vue'

export default {
name: 'AlbumForm',
Expand All @@ -102,9 +104,8 @@
},

props: {
/** @type {import('vue').PropType<import('../../store/albums.js').Album|null>} */
album: {
type: Object,
type: Object as PropType<Album|null>,

Check warning on line 108 in src/components/Albums/AlbumForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumForm.vue#L108

Added line #L108 was not covered by tests
default: null,
},
displayBackButton: {
Expand All @@ -123,24 +124,15 @@
},

computed: {
/**
* @return {boolean} Whether sharing is enabled.
*/
editMode() {
editMode(): boolean {

Check warning on line 127 in src/components/Albums/AlbumForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumForm.vue#L127

Added line #L127 was not covered by tests
return this.album !== null
},

/**
* @return {boolean} Whether sharing is enabled.
*/
sharingEnabled() {
sharingEnabled(): boolean {

Check warning on line 131 in src/components/Albums/AlbumForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumForm.vue#L131

Added line #L131 was not covered by tests
return OC.Share !== undefined
},

/**
* @return {string} The album's filename based on its name. Useful to fetch the location information and content.
*/
albumFileName() {
albumFileName(): string {

Check warning on line 135 in src/components/Albums/AlbumForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumForm.vue#L135

Added line #L135 was not covered by tests
return this.$store.getters.getAlbumName(this.albumName)
},
},
Expand All @@ -159,8 +151,7 @@
methods: {
...mapActions(['createCollection', 'renameCollection', 'updateCollection']),

/** @param {import('../../store/albums.js').Collaborator[]} collaborators */
submit(collaborators = []) {
submit(collaborators: Collaborator[] = []) {

Check warning on line 154 in src/components/Albums/AlbumForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumForm.vue#L154

Added line #L154 was not covered by tests
if (this.albumName === '' || this.loading) {
return
}
Expand All @@ -172,8 +163,7 @@
}
},

/** @param {import('../../store/albums.js').Collaborator[]} collaborators */
async handleCreateAlbum(collaborators = []) {
async handleCreateAlbum(collaborators: Collaborator[] = []) {

Check warning on line 166 in src/components/Albums/AlbumForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumForm.vue#L166

Added line #L166 was not covered by tests
try {
this.loading = true
let album = await this.createCollection({
Expand Down
26 changes: 6 additions & 20 deletions src/components/Albums/AlbumPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

import FetchCollectionsMixin from '../../mixins/FetchCollectionsMixin.js'
import AlbumForm from './AlbumForm.vue'
import type { Album } from '../../store/albums.js'

export default {
name: 'AlbumPicker',
Expand All @@ -77,11 +78,7 @@
},

filters: {
/**
* @param {string} fileId - The id of the file.
* @return {string}
*/
toCoverUrl(fileId) {
toCoverUrl(fileId: string): string {

Check warning on line 81 in src/components/Albums/AlbumPicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumPicker.vue#L81

Added line #L81 was not covered by tests
return generateUrl(`/apps/photos/api/v1/preview/${fileId}?x=${64}&y=${64}`)
},
},
Expand All @@ -102,10 +99,7 @@
'sharedAlbums',
]),

/**
* @return {import('../../store/albums.js').Album[]}
*/
allAlbums() {
allAlbums(): Album[] {

Check warning on line 102 in src/components/Albums/AlbumPicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumPicker.vue#L102

Added line #L102 was not covered by tests
return [...Object.values(this.albums), ...Object.values(this.sharedAlbums)]
},
},
Expand All @@ -125,23 +119,15 @@
this.fetchAlbumList()
},

pickAlbum(album) {
pickAlbum(album: Album) {

Check warning on line 122 in src/components/Albums/AlbumPicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumPicker.vue#L122

Added line #L122 was not covered by tests
this.$emit('album-picked', album)
},

/**
* @param {object} album
* @return {boolean}
*/
isSharedAlbum(album) {
isSharedAlbum(album: Album): boolean {

Check warning on line 126 in src/components/Albums/AlbumPicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumPicker.vue#L126

Added line #L126 was not covered by tests
return album.filename.match(/^\/photos\/.+\/sharedalbums\//) !== null
},

/**
* @param {object} album The album's full name, including the userid.
* @return {string} The album name without the userId between parentheses.
*/
originalName(album) {
originalName(album: Album): string {

Check warning on line 130 in src/components/Albums/AlbumPicker.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/AlbumPicker.vue#L130

Added line #L130 was not covered by tests
if (this.isSharedAlbum(album)) {
return album.basename.replace(new RegExp(`\\(${album.collaborators[0].id}\\)$`), '')
} else {
Expand Down
121 changes: 43 additions & 78 deletions src/components/Albums/CollaboratorsSelectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
:display-name="availableCollaborators[collaboratorKey].label"
:name="availableCollaborators[collaboratorKey].label"
:user="availableCollaborators[collaboratorKey].id"
:is-no-user="availableCollaborators[collaboratorKey].type !== collaboratorTypes.SHARE_TYPE_USER">
<AccountGroup v-if="availableCollaborators[collaboratorKey].type === collaboratorTypes.SHARE_TYPE_GROUP" :title="t('photos', 'Group')" />
:is-no-user="availableCollaborators[collaboratorKey].type !== collaboratorTypes.User">
<AccountGroup v-if="availableCollaborators[collaboratorKey].type === collaboratorTypes.Group" :title="t('photos', 'Group')" />
<NcButton type="tertiary"
:aria-label="t('photos', 'Remove {collaboratorLabel} from the collaborators list', {collaboratorLabel: availableCollaborators[collaboratorKey].label})"
@click="unselectEntity(collaboratorKey)">
Expand Down Expand Up @@ -100,25 +100,19 @@
import { getCurrentUser } from '@nextcloud/auth'
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
import { NcButton, NcListItemIcon, NcSelect } from '@nextcloud/vue'
import { Type } from '@nextcloud/sharing'
import { ShareType } from '@nextcloud/sharing'

Check warning on line 103 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L103

Added line #L103 was not covered by tests
import { translate } from '@nextcloud/l10n'

import logger from '../../services/logger.js'
import FetchCollectionContentMixin from '../../mixins/FetchCollectionContentMixin.js'
import type { Collaborator } from '../../store/albums.js'
import type { PropType } from 'vue'

/**
* @typedef {object} Collaborator
* @property {string} id - The id of the collaborator.
* @property {string} label - The label of the collaborator for display.
* @property {Type.SHARE_TYPE_USER|Type.SHARE_TYPE_GROUP|Type.SHARE_TYPE_LINK} type - The type of the collaborator.
*/

/**
* @typedef {Collaborator} SearchResult
* @property {string} key
* @property {string} displayName - The label of the collaborator for display.
* @property {Element} [iconSvg] - An icon to differentiate the collaborator type.
*/
type CollaboratorSearchResult = Collaborator & {
key: string
displayName: string // The label of the collaborator for display.
iconSvg?: Element // An icon to differentiate the collaborator type.
}

export default {
name: 'CollaboratorsSelectionForm',
Expand All @@ -142,9 +136,8 @@
required: true,
},

/** @type {import('vue').PropType<import('../../store/albums.js').Collaborator[]>} */
collaborators: {
type: Array,
type: Array as PropType<Collaborator[]>,

Check warning on line 140 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L140

Added line #L140 was not covered by tests
default: () => [],
},

Expand All @@ -157,76 +150,56 @@
data() {
return {
searchText: null,
/** @type {import('../../store/albums.js').IndexedCollaborators} */
availableCollaborators: {},
/** @type {string[]} */
selectedCollaboratorsKeys: [],
/** @type {import('../../store/albums.js').Collaborator[]} */
currentSearchResults: [],
availableCollaborators: {} as Record<string, Collaborator>,
selectedCollaboratorsKeys: [] as string[],
currentSearchResults: [] as Collaborator[],

Check warning on line 155 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L153-L155

Added lines #L153 - L155 were not covered by tests
loadingCollaborators: false,
randomId: Math.random().toString().substring(2, 10),
publicLinkCopied: false,
collaboratorTypes: Type,
collaboratorTypes: ShareType,

Check warning on line 159 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L159

Added line #L159 was not covered by tests
config: {
minSearchStringLength: parseInt(OC.config['sharing.minSearchStringLength'], 10) || 0,
},
}
},

computed: {
/**
* @return {SearchResult[]}
*/
searchResults() {
searchResults(): CollaboratorSearchResult[] {

Check warning on line 167 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L167

Added line #L167 was not covered by tests
return this.currentSearchResults
.filter(({ id }) => id !== getCurrentUser().uid)
.filter(({ id }) => id !== getCurrentUser()?.uid)

Check warning on line 169 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L169

Added line #L169 was not covered by tests
.map((collaborator) => {
return {
...collaborator,
key: `${collaborator.type}:${collaborator.id}`,
iconSvg: collaborator.type === Type.SHARE_TYPE_GROUP ? AccountGroupSvg : undefined,
iconSvg: collaborator.type === ShareType.Group ? AccountGroupSvg : undefined,

Check warning on line 174 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L174

Added line #L174 was not covered by tests
}
})
.filter(({ key }) => !this.selectedCollaboratorsKeys.includes(key))
},

/**
* @return {string[]}
*/
listableSelectedCollaboratorsKeys() {
listableSelectedCollaboratorsKeys(): string[] {

Check warning on line 180 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L180

Added line #L180 was not covered by tests
return this.selectedCollaboratorsKeys
.filter(collaboratorKey => this.availableCollaborators[collaboratorKey].type !== Type.SHARE_TYPE_LINK)
.filter(collaboratorKey => this.availableCollaborators[collaboratorKey].type !== ShareType.Link)

Check warning on line 182 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L182

Added line #L182 was not covered by tests
},

/**
* @return {import('../../store/albums.js').Collaborator[]}
*/
selectedCollaborators() {
selectedCollaborators(): Collaborator[] {

Check warning on line 185 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L185

Added line #L185 was not covered by tests
return this.selectedCollaboratorsKeys
.map((collaboratorKey) => this.availableCollaborators[collaboratorKey])
},

/**
* @return {boolean}
*/
isPublicLinkSelected() {
return this.selectedCollaboratorsKeys.includes(`${Type.SHARE_TYPE_LINK}`)
isPublicLinkSelected(): boolean {
return this.selectedCollaboratorsKeys.includes(`${ShareType.Link}`)

Check warning on line 191 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L190-L191

Added lines #L190 - L191 were not covered by tests
},

/** @return {import('../../store/albums.js').Collaborator} */
publicLink() {
return this.availableCollaborators[Type.SHARE_TYPE_LINK]
publicLink(): Collaborator {
return this.availableCollaborators[ShareType.Link]

Check warning on line 195 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L194-L195

Added lines #L194 - L195 were not covered by tests
},

/** @return {string} */
publicLinkURL() {
publicLinkURL(): string {

Check warning on line 198 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L198

Added line #L198 was not covered by tests
return `${window.location.protocol}//${window.location.host}${generateUrl(`apps/photos/public/${this.publicLink.id}`)}`
},

/**
* @return {string} The album's filename based on its name. Useful to fetch the location information and content.
*/
albumFileName() {
albumFileName(): string {

Check warning on line 202 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L202

Added line #L202 was not covered by tests
return this.$store.getters.getAlbumName(this.albumName)
},
},
Expand All @@ -246,10 +219,8 @@

/**
* Fetch possible collaborators.
*
* @param {string} query
*/
async searchCollaborators(query) {
async searchCollaborators(query: string) {

Check warning on line 223 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L223

Added line #L223 was not covered by tests
if (query === undefined) {
return
}
Expand All @@ -267,8 +238,8 @@
search: query,
itemType: 'share-recipients',
shareTypes: [
Type.SHARE_TYPE_USER,
Type.SHARE_TYPE_GROUP,
ShareType.User,
ShareType.Group,

Check warning on line 242 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L241-L242

Added lines #L241 - L242 were not covered by tests
],
},
})
Expand All @@ -277,9 +248,9 @@
.map(collaborator => {
switch (collaborator.source) {
case 'users':
return { id: collaborator.id, label: collaborator.label, type: Type.SHARE_TYPE_USER }
return { id: collaborator.id, label: collaborator.label, type: ShareType.User }

Check warning on line 251 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L251

Added line #L251 was not covered by tests
case 'groups':
return { id: collaborator.id, label: collaborator.label, type: Type.SHARE_TYPE_GROUP }
return { id: collaborator.id, label: collaborator.label, type: ShareType.Group }

Check warning on line 253 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L253

Added line #L253 was not covered by tests
default:
throw new Error(`Invalid collaborator source ${collaborator.source}`)
}
Expand All @@ -291,42 +262,36 @@
}
} catch (error) {
this.errorFetchingCollaborators = error
logger.error(t('photos', 'Failed to fetch collaborators list.'), error)
showError(t('photos', 'Failed to fetch collaborators list.'))
logger.error(this.t('photos', 'Failed to fetch collaborators list.'), { error })
showError(this.t('photos', 'Failed to fetch collaborators list.'))

Check warning on line 266 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L265-L266

Added lines #L265 - L266 were not covered by tests
} finally {
this.loadingCollaborators = false
}
},

/**
* Populate selectedCollaboratorsKeys and availableCollaborators.
*
* @param {import('../../store/albums.js').Collaborator[]} collaborators - The list of collaborators
*/
populateCollaborators(collaborators) {
populateCollaborators(collaborators: Collaborator[]) {

Check warning on line 275 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L275

Added line #L275 was not covered by tests
const initialCollaborators = collaborators.reduce(this.indexCollaborators, {})
this.selectedCollaboratorsKeys = Object.keys(initialCollaborators)
this.availableCollaborators = {
3: {
id: '',
label: t('photos', 'Public link'),
type: Type.SHARE_TYPE_LINK,
label: this.t('photos', 'Public link'),
type: ShareType.Link,

Check warning on line 282 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L281-L282

Added lines #L281 - L282 were not covered by tests
},
...this.availableCollaborators,
...initialCollaborators,
}
},

/**
* @param {import('../../store/albums.js').IndexedCollaborators} collaborators - Index of collaborators
* @param {import('../../store/albums.js').Collaborator} collaborator - A collaborator
*/
indexCollaborators(collaborators, collaborator) {
return { ...collaborators, [`${collaborator.type}${collaborator.type === Type.SHARE_TYPE_LINK ? '' : ':'}${collaborator.type === Type.SHARE_TYPE_LINK ? '' : collaborator.id}`]: collaborator }
indexCollaborators(collaborators: Record<string, Collaborator>, collaborator: Collaborator) {
return { ...collaborators, [`${collaborator.type}${collaborator.type === ShareType.Link ? '' : ':'}${collaborator.type === ShareType.Link ? '' : collaborator.id}`]: collaborator }

Check warning on line 290 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L289-L290

Added lines #L289 - L290 were not covered by tests
},

async createPublicLinkForAlbum() {
this.selectEntity(`${Type.SHARE_TYPE_LINK}`)
this.selectEntity(`${ShareType.Link}`)

Check warning on line 294 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L294

Added line #L294 was not covered by tests
await this.updateAlbumCollaborators()
await this.fetchCollection(
this.albumFileName,
Expand All @@ -335,11 +300,11 @@
},

async deletePublicLink() {
this.unselectEntity(`${Type.SHARE_TYPE_LINK}`)
this.unselectEntity(`${ShareType.Link}`)

Check warning on line 303 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L303

Added line #L303 was not covered by tests
this.availableCollaborators[3] = {
id: '',
label: t('photos', 'Public link'),
type: Type.SHARE_TYPE_LINK,
label: this.t('photos', 'Public link'),
type: ShareType.Link,

Check warning on line 307 in src/components/Albums/CollaboratorsSelectionForm.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Albums/CollaboratorsSelectionForm.vue#L306-L307

Added lines #L306 - L307 were not covered by tests
}
this.publicLinkCopied = false
await this.updateAlbumCollaborators()
Expand Down
Loading
Loading