From 19a1a0ffdae78fc012413eeab4e0879137bf50c0 Mon Sep 17 00:00:00 2001 From: cballevre Date: Mon, 18 Dec 2023 12:51:30 +0100 Subject: [PATCH 01/18] refactor: Extract lib/doctypes out of drive --- src/folder-references/index.js | 2 +- src/lib/doctypes.js | 32 +++++++++++++++++++++++++ src/photos/components/Topbar.jsx | 2 +- src/photos/ducks/albums/index.jsx | 2 +- src/photos/ducks/clustering/albums.js | 2 +- src/photos/ducks/clustering/files.js | 2 +- src/photos/ducks/clustering/settings.js | 2 +- src/photos/ducks/clustering/utils.js | 2 +- src/photos/lib/onPhotoTrashed.js | 2 +- src/photos/queries/queries.js | 2 +- src/photos/targets/browser/doctypes.js | 2 +- src/photos/targets/browser/index.jsx | 2 +- 12 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/lib/doctypes.js diff --git a/src/folder-references/index.js b/src/folder-references/index.js index f75ccc04b..7a8bb5512 100644 --- a/src/folder-references/index.js +++ b/src/folder-references/index.js @@ -1,4 +1,4 @@ -import { DOCTYPE_APPS, DOCTYPE_FILES } from 'drive/lib/doctypes' +import { DOCTYPE_APPS, DOCTYPE_FILES } from 'lib/doctypes' export const REF_PHOTOS = `${DOCTYPE_APPS}/photos` export const REF_UPLOAD = `${DOCTYPE_APPS}/photos/upload` diff --git a/src/lib/doctypes.js b/src/lib/doctypes.js new file mode 100644 index 000000000..c977f87b8 --- /dev/null +++ b/src/lib/doctypes.js @@ -0,0 +1,32 @@ +import { Contact, Group } from 'models' + +export const DOCTYPE_FILES = 'io.cozy.files' +export const DOCTYPE_FILES_SETTINGS = 'io.cozy.files.settings' +export const DOCTYPE_FILES_ENCRYPTION = 'io.cozy.files.encryption' +export const DOCTYPE_FILES_SHORTCUT = 'io.cozy.files.shortcuts' +export const DOCTYPE_ALBUMS = 'io.cozy.photos.albums' +export const DOCTYPE_PHOTOS_SETTINGS = 'io.cozy.photos.settings' +export const DOCTYPE_APPS = 'io.cozy.apps' +export const DOCTYPE_CONTACTS_VERSION = 2 + +export const schema = { + files: { + doctype: DOCTYPE_FILES, + relationships: { + old_versions: { + type: 'has-many', + doctype: 'io.cozy.files.versions' + }, + encryption: { + type: 'io.cozy.files:has-many', + doctype: DOCTYPE_FILES_ENCRYPTION + } + } + }, + contacts: { + doctype: Contact.doctype, + doctypeVersion: DOCTYPE_CONTACTS_VERSION + }, + groups: { doctype: Group.doctype }, + versions: { doctype: 'io.cozy.files.versions' } +} diff --git a/src/photos/components/Topbar.jsx b/src/photos/components/Topbar.jsx index 8a3875d9f..c3f6cbc18 100644 --- a/src/photos/components/Topbar.jsx +++ b/src/photos/components/Topbar.jsx @@ -7,7 +7,7 @@ import { withClient } from 'cozy-client' import PropTypes from 'prop-types' import flow from 'lodash/flow' import SharingProvider from 'cozy-sharing' -import { DOCTYPE_ALBUMS } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS } from 'lib/doctypes' import { useNavigate, useLocation } from 'react-router-dom' import { BarCenter, BarRight, BarLeft } from 'components/Bar' diff --git a/src/photos/ducks/albums/index.jsx b/src/photos/ducks/albums/index.jsx index f6ccfffd0..c193eef94 100644 --- a/src/photos/ducks/albums/index.jsx +++ b/src/photos/ducks/albums/index.jsx @@ -10,7 +10,7 @@ import AddToAlbumModal from './components/AddToAlbumModal' import Loading from '../../components/Loading' import Oops from 'photos/components/Error/Oops' -import { DOCTYPE_ALBUMS } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS } from 'lib/doctypes' import { useParams } from 'react-router-dom' import { buildAlbumsQuery } from '../../queries/queries' diff --git a/src/photos/ducks/clustering/albums.js b/src/photos/ducks/clustering/albums.js index 0d4d6bbf8..5b606bba5 100644 --- a/src/photos/ducks/clustering/albums.js +++ b/src/photos/ducks/clustering/albums.js @@ -1,5 +1,5 @@ import log from 'cozy-logger' -import { DOCTYPE_ALBUMS } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS } from 'lib/doctypes' import uniq from 'lodash/uniq' import { Q } from 'cozy-client' diff --git a/src/photos/ducks/clustering/files.js b/src/photos/ducks/clustering/files.js index 22c479587..2adbd86fd 100644 --- a/src/photos/ducks/clustering/files.js +++ b/src/photos/ducks/clustering/files.js @@ -1,5 +1,5 @@ import log from 'cozy-logger' -import { DOCTYPE_FILES, DOCTYPE_ALBUMS } from 'drive/lib/doctypes' +import { DOCTYPE_FILES, DOCTYPE_ALBUMS } from 'lib/doctypes' import { Q } from 'cozy-client' export const getFilesFromDate = async (client, date, { limit = 0 } = {}) => { diff --git a/src/photos/ducks/clustering/settings.js b/src/photos/ducks/clustering/settings.js index 3657ede2a..213f7d407 100644 --- a/src/photos/ducks/clustering/settings.js +++ b/src/photos/ducks/clustering/settings.js @@ -1,6 +1,6 @@ import log from 'cozy-logger' import { Q } from 'cozy-client' -import { DOCTYPE_PHOTOS_SETTINGS } from 'drive/lib/doctypes' +import { DOCTYPE_PHOTOS_SETTINGS } from 'lib/doctypes' import { SETTING_TYPE, DEFAULT_SETTING, diff --git a/src/photos/ducks/clustering/utils.js b/src/photos/ducks/clustering/utils.js index 2cbfc95e1..90a21d8c2 100644 --- a/src/photos/ducks/clustering/utils.js +++ b/src/photos/ducks/clustering/utils.js @@ -1,4 +1,4 @@ -import { DOCTYPE_ALBUMS } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS } from 'lib/doctypes' import { DAY_DURATION_IN_MS } from './consts' import get from 'lodash/get' import log from 'cozy-logger' diff --git a/src/photos/lib/onPhotoTrashed.js b/src/photos/lib/onPhotoTrashed.js index ecf73ceac..5e4a5627d 100644 --- a/src/photos/lib/onPhotoTrashed.js +++ b/src/photos/lib/onPhotoTrashed.js @@ -3,7 +3,7 @@ import log from 'cozy-logger' import pLimit from 'p-limit' import { buildPhotosTrashedWithReferencedBy } from 'photos/queries/queries' -import { DOCTYPE_ALBUMS, DOCTYPE_FILES } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS, DOCTYPE_FILES } from 'lib/doctypes' const onPhotoTrashed = async client => { const photosTrashedQuery = buildPhotosTrashedWithReferencedBy() diff --git a/src/photos/queries/queries.js b/src/photos/queries/queries.js index 0ebf9615c..bac2554b2 100644 --- a/src/photos/queries/queries.js +++ b/src/photos/queries/queries.js @@ -1,6 +1,6 @@ import { Q, fetchPolicies } from 'cozy-client' -import { DOCTYPE_ALBUMS, DOCTYPE_FILES } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS, DOCTYPE_FILES } from 'lib/doctypes' const older30s = 30 * 1000 diff --git a/src/photos/targets/browser/doctypes.js b/src/photos/targets/browser/doctypes.js index f2673b250..8065c5a8b 100644 --- a/src/photos/targets/browser/doctypes.js +++ b/src/photos/targets/browser/doctypes.js @@ -1,4 +1,4 @@ -import { DOCTYPE_ALBUMS, DOCTYPE_FILES } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS, DOCTYPE_FILES } from 'lib/doctypes' import { Contact } from 'cozy-doctypes' import { QueryDefinition, HasMany } from 'cozy-client' diff --git a/src/photos/targets/browser/index.jsx b/src/photos/targets/browser/index.jsx index dca709e0a..d4b813b58 100755 --- a/src/photos/targets/browser/index.jsx +++ b/src/photos/targets/browser/index.jsx @@ -18,7 +18,7 @@ import { I18n } from 'cozy-ui/transpiled/react/providers/I18n' import SharingProvider from 'cozy-sharing' import { WebviewIntentProvider } from 'cozy-intent' -import { DOCTYPE_ALBUMS } from 'drive/lib/doctypes' +import { DOCTYPE_ALBUMS } from 'lib/doctypes' import PushBannerProvider from 'components/PushBanner/PushBannerProvider' import appReducers from 'photos/reducers' From ec2a6c5530de6647ecf1f87cc4dcd76ed8569014 Mon Sep 17 00:00:00 2001 From: cballevre Date: Mon, 18 Dec 2023 12:28:14 +0100 Subject: [PATCH 02/18] refactor: Extract QuotaAlert out of drive --- src/components/QuotaAlert.jsx | 8 ++++++++ src/photos/ducks/upload/index.jsx | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/components/QuotaAlert.jsx diff --git a/src/components/QuotaAlert.jsx b/src/components/QuotaAlert.jsx new file mode 100644 index 000000000..904f9703c --- /dev/null +++ b/src/components/QuotaAlert.jsx @@ -0,0 +1,8 @@ +import React from 'react' +import { default as UIQuotaAlert } from 'cozy-ui/transpiled/react/deprecated/QuotaAlert' + +const QuotaAlert = ({ onClose }) => { + return +} + +export default QuotaAlert diff --git a/src/photos/ducks/upload/index.jsx b/src/photos/ducks/upload/index.jsx index a1ad11227..f6060941d 100644 --- a/src/photos/ducks/upload/index.jsx +++ b/src/photos/ducks/upload/index.jsx @@ -6,7 +6,7 @@ import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter' import UploadQueue from './UploadQueue' import { showModal } from 'react-cozy-helpers' -import QuotaAlert from 'drive/web/modules/upload/QuotaAlert' +import QuotaAlert from 'components/QuotaAlert' export { UploadQueue } From 0440e7824fb80d6730a452e3b509cbe33341eb23 Mon Sep 17 00:00:00 2001 From: cballevre Date: Mon, 18 Dec 2023 12:52:15 +0100 Subject: [PATCH 03/18] refactor: Extract lib/reporter out of drive --- src/lib/reporter.js | 74 ++++++++++++++++++++++++++++ src/photos/targets/browser/index.jsx | 2 +- src/photos/targets/public/index.jsx | 2 +- 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/lib/reporter.js diff --git a/src/lib/reporter.js b/src/lib/reporter.js new file mode 100644 index 000000000..c9818febe --- /dev/null +++ b/src/lib/reporter.js @@ -0,0 +1,74 @@ +/* global __SENTRY_URL__, __DEVELOPMENT__ */ +import Raven from 'raven-js' +import appMetadata from 'photos/appMetadata' +import logger from 'lib/logger' + +export const ANALYTICS_URL = + typeof __SENTRY_URL__ === 'undefined' ? '' : __SENTRY_URL__ + +// normalize files path on mobile, see https://github.com/getsentry/sentry-cordova/blob/17e8b3395e8ce391ecf28658d0487b97487bb509/src/js/SentryCordova.ts#L213 +const normalizeUrl = (url, pathStripRe) => + url.replace(/^file:\/\//, 'app://').replace(pathStripRe, '') + +export const normalizeData = data => { + const PATH_STRIP_RE = /^.*\/[^.]+(\.app|CodePush|.*(?=\/))/ + + if (data.culprit) { + data.culprit = normalizeUrl(data.culprit, PATH_STRIP_RE) + } + const stacktrace = + data.stacktrace || + (data.exception && + data.exception.values && + data.exception.values[0] && + data.exception.values[0].stacktrace) + + if (stacktrace) { + stacktrace.frames = stacktrace.frames.map(frame => + frame.filename !== '[native code]' + ? { ...frame, filename: normalizeUrl(frame.filename, PATH_STRIP_RE) } + : frame + ) + } + return data +} + +export const getReporterConfiguration = () => ({ + shouldSendCallback: true, + environment: __DEVELOPMENT__ ? 'development' : 'production', + release: appMetadata.version, + allowSecretKey: true, + dataCallback: normalizeData +}) + +export const configureReporter = () => { + Raven.config(ANALYTICS_URL, getReporterConfiguration()).install() +} + +export const logException = (err, extraContext = null, fingerprint = null) => { + return new Promise(resolve => { + Raven.captureException(err, { extra: extraContext, fingerprint }) + logger.warn('Raven is recording exception') + logger.error(err) + resolve() + }) +} + +export const setCozyUrl = instance => { + Raven.setTagsContext({ instance }) +} + +const logMessage = (message, serverUrl, level = 'info') => { + return new Promise(resolve => { + Raven.setUserContext = { + url: serverUrl + } + Raven.captureMessage(`[${serverUrl}] ${message}`, { + level + }) + resolve() + }) +} + +export const logInfo = (message, serverUrl) => + logMessage(message, serverUrl, 'info') diff --git a/src/photos/targets/browser/index.jsx b/src/photos/targets/browser/index.jsx index d4b813b58..ecdab2107 100755 --- a/src/photos/targets/browser/index.jsx +++ b/src/photos/targets/browser/index.jsx @@ -26,7 +26,7 @@ import AppRouter from 'photos/components/AppRouter' import StyledApp from 'photos/components/StyledApp' import memoize from 'lodash/memoize' -import { configureReporter, setCozyUrl } from 'drive/lib/reporter' +import { configureReporter, setCozyUrl } from 'lib/reporter' import appMetadata from 'photos/appMetadata' import doctypes from './doctypes' import cozyBar from 'lib/cozyBar' diff --git a/src/photos/targets/public/index.jsx b/src/photos/targets/public/index.jsx index 46fa4b88f..9f88ca0f7 100644 --- a/src/photos/targets/public/index.jsx +++ b/src/photos/targets/public/index.jsx @@ -26,7 +26,7 @@ import App from './App' import { AlbumPhotosViewer } from 'photos/components/PhotosViewer' import StyledApp from 'photos/components/StyledApp' -import { configureReporter, setCozyUrl } from 'drive/lib/reporter' +import { configureReporter, setCozyUrl } from 'lib/reporter' import { WebviewIntentProvider } from 'cozy-intent' import cozyBar from 'lib/cozyBar' From ffbec9e9762ed03dc7c32f14bd45e74421809b2a Mon Sep 17 00:00:00 2001 From: cballevre Date: Mon, 18 Dec 2023 12:43:46 +0100 Subject: [PATCH 04/18] refactor: Extract config out of drive --- src/components/pushClient/Banner.jsx | 2 +- src/components/pushClient/Button.jsx | 2 +- src/config/config.json | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/config/config.json diff --git a/src/components/pushClient/Banner.jsx b/src/components/pushClient/Banner.jsx index 8a202c479..4f24395bb 100644 --- a/src/components/pushClient/Banner.jsx +++ b/src/components/pushClient/Banner.jsx @@ -21,7 +21,7 @@ import { isClientAlreadyInstalled, DESKTOP_BANNER } from '.' -import Config from 'drive/config/config.json' +import Config from 'config/config.json' import styles from './pushClient.styl' class BannerClient extends Component { diff --git a/src/components/pushClient/Button.jsx b/src/components/pushClient/Button.jsx index f784c582b..b03f7671c 100644 --- a/src/components/pushClient/Button.jsx +++ b/src/components/pushClient/Button.jsx @@ -7,7 +7,7 @@ import { default as UIButtonClient } from 'cozy-ui/transpiled/react/deprecated/P import { isFlagshipApp } from 'cozy-device-helper' import { isLinux, isClientAlreadyInstalled, DESKTOP_BANNER } from '.' -import Config from 'drive/config/config.json' +import Config from 'config/config.json' class ButtonClient extends Component { state = { diff --git a/src/config/config.json b/src/config/config.json new file mode 100644 index 000000000..65ecc4254 --- /dev/null +++ b/src/config/config.json @@ -0,0 +1,5 @@ +{ + "promoteDesktop": { + "isActivated": true + } +} From 067bad91f7cca49d1f075898ce7adeba6db59830 Mon Sep 17 00:00:00 2001 From: cballevre Date: Mon, 18 Dec 2023 13:01:45 +0100 Subject: [PATCH 05/18] refactor: Use constants from photos instead drive --- src/components/Button/CozyHomeLink.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Button/CozyHomeLink.jsx b/src/components/Button/CozyHomeLink.jsx index cbff61205..fb10da075 100644 --- a/src/components/Button/CozyHomeLink.jsx +++ b/src/components/Button/CozyHomeLink.jsx @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import { ButtonLink, useI18n } from 'cozy-ui/transpiled/react' -import { HOME_LINK_HREF } from 'drive/constants/config' +import { HOME_LINK_HREF } from 'photos/constants/config' import CozyHomeLinkIcon from 'components/Button/CozyHomeLinkIcon' const CozyHomeLink = ({ className }) => { From a973dc9dba560841f92b4eff5320bd84212aad38 Mon Sep 17 00:00:00 2001 From: cballevre Date: Mon, 18 Dec 2023 12:39:34 +0100 Subject: [PATCH 06/18] refactor: Remove components related to Drive into shared folder --- src/components/App/App.jsx | 45 ------- src/components/Error/Empty.jsx | 19 +-- src/components/Error/Oops.jsx | 35 ------ src/components/Error/oops.styl | 5 - src/components/FileHistory/HistoryModal.jsx | 117 ------------------ src/components/FileHistory/index.jsx | 50 -------- src/components/FileHistory/styles.styl | 3 - .../PushBanner/QuotaBanner.spec.jsx | 2 +- src/components/useDocument.jsx | 15 --- src/components/useHead.jsx | 16 --- 10 files changed, 2 insertions(+), 305 deletions(-) delete mode 100644 src/components/App/App.jsx delete mode 100644 src/components/Error/Oops.jsx delete mode 100644 src/components/Error/oops.styl delete mode 100644 src/components/FileHistory/HistoryModal.jsx delete mode 100644 src/components/FileHistory/index.jsx delete mode 100644 src/components/FileHistory/styles.styl delete mode 100644 src/components/useDocument.jsx delete mode 100644 src/components/useHead.jsx diff --git a/src/components/App/App.jsx b/src/components/App/App.jsx deleted file mode 100644 index 09467894a..000000000 --- a/src/components/App/App.jsx +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react' -import { Provider } from 'react-redux' -import PropTypes from 'prop-types' - -import { WebviewIntentProvider } from 'cozy-intent' - -import DriveProvider from 'drive/lib/DriveProvider' -import { ThumbnailSizeContextProvider } from 'drive/lib/ThumbnailSizeContext' -import { ModalContextProvider } from 'drive/lib/ModalContext' -import { AcceptingSharingProvider } from 'drive/lib/AcceptingSharingContext' -import PushBannerProvider from 'components/PushBanner/PushBannerProvider' -import cozyBar from 'lib/cozyBar' -import { onFileUploaded } from 'drive/web/modules/views/Upload/UploadUtils' - -const App = ({ store, client, lang, polyglot, children }) => { - return ( - - onFileUploaded({ file, isSuccess }, store.dispatch) - }} - > - - - - - - {children} - - - - - - - ) -} - -App.propTypes = { - store: PropTypes.object, - lang: PropTypes.string, - polyglot: PropTypes.object, - client: PropTypes.object -} -export default App diff --git a/src/components/Error/Empty.jsx b/src/components/Error/Empty.jsx index f9c57c6d5..bcbf0dd4d 100644 --- a/src/components/Error/Empty.jsx +++ b/src/components/Error/Empty.jsx @@ -3,19 +3,13 @@ import cx from 'classnames' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' import Empty from 'cozy-ui/transpiled/react/Empty' -import DriveIcon from 'cozy-ui/transpiled/react/Icons/FileTypeFolder' -import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash' import PhotosIcon from 'cozy-ui/transpiled/react/Icons/FileTypeImage' -import EncryptedFolderIcon from 'drive/web/modules/views/Folder/EncryptedFolderIcon' import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' import styles from './empty.styl' const EmptyIcon = { - drive: DriveIcon, - encrypted: EncryptedFolderIcon, - photos: PhotosIcon, - trash: TrashIcon + photos: PhotosIcon } const EmptyCanvas = ({ type, canUpload, localeKey, hasTextMobileVersion }) => { @@ -40,15 +34,4 @@ const EmptyCanvas = ({ type, canUpload, localeKey, hasTextMobileVersion }) => { export default EmptyCanvas -export const EmptyDrive = props => { - const { isEncrypted } = props - if (isEncrypted) { - return - } - return -} export const EmptyPhotos = props => - -export const EmptyTrash = props => ( - -) diff --git a/src/components/Error/Oops.jsx b/src/components/Error/Oops.jsx deleted file mode 100644 index 460c9ee82..000000000 --- a/src/components/Error/Oops.jsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' - -import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' -import Empty from 'cozy-ui/transpiled/react/Empty' -import Button from 'cozy-ui/transpiled/react/deprecated/Button' - -import EmptyIcon from '../../drive/assets/icons/icon-folder-broken.svg' - -import styles from './oops.styl' - -const reload = () => { - window.location.reload() -} - -const Oops = ({ title, icon }) => { - const { t } = useI18n() - - return ( - -