Skip to content

Commit

Permalink
doc(move): Add type definitions to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Dec 7, 2023
1 parent a7b8831 commit 2019786
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/drive/web/modules/move/helpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
// eslint-disable-next-line no-unused-vars
const { IOCozyFile } = require('cozy-client/dist/types')

import { CozyFile } from 'models'
import logger from 'lib/logger'

/**
* Returns whether one of the targeted folders is part of the current folder
* @param {object[]} targets List of folders
* @param {string} currentDirId The id of the current folder
* @returns {boolean} whether one of the targeted folders is part of the current folder
* @param {IOCozyFile[]} targets - List of folders
* @param {string} currentDirId - The id of the current folder
* @returns {boolean} - Whether one of the targeted folders is part of the current folder
*/
export const areTargetsInCurrentDir = (targets, currentDirId) => {
const targetsInCurrentDir = targets.filter(
Expand All @@ -19,8 +21,8 @@ export const areTargetsInCurrentDir = (targets, currentDirId) => {
/**
* Cancel file movement function
* @param {object} client - The CozyClient instance
* @param {object[]} entries - List of files moved
* @param {string[]} trashedFiles - List of ids for files moved to the trash
* @param {IOCozyFile[]} entries - List of files moved
* @param {IOCozyFile[]} trashedFiles - List of ids for files moved to the trash
* @param {Function} registerCancelable - Function to register the promise
* @param {Functione} refreshSharing - Function refresh sharing state
*/
Expand Down Expand Up @@ -70,9 +72,9 @@ export const cancelMove = async ({

/**
* Gets a name for the entry if there is only one, or a sentence with the number of elements if there are several
* @param {object[]} entries - List of files moved
* @param {Function} t translation function
* @returns {string} name for entries
* @param {IOCozyFile[]} entries - List of files moved
* @param {Function} t - Translation function
* @returns {string} - Name for entries
*/
export const getEntriesName = (entries, t) => {
return entries.length !== 1
Expand All @@ -84,8 +86,8 @@ export const getEntriesName = (entries, t) => {

/**
* Get type from the entries
* @param {object[]} entries
* @returns {string} type from the entries
* @param {IOCozyFile[]} entries - List of files moved
* @returns {string} - Type from the entries
*/
export const getEntriesType = entries => {
return entries.reduce((previous, current) => {
Expand All @@ -101,11 +103,17 @@ export const getEntriesType = entries => {
}, null)
}

/**
* @typedef {Object} SharedDoc
* @property {string[]} permissions - List of permissions
* @property {string[]} sharings - List of sharings
*/

/**
* Returns whether one of the entries that is shared not only by link
* @param {object[]} entries
* @param {object} byDocId
* @returns
* @param {IOCozyFile[]} entries - List of files moved
* @param {Object<string, SharedDoc>} byDocId - Object with shared files by id from cozy-sharing
* @returns {boolean} - Whether one of the entries that is shared not only by link
*/
export const hasOneOfEntriesShared = (entries, byDocId) => {
const sharedEntries = entries.filter(({ _id }) => {
Expand Down

0 comments on commit 2019786

Please sign in to comment.