Преглед изворни кода

Merge pull request #15844 from overleaf/jpa-download-events

[web] change isMobileDevice segmentation to isSmallDevice

GitOrigin-RevId: 1fcaf6ececc1fa75fd681ef2497bfa5e5567143d
Jakob Ackermann пре 2 година
родитељ
комит
6470afaec3
16 измењених фајлова са 28 додато и 31 уклоњено
  1. 2 2
      services/web/frontend/js/features/editor-left-menu/components/download-pdf.tsx
  2. 2 2
      services/web/frontend/js/features/editor-left-menu/components/download-source.tsx
  3. 2 2
      services/web/frontend/js/features/event-tracking/document-first-change-event.js
  4. 2 2
      services/web/frontend/js/features/pdf-preview/components/pdf-hybrid-download-button.tsx
  5. 2 2
      services/web/frontend/js/features/project-list/components/modals/projects-action-modal.tsx
  6. 2 2
      services/web/frontend/js/features/project-list/components/modals/rename-project-modal.tsx
  7. 2 2
      services/web/frontend/js/features/project-list/components/search-form.tsx
  8. 2 2
      services/web/frontend/js/features/project-list/components/table/cells/action-buttons/copy-project-button.tsx
  9. 2 2
      services/web/frontend/js/features/project-list/components/table/cells/action-buttons/download-project-button.tsx
  10. 2 2
      services/web/frontend/js/features/project-list/components/table/project-tools/buttons/download-projects-button.tsx
  11. 2 2
      services/web/frontend/js/features/project-list/components/table/project-tools/menu-items/copy-project-menu-item.tsx
  12. 1 1
      services/web/frontend/js/infrastructure/event-tracking.js
  13. 0 3
      services/web/test/frontend/bootstrap.js
  14. 3 3
      services/web/test/frontend/features/project-list/components/project-list-root.test.tsx
  15. 1 1
      services/web/test/frontend/features/project-list/components/project-search.test.tsx
  16. 1 1
      services/web/test/frontend/features/project-list/components/table/projects-action-modal.test.tsx

+ 2 - 2
services/web/frontend/js/features/editor-left-menu/components/download-pdf.tsx

@@ -4,7 +4,7 @@ import { useProjectContext } from '../../../shared/context/project-context'
 import Icon from '../../../shared/components/icon'
 import Icon from '../../../shared/components/icon'
 import Tooltip from '../../../shared/components/tooltip'
 import Tooltip from '../../../shared/components/tooltip'
 import * as eventTracking from '../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../infrastructure/event-tracking'
-import { isMobileDevice } from '../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../infrastructure/event-tracking'
 
 
 export default function DownloadPDF() {
 export default function DownloadPDF() {
   const { t } = useTranslation()
   const { t } = useTranslation()
@@ -15,7 +15,7 @@ export default function DownloadPDF() {
     eventTracking.sendMB('download-pdf-button-click', {
     eventTracking.sendMB('download-pdf-button-click', {
       projectId,
       projectId,
       location: 'left-menu',
       location: 'left-menu',
-      isMobileDevice,
+      isSmallDevice,
     })
     })
   }
   }
 
 

+ 2 - 2
services/web/frontend/js/features/editor-left-menu/components/download-source.tsx

@@ -2,7 +2,7 @@ import { useTranslation } from 'react-i18next'
 import { useProjectContext } from '../../../shared/context/project-context'
 import { useProjectContext } from '../../../shared/context/project-context'
 import Icon from '../../../shared/components/icon'
 import Icon from '../../../shared/components/icon'
 import * as eventTracking from '../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../infrastructure/event-tracking'
-import { isMobileDevice } from '../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../infrastructure/event-tracking'
 
 
 export default function DownloadSource() {
 export default function DownloadSource() {
   const { t } = useTranslation()
   const { t } = useTranslation()
@@ -12,7 +12,7 @@ export default function DownloadSource() {
     eventTracking.sendMB('download-zip-button-click', {
     eventTracking.sendMB('download-zip-button-click', {
       projectId,
       projectId,
       location: 'left-menu',
       location: 'left-menu',
-      isMobileDevice,
+      isSmallDevice,
     })
     })
   }
   }
 
 

+ 2 - 2
services/web/frontend/js/features/event-tracking/document-first-change-event.js

@@ -1,4 +1,4 @@
-import { isMobileDevice, sendMB } from '@/infrastructure/event-tracking'
+import { isSmallDevice, sendMB } from '@/infrastructure/event-tracking'
 import getMeta from '@/utils/meta'
 import getMeta from '@/utils/meta'
 
 
 // record once per page load
 // record once per page load
@@ -8,5 +8,5 @@ export function recordDocumentFirstChangeEvent() {
   if (recorded) return
   if (recorded) return
   recorded = true
   recorded = true
   const projectId = getMeta('ol-project_id')
   const projectId = getMeta('ol-project_id')
-  sendMB('document-first-change', { projectId, isMobileDevice })
+  sendMB('document-first-change', { projectId, isSmallDevice })
 }
 }

+ 2 - 2
services/web/frontend/js/features/pdf-preview/components/pdf-hybrid-download-button.tsx

@@ -5,7 +5,7 @@ import Icon from '../../../shared/components/icon'
 import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
 import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
 import { useProjectContext } from '../../../shared/context/project-context'
 import { useProjectContext } from '../../../shared/context/project-context'
 import * as eventTracking from '../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../infrastructure/event-tracking'
-import { isMobileDevice } from '../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../infrastructure/event-tracking'
 
 
 function PdfHybridDownloadButton() {
 function PdfHybridDownloadButton() {
   const { pdfDownloadUrl } = useCompileContext()
   const { pdfDownloadUrl } = useCompileContext()
@@ -21,7 +21,7 @@ function PdfHybridDownloadButton() {
     eventTracking.sendMB('download-pdf-button-click', {
     eventTracking.sendMB('download-pdf-button-click', {
       projectId,
       projectId,
       location: 'pdf-preview',
       location: 'pdf-preview',
-      isMobileDevice,
+      isSmallDevice,
     })
     })
   }
   }
 
 

+ 2 - 2
services/web/frontend/js/features/project-list/components/modals/projects-action-modal.tsx

@@ -6,7 +6,7 @@ import AccessibleModal from '../../../../shared/components/accessible-modal'
 import { getUserFacingMessage } from '../../../../infrastructure/fetch-json'
 import { getUserFacingMessage } from '../../../../infrastructure/fetch-json'
 import useIsMounted from '../../../../shared/hooks/use-is-mounted'
 import useIsMounted from '../../../../shared/hooks/use-is-mounted'
 import * as eventTracking from '../../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../../infrastructure/event-tracking'
-import { isMobileDevice } from '../../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../../infrastructure/event-tracking'
 import getMeta from '@/utils/meta'
 import getMeta from '@/utils/meta'
 import Notification from '@/shared/components/notification'
 import Notification from '@/shared/components/notification'
 
 
@@ -62,7 +62,7 @@ function ProjectsActionModal({
     if (showModal) {
     if (showModal) {
       eventTracking.sendMB('project-list-page-interaction', {
       eventTracking.sendMB('project-list-page-interaction', {
         action,
         action,
-        isMobileDevice,
+        isSmallDevice,
       })
       })
     }
     }
   }, [action, showModal])
   }, [action, showModal])

+ 2 - 2
services/web/frontend/js/features/project-list/components/modals/rename-project-modal.tsx

@@ -16,7 +16,7 @@ import useAsync from '../../../../shared/hooks/use-async'
 import { useProjectListContext } from '../../context/project-list-context'
 import { useProjectListContext } from '../../context/project-list-context'
 import { getUserFacingMessage } from '../../../../infrastructure/fetch-json'
 import { getUserFacingMessage } from '../../../../infrastructure/fetch-json'
 import { debugConsole } from '@/utils/debugging'
 import { debugConsole } from '@/utils/debugging'
-import { isMobileDevice } from '../../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../../infrastructure/event-tracking'
 import Notification from '@/shared/components/notification'
 import Notification from '@/shared/components/notification'
 import getMeta from '@/utils/meta'
 import getMeta from '@/utils/meta'
 
 
@@ -45,7 +45,7 @@ function RenameProjectModal({
       eventTracking.sendMB('project-list-page-interaction', {
       eventTracking.sendMB('project-list-page-interaction', {
         action: 'rename',
         action: 'rename',
         projectId: project.id,
         projectId: project.id,
-        isMobileDevice,
+        isSmallDevice,
       })
       })
     }
     }
   }, [showModal, project.id])
   }, [showModal, project.id])

+ 2 - 2
services/web/frontend/js/features/project-list/components/search-form.tsx

@@ -11,7 +11,7 @@ import * as eventTracking from '../../../infrastructure/event-tracking'
 import classnames from 'classnames'
 import classnames from 'classnames'
 import { Tag } from '../../../../../app/src/Features/Tags/types'
 import { Tag } from '../../../../../app/src/Features/Tags/types'
 import { Filter } from '../context/project-list-context'
 import { Filter } from '../context/project-list-context'
-import { isMobileDevice } from '../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../infrastructure/event-tracking'
 
 
 type SearchFormOwnProps = {
 type SearchFormOwnProps = {
   inputValue: string
   inputValue: string
@@ -67,7 +67,7 @@ function SearchForm({
   ) => {
   ) => {
     eventTracking.sendMB('project-list-page-interaction', {
     eventTracking.sendMB('project-list-page-interaction', {
       action: 'search',
       action: 'search',
-      isMobileDevice,
+      isSmallDevice,
     })
     })
     setInputValue(e.target.value)
     setInputValue(e.target.value)
   }
   }

+ 2 - 2
services/web/frontend/js/features/project-list/components/table/cells/action-buttons/copy-project-button.tsx

@@ -11,7 +11,7 @@ import {
   Project,
   Project,
 } from '../../../../../../../../types/project/dashboard/api'
 } from '../../../../../../../../types/project/dashboard/api'
 import { useProjectTags } from '@/features/project-list/hooks/use-project-tags'
 import { useProjectTags } from '@/features/project-list/hooks/use-project-tags'
-import { isMobileDevice } from '../../../../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../../../../infrastructure/event-tracking'
 
 
 type CopyButtonProps = {
 type CopyButtonProps = {
   project: Project
   project: Project
@@ -45,7 +45,7 @@ function CopyProjectButton({ project, children }: CopyButtonProps) {
       eventTracking.sendMB('project-list-page-interaction', {
       eventTracking.sendMB('project-list-page-interaction', {
         action: 'clone',
         action: 'clone',
         projectId: project.id,
         projectId: project.id,
-        isMobileDevice,
+        isSmallDevice,
       })
       })
       addClonedProjectToViewData(clonedProject)
       addClonedProjectToViewData(clonedProject)
       for (const tag of tags) {
       for (const tag of tags) {

+ 2 - 2
services/web/frontend/js/features/project-list/components/table/cells/action-buttons/download-project-button.tsx

@@ -5,7 +5,7 @@ import Icon from '../../../../../../shared/components/icon'
 import Tooltip from '../../../../../../shared/components/tooltip'
 import Tooltip from '../../../../../../shared/components/tooltip'
 import * as eventTracking from '../../../../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../../../../infrastructure/event-tracking'
 import { useLocation } from '../../../../../../shared/hooks/use-location'
 import { useLocation } from '../../../../../../shared/hooks/use-location'
-import { isMobileDevice } from '../../../../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../../../../infrastructure/event-tracking'
 
 
 type DownloadProjectButtonProps = {
 type DownloadProjectButtonProps = {
   project: Project
   project: Project
@@ -24,7 +24,7 @@ function DownloadProjectButton({
     eventTracking.sendMB('project-list-page-interaction', {
     eventTracking.sendMB('project-list-page-interaction', {
       action: 'downloadZip',
       action: 'downloadZip',
       projectId: project.id,
       projectId: project.id,
-      isMobileDevice,
+      isSmallDevice,
     })
     })
     location.assign(`/project/${project.id}/download/zip`)
     location.assign(`/project/${project.id}/download/zip`)
   }, [project, location])
   }, [project, location])

+ 2 - 2
services/web/frontend/js/features/project-list/components/table/project-tools/buttons/download-projects-button.tsx

@@ -5,7 +5,7 @@ import Tooltip from '../../../../../../shared/components/tooltip'
 import * as eventTracking from '../../../../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../../../../infrastructure/event-tracking'
 import { useProjectListContext } from '../../../../context/project-list-context'
 import { useProjectListContext } from '../../../../context/project-list-context'
 import { useLocation } from '../../../../../../shared/hooks/use-location'
 import { useLocation } from '../../../../../../shared/hooks/use-location'
-import { isMobileDevice } from '../../../../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../../../../infrastructure/event-tracking'
 
 
 function DownloadProjectsButton() {
 function DownloadProjectsButton() {
   const { selectedProjects, selectOrUnselectAllProjects } =
   const { selectedProjects, selectOrUnselectAllProjects } =
@@ -19,7 +19,7 @@ function DownloadProjectsButton() {
   const handleDownloadProjects = useCallback(() => {
   const handleDownloadProjects = useCallback(() => {
     eventTracking.sendMB('project-list-page-interaction', {
     eventTracking.sendMB('project-list-page-interaction', {
       action: 'downloadZips',
       action: 'downloadZips',
-      isMobileDevice,
+      isSmallDevice,
     })
     })
 
 
     location.assign(`/project/download/zip?project_ids=${projectIds.join(',')}`)
     location.assign(`/project/download/zip?project_ids=${projectIds.join(',')}`)

+ 2 - 2
services/web/frontend/js/features/project-list/components/table/project-tools/menu-items/copy-project-menu-item.tsx

@@ -7,7 +7,7 @@ import { useProjectListContext } from '../../../../context/project-list-context'
 import * as eventTracking from '../../../../../../infrastructure/event-tracking'
 import * as eventTracking from '../../../../../../infrastructure/event-tracking'
 import { ClonedProject } from '../../../../../../../../types/project/dashboard/api'
 import { ClonedProject } from '../../../../../../../../types/project/dashboard/api'
 import { useProjectTags } from '@/features/project-list/hooks/use-project-tags'
 import { useProjectTags } from '@/features/project-list/hooks/use-project-tags'
-import { isMobileDevice } from '../../../../../../infrastructure/event-tracking'
+import { isSmallDevice } from '../../../../../../infrastructure/event-tracking'
 
 
 function CopyProjectMenuItem() {
 function CopyProjectMenuItem() {
   const {
   const {
@@ -37,7 +37,7 @@ function CopyProjectMenuItem() {
       eventTracking.sendMB('project-list-page-interaction', {
       eventTracking.sendMB('project-list-page-interaction', {
         action: 'clone',
         action: 'clone',
         projectId: project.id,
         projectId: project.id,
-        isMobileDevice,
+        isSmallDevice,
       })
       })
       addClonedProjectToViewData(clonedProject)
       addClonedProjectToViewData(clonedProject)
       for (const tag of tags) {
       for (const tag of tags) {

+ 1 - 1
services/web/frontend/js/infrastructure/event-tracking.js

@@ -55,7 +55,7 @@ export function sendMBSampled(key, body = {}, rate = 0.01) {
 // @screen-xs-max: (@screen-sm-min - 1);
 // @screen-xs-max: (@screen-sm-min - 1);
 // @screen-sm-min: @screen-sm;
 // @screen-sm-min: @screen-sm;
 // @screen-sm: 768px;
 // @screen-sm: 768px;
-export const isMobileDevice = window.matchMedia('(max-width: 767px)').matches
+export const isSmallDevice = window.screen.width < 768
 
 
 function sendBeacon(key, data) {
 function sendBeacon(key, data) {
   if (!navigator || !navigator.sendBeacon) return
   if (!navigator || !navigator.sendBeacon) return

+ 0 - 3
services/web/test/frontend/bootstrap.js

@@ -120,9 +120,6 @@ globalThis.WebSocket = class WebSocket {
   static CLOSED = 3
   static CLOSED = 3
 }
 }
 
 
-// add stub for window.matchMedia
-window.matchMedia = () => ({ matches: false })
-
 // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
 // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
 const fetch = require('node-fetch')
 const fetch = require('node-fetch')
 globalThis.fetch =
 globalThis.fetch =

+ 3 - 3
services/web/test/frontend/features/project-list/components/project-list-root.test.tsx

@@ -821,7 +821,7 @@ describe('<ProjectListRoot />', function () {
                 action: 'rename',
                 action: 'rename',
                 page: '/',
                 page: '/',
                 projectId: copyableProject.id,
                 projectId: copyableProject.id,
-                isMobileDevice: false,
+                isSmallDevice: true,
               }
               }
             )
             )
 
 
@@ -954,7 +954,7 @@ describe('<ProjectListRoot />', function () {
                 action: 'clone',
                 action: 'clone',
                 page: '/',
                 page: '/',
                 projectId: archiveableProject.id,
                 projectId: archiveableProject.id,
-                isMobileDevice: false,
+                isSmallDevice: true,
               }
               }
             )
             )
 
 
@@ -1113,7 +1113,7 @@ describe('<ProjectListRoot />', function () {
             action: 'clone',
             action: 'clone',
             page: '/',
             page: '/',
             projectId: archiveableProject.id,
             projectId: archiveableProject.id,
-            isMobileDevice: false,
+            isSmallDevice: true,
           }
           }
         )
         )
 
 

+ 1 - 1
services/web/test/frontend/features/project-list/components/project-search.test.tsx

@@ -85,7 +85,7 @@ describe('Project list search form', function () {
     expect(sendMBSpy).to.have.been.calledWith('project-list-page-interaction', {
     expect(sendMBSpy).to.have.been.calledWith('project-list-page-interaction', {
       action: 'search',
       action: 'search',
       page: '/',
       page: '/',
-      isMobileDevice: false,
+      isSmallDevice: true,
     })
     })
     expect(setInputValueMock).to.be.calledWith(value)
     expect(setInputValueMock).to.be.calledWith(value)
   })
   })

+ 1 - 1
services/web/test/frontend/features/project-list/components/table/projects-action-modal.test.tsx

@@ -91,7 +91,7 @@ describe('<ProjectsActionModal />', function () {
     expect(sendMBSpy).to.have.been.calledWith('project-list-page-interaction', {
     expect(sendMBSpy).to.have.been.calledWith('project-list-page-interaction', {
       action: 'archive',
       action: 'archive',
       page: '/',
       page: '/',
-      isMobileDevice: false,
+      isSmallDevice: true,
     })
     })
   })
   })
 })
 })