|
@@ -1,4 +1,4 @@
|
|
|
-import { useState } from 'react'
|
|
|
|
|
|
|
+import { useCallback, useState } from 'react'
|
|
|
import { Dropdown, MenuItem } from 'react-bootstrap'
|
|
import { Dropdown, MenuItem } from 'react-bootstrap'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import { ExposedSettings } from '../../../../../types/exposed-settings'
|
|
import { ExposedSettings } from '../../../../../types/exposed-settings'
|
|
@@ -9,17 +9,35 @@ import NewProjectButtonModal, {
|
|
|
NewProjectButtonModalVariant,
|
|
NewProjectButtonModalVariant,
|
|
|
} from './new-project-button/new-project-button-modal'
|
|
} from './new-project-button/new-project-button-modal'
|
|
|
import { Nullable } from '../../../../../types/utils'
|
|
import { Nullable } from '../../../../../types/utils'
|
|
|
|
|
+import { sendMB } from '../../../infrastructure/event-tracking'
|
|
|
|
|
+
|
|
|
|
|
+type SendTrackingEvent = {
|
|
|
|
|
+ dropdownMenu: string
|
|
|
|
|
+ dropdownOpen: boolean
|
|
|
|
|
+ institutionTemplateName?: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type Segmentation = SendTrackingEvent & {
|
|
|
|
|
+ 'project-dashboard-react': 'enabled'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type ModalMenuClickOptions = {
|
|
|
|
|
+ modalVariant: NewProjectButtonModalVariant
|
|
|
|
|
+ dropdownMenuEvent: string
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
type NewProjectButtonProps = {
|
|
type NewProjectButtonProps = {
|
|
|
id: string
|
|
id: string
|
|
|
buttonText?: string
|
|
buttonText?: string
|
|
|
className?: string
|
|
className?: string
|
|
|
|
|
+ trackingKey?: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function NewProjectButton({
|
|
function NewProjectButton({
|
|
|
id,
|
|
id,
|
|
|
buttonText,
|
|
buttonText,
|
|
|
className,
|
|
className,
|
|
|
|
|
+ trackingKey,
|
|
|
}: NewProjectButtonProps) {
|
|
}: NewProjectButtonProps) {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
const { templateLinks } = getMeta('ol-ExposedSettings') as ExposedSettings
|
|
const { templateLinks } = getMeta('ol-ExposedSettings') as ExposedSettings
|
|
@@ -27,9 +45,100 @@ function NewProjectButton({
|
|
|
useState<Nullable<NewProjectButtonModalVariant>>(null)
|
|
useState<Nullable<NewProjectButtonModalVariant>>(null)
|
|
|
const portalTemplates = getMeta('ol-portalTemplates') as PortalTemplate[]
|
|
const portalTemplates = getMeta('ol-portalTemplates') as PortalTemplate[]
|
|
|
|
|
|
|
|
|
|
+ const sendTrackingEvent = useCallback(
|
|
|
|
|
+ ({
|
|
|
|
|
+ dropdownMenu,
|
|
|
|
|
+ dropdownOpen,
|
|
|
|
|
+ institutionTemplateName,
|
|
|
|
|
+ }: SendTrackingEvent) => {
|
|
|
|
|
+ if (trackingKey) {
|
|
|
|
|
+ let segmentation: Segmentation = {
|
|
|
|
|
+ 'project-dashboard-react': 'enabled',
|
|
|
|
|
+ dropdownMenu,
|
|
|
|
|
+ dropdownOpen,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (institutionTemplateName) {
|
|
|
|
|
+ segmentation = {
|
|
|
|
|
+ ...segmentation,
|
|
|
|
|
+ institutionTemplateName,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sendMB(trackingKey, segmentation)
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ [trackingKey]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const handleMainButtonClick = useCallback(
|
|
|
|
|
+ (dropdownOpen: boolean) => {
|
|
|
|
|
+ sendTrackingEvent({
|
|
|
|
|
+ dropdownMenu: 'main-button',
|
|
|
|
|
+ dropdownOpen,
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ [sendTrackingEvent]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const handleModalMenuClick = useCallback(
|
|
|
|
|
+ (
|
|
|
|
|
+ e: React.MouseEvent<Record<string, unknown>>,
|
|
|
|
|
+ { modalVariant, dropdownMenuEvent }: ModalMenuClickOptions
|
|
|
|
|
+ ) => {
|
|
|
|
|
+ // avoid invoking the "onClick" callback on the main dropdown button
|
|
|
|
|
+ e.stopPropagation()
|
|
|
|
|
+
|
|
|
|
|
+ sendTrackingEvent({
|
|
|
|
|
+ dropdownMenu: dropdownMenuEvent,
|
|
|
|
|
+ dropdownOpen: true,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ setModal(modalVariant)
|
|
|
|
|
+ },
|
|
|
|
|
+ [sendTrackingEvent]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const handlePortalTemplateClick = useCallback(
|
|
|
|
|
+ (
|
|
|
|
|
+ e: React.MouseEvent<Record<string, unknown>>,
|
|
|
|
|
+ institutionTemplateName: string
|
|
|
|
|
+ ) => {
|
|
|
|
|
+ // avoid invoking the "onClick" callback on the main dropdown button
|
|
|
|
|
+ e.stopPropagation()
|
|
|
|
|
+
|
|
|
|
|
+ sendTrackingEvent({
|
|
|
|
|
+ dropdownMenu: 'institution-template',
|
|
|
|
|
+ dropdownOpen: true,
|
|
|
|
|
+ institutionTemplateName,
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ [sendTrackingEvent]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const handleStaticTemplateClick = useCallback(
|
|
|
|
|
+ (
|
|
|
|
|
+ e: React.MouseEvent<Record<string, unknown>>,
|
|
|
|
|
+ templateTrackingKey: string
|
|
|
|
|
+ ) => {
|
|
|
|
|
+ // avoid invoking the "onClick" callback on the main dropdown button
|
|
|
|
|
+ e.stopPropagation()
|
|
|
|
|
+
|
|
|
|
|
+ sendTrackingEvent({
|
|
|
|
|
+ dropdownMenu: templateTrackingKey,
|
|
|
|
|
+ dropdownOpen: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ [sendTrackingEvent]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
- <ControlledDropdown id={id} className={className}>
|
|
|
|
|
|
|
+ <ControlledDropdown
|
|
|
|
|
+ id={id}
|
|
|
|
|
+ className={className}
|
|
|
|
|
+ onMainButtonClick={handleMainButtonClick}
|
|
|
|
|
+ >
|
|
|
<Dropdown.Toggle
|
|
<Dropdown.Toggle
|
|
|
noCaret
|
|
noCaret
|
|
|
className="new-project-button"
|
|
className="new-project-button"
|
|
@@ -38,16 +147,44 @@ function NewProjectButton({
|
|
|
{buttonText || t('new_project')}
|
|
{buttonText || t('new_project')}
|
|
|
</Dropdown.Toggle>
|
|
</Dropdown.Toggle>
|
|
|
<Dropdown.Menu>
|
|
<Dropdown.Menu>
|
|
|
- <MenuItem onClick={() => setModal('blank_project')}>
|
|
|
|
|
|
|
+ <MenuItem
|
|
|
|
|
+ onClick={e =>
|
|
|
|
|
+ handleModalMenuClick(e, {
|
|
|
|
|
+ modalVariant: 'blank_project',
|
|
|
|
|
+ dropdownMenuEvent: 'blank-project',
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
{t('blank_project')}
|
|
{t('blank_project')}
|
|
|
</MenuItem>
|
|
</MenuItem>
|
|
|
- <MenuItem onClick={() => setModal('example_project')}>
|
|
|
|
|
|
|
+ <MenuItem
|
|
|
|
|
+ onClick={e =>
|
|
|
|
|
+ handleModalMenuClick(e, {
|
|
|
|
|
+ modalVariant: 'example_project',
|
|
|
|
|
+ dropdownMenuEvent: 'example-project',
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
{t('example_project')}
|
|
{t('example_project')}
|
|
|
</MenuItem>
|
|
</MenuItem>
|
|
|
- <MenuItem onClick={() => setModal('upload_project')}>
|
|
|
|
|
|
|
+ <MenuItem
|
|
|
|
|
+ onClick={e =>
|
|
|
|
|
+ handleModalMenuClick(e, {
|
|
|
|
|
+ modalVariant: 'upload_project',
|
|
|
|
|
+ dropdownMenuEvent: 'upload-project',
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
{t('upload_project')}
|
|
{t('upload_project')}
|
|
|
</MenuItem>
|
|
</MenuItem>
|
|
|
- <MenuItem onClick={() => setModal('import_from_github')}>
|
|
|
|
|
|
|
+ <MenuItem
|
|
|
|
|
+ onClick={e =>
|
|
|
|
|
+ handleModalMenuClick(e, {
|
|
|
|
|
+ modalVariant: 'import_from_github',
|
|
|
|
|
+ dropdownMenuEvent: 'import-from-github',
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
{t('import_from_github')}
|
|
{t('import_from_github')}
|
|
|
</MenuItem>
|
|
</MenuItem>
|
|
|
{portalTemplates?.length > 0 ? (
|
|
{portalTemplates?.length > 0 ? (
|
|
@@ -60,6 +197,9 @@ function NewProjectButton({
|
|
|
<MenuItem
|
|
<MenuItem
|
|
|
key={`portal-template-${index}`}
|
|
key={`portal-template-${index}`}
|
|
|
href={`${portalTemplate.url}#templates`}
|
|
href={`${portalTemplate.url}#templates`}
|
|
|
|
|
+ onClick={e =>
|
|
|
|
|
+ handlePortalTemplateClick(e, portalTemplate.name)
|
|
|
|
|
+ }
|
|
|
>
|
|
>
|
|
|
{portalTemplate.name}
|
|
{portalTemplate.name}
|
|
|
</MenuItem>
|
|
</MenuItem>
|
|
@@ -72,6 +212,9 @@ function NewProjectButton({
|
|
|
<MenuItem
|
|
<MenuItem
|
|
|
key={`new-project-button-template-${index}`}
|
|
key={`new-project-button-template-${index}`}
|
|
|
href={templateLink.url}
|
|
href={templateLink.url}
|
|
|
|
|
+ onClick={e =>
|
|
|
|
|
+ handleStaticTemplateClick(e, templateLink.trackingKey)
|
|
|
|
|
+ }
|
|
|
>
|
|
>
|
|
|
{templateLink.name === 'view_all'
|
|
{templateLink.name === 'view_all'
|
|
|
? t('view_all')
|
|
? t('view_all')
|