From 031ea1428cf177cc4d4cf2424f4a3ac2698c0226 Mon Sep 17 00:00:00 2001 From: cballevre Date: Fri, 25 Oct 2024 09:46:29 +0200 Subject: [PATCH 1/5] feat: Remove drive.show-favorites-dev flag --- src/lib/flags.js | 1 - .../actions/components/addToFavorites.tsx | 5 +---- .../actions/components/removeFromFavorites.tsx | 5 +---- src/modules/navigation/AppRoute.jsx | 16 +++++++--------- src/modules/navigation/Nav.jsx | 5 ++--- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/lib/flags.js b/src/lib/flags.js index 12e2055ebf..94f95d5cea 100644 --- a/src/lib/flags.js +++ b/src/lib/flags.js @@ -28,5 +28,4 @@ const flagsList = () => { flag('drive.breadcrumb.showCompleteBreadcrumbOnPublicPage') // flagName should use kebab case flag('drive.thumbnails-pdf.enabled') flag('drive.show-nextcloud-dev') - flag('drive.show-favorites-dev') } diff --git a/src/modules/actions/components/addToFavorites.tsx b/src/modules/actions/components/addToFavorites.tsx index 61fe56b8e4..6fa51ab4ce 100644 --- a/src/modules/actions/components/addToFavorites.tsx +++ b/src/modules/actions/components/addToFavorites.tsx @@ -2,7 +2,6 @@ import React, { forwardRef } from 'react' import { splitFilename } from 'cozy-client/dist/models/file' import CozyClient from 'cozy-client/types/CozyClient' -import flag from 'cozy-flags' import { Action } from 'cozy-ui/transpiled/react/ActionsMenu/Actions' import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' import Icon from 'cozy-ui/transpiled/react/Icon' @@ -29,9 +28,7 @@ const addToFavorites = ({ label, icon, displayCondition: docs => - docs.length > 0 && - docs.every(doc => !doc.cozyMetadata?.favorite) && - flag('drive.show-favorites-dev'), + docs.length > 0 && docs.every(doc => !doc.cozyMetadata?.favorite), action: async (files): Promise => { try { for (const file of files) { diff --git a/src/modules/actions/components/removeFromFavorites.tsx b/src/modules/actions/components/removeFromFavorites.tsx index 4e7f56e5b0..f5e0f2e1d0 100644 --- a/src/modules/actions/components/removeFromFavorites.tsx +++ b/src/modules/actions/components/removeFromFavorites.tsx @@ -2,7 +2,6 @@ import React, { forwardRef } from 'react' import { splitFilename } from 'cozy-client/dist/models/file' import CozyClient from 'cozy-client/types/CozyClient' -import flag from 'cozy-flags' import { Action } from 'cozy-ui/transpiled/react/ActionsMenu/Actions' import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' import Icon from 'cozy-ui/transpiled/react/Icon' @@ -29,9 +28,7 @@ const removeFromFavorites = ({ label, icon, displayCondition: docs => - docs.length > 0 && - docs.every(doc => doc.cozyMetadata?.favorite) && - flag('drive.show-favorites-dev'), + docs.length > 0 && docs.every(doc => doc.cozyMetadata?.favorite), action: async (files): Promise => { try { for (const file of files) { diff --git a/src/modules/navigation/AppRoute.jsx b/src/modules/navigation/AppRoute.jsx index 1092a6325f..18f198f449 100644 --- a/src/modules/navigation/AppRoute.jsx +++ b/src/modules/navigation/AppRoute.jsx @@ -153,15 +153,13 @@ const AppRoute = () => ( } /> } /> - {flag('drive.show-favorites-dev') ? ( - }> - } /> - } /> - } /> - } /> - } /> - - ) : null} + }> + } /> + } /> + } /> + } /> + } /> + ) diff --git a/src/modules/navigation/Nav.jsx b/src/modules/navigation/Nav.jsx index 73e4f71ce7..9a1f621a92 100644 --- a/src/modules/navigation/Nav.jsx +++ b/src/modules/navigation/Nav.jsx @@ -1,6 +1,5 @@ import React, { useState } from 'react' -import flag from 'cozy-flags' import UINav from 'cozy-ui/transpiled/react/Nav' import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' @@ -21,7 +20,7 @@ export const Nav = () => { rx={/\/(folder|nextcloud|trash)(\/.*)?/} clickState={clickState} /> - {!isDesktop && flag('drive.show-favorites-dev') ? ( + {!isDesktop ? ( { clickState={clickState} /> - {isDesktop && flag('drive.show-favorites-dev') ? ( + {isDesktop ? ( ) : null} From c0696ce34dc328905db1ed50f75c5001ea28b3e6 Mon Sep 17 00:00:00 2001 From: cballevre Date: Fri, 25 Oct 2024 09:53:15 +0200 Subject: [PATCH 2/5] feat(nextcloud): Remove small development flag --- src/modules/navigation/AppRoute.jsx | 16 +++++++--------- .../components/actions/deleteNextcloudFile.tsx | 2 -- .../components/actions/moveNextcloud.jsx | 5 +---- .../components/actions/shareNextcloudFile.jsx | 2 -- src/modules/views/Modal/MoveFilesView.jsx | 7 +++---- .../views/Nextcloud/NextcloudFolderView.jsx | 3 +-- 6 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/modules/navigation/AppRoute.jsx b/src/modules/navigation/AppRoute.jsx index 18f198f449..590912cb5d 100644 --- a/src/modules/navigation/AppRoute.jsx +++ b/src/modules/navigation/AppRoute.jsx @@ -88,15 +88,13 @@ const AppRoute = () => ( } /> } /> - {flag('drive.show-nextcloud-trash-dev') ? ( - } - > - } /> - } /> - - ) : null} + } + > + } /> + } /> + ) : null} diff --git a/src/modules/nextcloud/components/actions/deleteNextcloudFile.tsx b/src/modules/nextcloud/components/actions/deleteNextcloudFile.tsx index 704b30c0e4..1aa1694eb5 100644 --- a/src/modules/nextcloud/components/actions/deleteNextcloudFile.tsx +++ b/src/modules/nextcloud/components/actions/deleteNextcloudFile.tsx @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react' -import flag from 'cozy-flags' import { Action } from 'cozy-ui/transpiled/react/ActionsMenu/Actions' import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' import Icon from 'cozy-ui/transpiled/react/Icon' @@ -48,7 +47,6 @@ export const deleteNextcloudFile = ({ search }) }, - disabled: () => !flag('drive.show-nextcloud-delete-dev'), Component: forwardRef(function DeleteNextcloudFile(props, ref) { return ( diff --git a/src/modules/nextcloud/components/actions/moveNextcloud.jsx b/src/modules/nextcloud/components/actions/moveNextcloud.jsx index c5c2c93899..2de49f7087 100644 --- a/src/modules/nextcloud/components/actions/moveNextcloud.jsx +++ b/src/modules/nextcloud/components/actions/moveNextcloud.jsx @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react' -import flag from 'cozy-flags' import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' import Icon from 'cozy-ui/transpiled/react/Icon' import MovetoIcon from 'cozy-ui/transpiled/react/Icons/Moveto' @@ -27,9 +26,7 @@ const moveNextcloud = ({ t, pathname, navigate, search }) => { search }) }, - disabled: docs => - docs.some(doc => doc.type === 'directory') || - !flag('drive.show-nextcloud-move-dev'), + disabled: docs => docs.some(doc => doc.type === 'directory'), Component: forwardRef(function MoveNextcloud(props, ref) { return ( diff --git a/src/modules/nextcloud/components/actions/shareNextcloudFile.jsx b/src/modules/nextcloud/components/actions/shareNextcloudFile.jsx index 0241a61648..d293c1bc47 100644 --- a/src/modules/nextcloud/components/actions/shareNextcloudFile.jsx +++ b/src/modules/nextcloud/components/actions/shareNextcloudFile.jsx @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react' -import flag from 'cozy-flags' import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' import Icon from 'cozy-ui/transpiled/react/Icon' import LinkOutIcon from 'cozy-ui/transpiled/react/Icons/LinkOut' @@ -20,7 +19,6 @@ const shareNextcloudFile = ({ t }) => { action: docs => { window.open(docs[0].links.self, '_blank') }, - disabled: () => !flag('drive.show-nextcloud-share-dev'), Component: forwardRef(function Share(props, ref) { return ( diff --git a/src/modules/views/Modal/MoveFilesView.jsx b/src/modules/views/Modal/MoveFilesView.jsx index e8c5300246..9dfa4e53ab 100644 --- a/src/modules/views/Modal/MoveFilesView.jsx +++ b/src/modules/views/Modal/MoveFilesView.jsx @@ -2,7 +2,6 @@ import React from 'react' import { Navigate, useLocation, useNavigate } from 'react-router-dom' import { hasQueryBeenLoaded, useQuery } from 'cozy-client' -import flag from 'cozy-flags' import { LoaderModal } from 'components/LoaderModal' import useDisplayedFolder from 'hooks/useDisplayedFolder' @@ -31,9 +30,9 @@ const MoveFilesView = () => { navigate('..', { replace: true }) } - const showNextcloudFolder = - flag('drive.show-nextcloud-move-dev') && - !fileResult.data.some(file => file.type === 'directory') + const showNextcloudFolder = !fileResult.data.some( + file => file.type === 'directory' + ) return ( { }) var queryResults = [nextcloudResult] - if (path === '/' && flag('drive.show-nextcloud-trash-dev')) { + if (path === '/') { queryResults = [ nextcloudResult, { From 0343d399b8745a93fc17ff57d8ef0108546b819d Mon Sep 17 00:00:00 2001 From: cballevre Date: Fri, 25 Oct 2024 10:19:43 +0200 Subject: [PATCH 3/5] feat: Revert flag from drive.show-nextcloud-dev to display it by default --- src/lib/flags.js | 2 +- src/modules/filelist/cells/FileName.jsx | 2 +- src/modules/navigation/AppRoute.jsx | 2 +- src/modules/navigation/hooks/helpers.spec.js | 3 --- src/modules/nextcloud/helpers.ts | 2 +- src/modules/views/Folder/FolderDuplicateView.tsx | 2 +- 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib/flags.js b/src/lib/flags.js index 94f95d5cea..d4bd65f8e7 100644 --- a/src/lib/flags.js +++ b/src/lib/flags.js @@ -27,5 +27,5 @@ const flagsList = () => { flag('drive.dacc-files-size-by-slug') flag('drive.breadcrumb.showCompleteBreadcrumbOnPublicPage') // flagName should use kebab case flag('drive.thumbnails-pdf.enabled') - flag('drive.show-nextcloud-dev') + flag('drive.hide-nextcloud-dev') } diff --git a/src/modules/filelist/cells/FileName.jsx b/src/modules/filelist/cells/FileName.jsx index 021867ba56..b4122d8d7c 100644 --- a/src/modules/filelist/cells/FileName.jsx +++ b/src/modules/filelist/cells/FileName.jsx @@ -112,7 +112,7 @@ const FileName = ({ if ( attributes.cozyMetadata?.createdByApp === 'nextcloud' && - flag('drive.show-nextcloud-dev') + !flag('drive.hide-nextcloud-dev') ) { return { title: filename, diff --git a/src/modules/navigation/AppRoute.jsx b/src/modules/navigation/AppRoute.jsx index 590912cb5d..36e868da98 100644 --- a/src/modules/navigation/AppRoute.jsx +++ b/src/modules/navigation/AppRoute.jsx @@ -78,7 +78,7 @@ const AppRoute = () => ( } /> - {flag('drive.show-nextcloud-dev') ? ( + {!flag('drive.hide-nextcloud-dev') ? ( <> { createdByApp: 'nextcloud' } } - flag.mockReturnValue(true) // mock flag drive.show-nextcloud-dev expect(computeFileType(file)).toBe('nextcloud') }) diff --git a/src/modules/nextcloud/helpers.ts b/src/modules/nextcloud/helpers.ts index 361f79557f..f3703512f6 100644 --- a/src/modules/nextcloud/helpers.ts +++ b/src/modules/nextcloud/helpers.ts @@ -24,7 +24,7 @@ export const isNextcloudShortcut = (file: IOCozyFile): boolean => { return ( isShortcut(file) && file.cozyMetadata?.createdByApp === 'nextcloud' && - flag('drive.show-nextcloud-dev') + !flag('drive.hide-nextcloud-dev') ) } diff --git a/src/modules/views/Folder/FolderDuplicateView.tsx b/src/modules/views/Folder/FolderDuplicateView.tsx index b8c39f3de7..a62b9b336e 100644 --- a/src/modules/views/Folder/FolderDuplicateView.tsx +++ b/src/modules/views/Folder/FolderDuplicateView.tsx @@ -38,7 +38,7 @@ const FolderDuplicateView: FC = () => { return ( Date: Fri, 25 Oct 2024 10:29:36 +0200 Subject: [PATCH 4/5] refactor(FileName): Extract logic to split name into its own function --- src/modules/filelist/cells/FileName.jsx | 40 ++--------------------- src/modules/filelist/helpers.ts | 43 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 src/modules/filelist/helpers.ts diff --git a/src/modules/filelist/cells/FileName.jsx b/src/modules/filelist/cells/FileName.jsx index b4122d8d7c..2375771844 100644 --- a/src/modules/filelist/cells/FileName.jsx +++ b/src/modules/filelist/cells/FileName.jsx @@ -1,12 +1,10 @@ import cx from 'classnames' import get from 'lodash/get' -import { CozyFile } from 'models' -import React, { useCallback, useMemo } from 'react' +import React, { useCallback } from 'react' import { Link } from 'react-router-dom' import { useClient } from 'cozy-client' import { isDirectory } from 'cozy-client/dist/models/file' -import flag from 'cozy-flags' import AppIcon from 'cozy-ui/transpiled/react/AppIcon' import Icon from 'cozy-ui/transpiled/react/Icon' import CarbonCopyIcon from 'cozy-ui/transpiled/react/Icons/CarbonCopy' @@ -14,8 +12,8 @@ import MidEllipsis from 'cozy-ui/transpiled/react/MidEllipsis' import { TableCell } from 'cozy-ui/transpiled/react/deprecated/Table' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' -import { TRASH_DIR_ID } from 'constants/config' import RenameInput from 'modules/drive/RenameInput' +import { getFileNameAndExtension } from 'modules/filelist/helpers' import styles from 'styles/filelist.styl' @@ -93,39 +91,7 @@ const FileName = ({ { [styles['fil-content-row-disabled']]: isInSyncFromSharing } ) - const { title, filename, extension } = useMemo(() => { - const { filename, extension } = CozyFile.splitFilename(attributes) - - if (attributes._id === TRASH_DIR_ID) { - return { - title: t('FileName.trash'), - filename: t('FileName.trash') - } - } - - if (attributes._id === 'io.cozy.files.shared-drives-dir') { - return { - title: t('FileName.sharedDrive'), - filename: t('FileName.sharedDrive') - } - } - - if ( - attributes.cozyMetadata?.createdByApp === 'nextcloud' && - !flag('drive.hide-nextcloud-dev') - ) { - return { - title: filename, - filename: filename - } - } - - return { - title: attributes.name, - filename, - extension - } - }, [attributes, t]) + const { title, filename, extension } = getFileNameAndExtension(attributes, t) return ( diff --git a/src/modules/filelist/helpers.ts b/src/modules/filelist/helpers.ts new file mode 100644 index 0000000000..7bb7ce63df --- /dev/null +++ b/src/modules/filelist/helpers.ts @@ -0,0 +1,43 @@ +import { splitFilename } from 'cozy-client/dist/models/file' + +import type { File } from 'components/FolderPicker/types' +import { TRASH_DIR_ID } from 'constants/config' +import { isNextcloudShortcut } from 'modules/nextcloud/helpers' + +export const getFileNameAndExtension = ( + file: File, + t: (key: string) => string +): { + title: string + filename: string + extension?: string +} => { + const { filename, extension } = splitFilename(file) + + if (file._id === TRASH_DIR_ID) { + return { + title: t('FileName.trash'), + filename: t('FileName.trash') + } + } + + if (file._id === 'io.cozy.files.shared-drives-dir') { + return { + title: t('FileName.sharedDrive'), + filename: t('FileName.sharedDrive') + } + } + + if (file._type === 'io.cozy.files' && isNextcloudShortcut(file)) { + return { + title: filename, + filename: filename + } + } + + return { + title: file.name, + filename, + extension + } +} From 0996b05d1f351f28daf13d6c63e67f0ed139e07a Mon Sep 17 00:00:00 2001 From: cballevre Date: Fri, 25 Oct 2024 10:30:56 +0200 Subject: [PATCH 5/5] fix(FolderPicker): Display correct name for Nextcloud folder --- src/components/FolderPicker/FolderPickerListItem.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/FolderPicker/FolderPickerListItem.tsx b/src/components/FolderPicker/FolderPickerListItem.tsx index 6f62dece4f..1e5df6665c 100644 --- a/src/components/FolderPicker/FolderPickerListItem.tsx +++ b/src/components/FolderPicker/FolderPickerListItem.tsx @@ -10,6 +10,7 @@ import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' import type { File } from 'components/FolderPicker/types' +import { getFileNameAndExtension } from 'modules/filelist/helpers' import FileThumbnail from 'modules/filelist/icons/FileThumbnail' import styles from 'styles/folder-picker.styl' @@ -43,6 +44,8 @@ const FolderPickerListItem: FC = ({ ? `${formattedUpdatedAt}${formattedSize ? ` - ${formattedSize}` : ''}` : undefined + const { title } = getFileNameAndExtension(file, t) + return ( <> = ({ }} /> - + {showDivider && }