From 6d122534dc875f8b5ff245bab533b5a8b31c1a97 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Wed, 6 Sep 2023 15:05:17 +0100 Subject: [PATCH] Merge pull request #14656 from overleaf/mj-table-generator-analytics [visual] Add analytics to table generator GitOrigin-RevId: ab5e9c9a870b76d2d51c74190f386b1de5153bb1 --- .../components/table-generator/analytics.ts | 6 ++ .../toolbar/toolbar-button.tsx | 4 +- .../toolbar/toolbar-dropdown.tsx | 28 +++++- .../table-generator/toolbar/toolbar.tsx | 92 ++++++++----------- .../toolbar/table-inserter-dropdown.tsx | 2 + 5 files changed, 75 insertions(+), 57 deletions(-) create mode 100644 services/web/frontend/js/features/source-editor/components/table-generator/analytics.ts diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/analytics.ts b/services/web/frontend/js/features/source-editor/components/table-generator/analytics.ts new file mode 100644 index 0000000000..b085f968b6 --- /dev/null +++ b/services/web/frontend/js/features/source-editor/components/table-generator/analytics.ts @@ -0,0 +1,6 @@ +import { EditorView } from '@codemirror/view' +import { emitCommandEvent } from '../../extensions/toolbar/utils/analytics' + +export function emitTableGeneratorEvent(view: EditorView, command: string) { + emitCommandEvent(view, 'codemirror-table-generator-event', command) +} diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-button.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-button.tsx index c5d2ee2bfa..6873be66b0 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-button.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-button.tsx @@ -4,6 +4,7 @@ import { memo, useCallback } from 'react' import Tooltip from '../../../../../shared/components/tooltip' import MaterialIcon from '../../../../../shared/components/material-icon' import { useCodeMirrorViewContext } from '../../codemirror-editor' +import { emitTableGeneratorEvent } from '../analytics' export const ToolbarButton = memo<{ id: string @@ -34,11 +35,12 @@ export const ToolbarButton = memo<{ const handleClick = useCallback( event => { if (command) { + emitTableGeneratorEvent(view, id) event.preventDefault() command(view) } }, - [command, view] + [command, view, id] ) const button = ( diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-dropdown.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-dropdown.tsx index 7219016cbd..c33c72e14b 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-dropdown.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar-dropdown.tsx @@ -1,9 +1,11 @@ -import { FC, useRef } from 'react' +import { ButtonHTMLAttributes, FC, useCallback, useRef } from 'react' import useDropdown from '../../../../../shared/hooks/use-dropdown' import { Overlay, Popover } from 'react-bootstrap' import MaterialIcon from '../../../../../shared/components/material-icon' import Tooltip from '../../../../../shared/components/tooltip' import { useTabularContext } from '../contexts/tabular-context' +import { emitTableGeneratorEvent } from '../analytics' +import { useCodeMirrorViewContext } from '../../codemirror-editor' export const ToolbarDropdown: FC<{ id: string @@ -102,3 +104,27 @@ export const ToolbarDropdown: FC<{ ) } + +export const ToolbarDropdownItem: FC< + Omit, 'onClick'> & { + command: () => void + id: string + } +> = ({ children, command, id, ...props }) => { + const view = useCodeMirrorViewContext() + const onClick = useCallback(() => { + emitTableGeneratorEvent(view, id) + command() + }, [view, command, id]) + return ( + + ) +} diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx index bdeded5dbd..446dbb8fd8 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/toolbar/toolbar.tsx @@ -2,7 +2,7 @@ import { memo, useMemo } from 'react' import { useSelectionContext } from '../contexts/selection-context' import { ToolbarButton } from './toolbar-button' import { ToolbarButtonMenu } from './toolbar-button-menu' -import { ToolbarDropdown } from './toolbar-dropdown' +import { ToolbarDropdown, ToolbarDropdownItem } from './toolbar-dropdown' import MaterialIcon from '../../../../../shared/components/material-icon' import { BorderTheme, @@ -68,46 +68,38 @@ export const Toolbar = memo(function Toolbar() { label={captionLabel} disabled={!tableEnvironment} > - - - + - - +
@@ -231,11 +221,9 @@ export const Toolbar = memo(function Toolbar() { tooltip="Insert" disabled={!selection} > - - +
- - +
diff --git a/services/web/frontend/js/features/source-editor/components/toolbar/table-inserter-dropdown.tsx b/services/web/frontend/js/features/source-editor/components/toolbar/table-inserter-dropdown.tsx index 3ab5b3c0c6..1a6e8f7812 100644 --- a/services/web/frontend/js/features/source-editor/components/toolbar/table-inserter-dropdown.tsx +++ b/services/web/frontend/js/features/source-editor/components/toolbar/table-inserter-dropdown.tsx @@ -7,6 +7,7 @@ import { useCodeMirrorViewContext } from '../codemirror-editor' import Tooltip from '../../../../shared/components/tooltip' import MaterialIcon from '../../../../shared/components/material-icon' import classNames from 'classnames' +import { emitToolbarEvent } from '../../extensions/toolbar/utils/analytics' export const TableInserterDropdown: FC = () => { const { t } = useTranslation() @@ -18,6 +19,7 @@ export const TableInserterDropdown: FC = () => { (sizeX: number, sizeY: number) => { onToggle(false) commands.insertTable(view, sizeX, sizeY) + emitToolbarEvent(view, 'table-generator-insert-table') view.focus() }, [view, onToggle]