From 56726053e8cf4e8bebbfd2bb75ab90f924a2865a Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Mon, 16 Jan 2023 09:37:00 -0500 Subject: [PATCH] Merge pull request #11158 from overleaf/em-recompile-pdf-split-test Recompile PDF split test GitOrigin-RevId: b02b3fb5b7a979ac299358e276ed432d736c7a03 --- .../src/Features/Project/ProjectController.js | 25 ++++++++++++++++ .../components/pdf-compile-button-inner.tsx | 30 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index bb78e40868..b5550f646f 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -48,6 +48,10 @@ const ProjectListController = require('./ProjectListController') const ProjectAuditLogHandler = require('./ProjectAuditLogHandler') const PublicAccessLevels = require('../Authorization/PublicAccessLevels') +// We want the recompile-button-text split test to only target users who have +// signed up recently. +const RECOMPILE_BUTTON_SPLIT_TEST_MIN_SIGNUP_DATE = new Date('2023-01-16') + /** * @typedef {import("./types").GetProjectsRequest} GetProjectsRequest * @typedef {import("./types").GetProjectsResponse} GetProjectsResponse @@ -1082,6 +1086,27 @@ const ProjectController = { } ) }, + recompileButtonTextAssignment: [ + 'user', + (results, cb) => { + if ( + results.user.signUpDate < + RECOMPILE_BUTTON_SPLIT_TEST_MIN_SIGNUP_DATE + ) { + return cb() + } + SplitTestHandler.getAssignment( + req, + res, + 'recompile-button-text', + {}, + () => { + // do not fail editor load if assignment fails + cb() + } + ) + }, + ], }, ( err, diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-compile-button-inner.tsx b/services/web/frontend/js/features/pdf-preview/components/pdf-compile-button-inner.tsx index 9c99b0ef19..7cfb0e8c3f 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-compile-button-inner.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-compile-button-inner.tsx @@ -1,8 +1,11 @@ import { Button } from 'react-bootstrap' +import PropTypes from 'prop-types' import Tooltip from '../../../shared/components/tooltip' import Icon from '../../../shared/components/icon' import { useTranslation } from 'react-i18next' -import { memo } from 'react' +import { memo, useCallback } from 'react' +import { useSplitTestContext } from '../../../shared/context/split-test-context' +import * as eventTracking from '../../../infrastructure/event-tracking' const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl' @@ -17,7 +20,28 @@ function PdfCompileButtonInner({ }: PdfCompileButtonInnerProps) { const { t } = useTranslation() - const compileButtonLabel = compiling ? t('compiling') + '…' : t('recompile') + const { splitTestVariants } = useSplitTestContext({ + splitTestVariants: PropTypes.object, + }) + const recompileButtonTextVariant = splitTestVariants['recompile-button-text'] + + let compileButtonLabel + if (compiling) { + compileButtonLabel = t('compiling') + '…' + } else if (splitTestVariants['recompile-button-text'] === 'recompile-pdf') { + compileButtonLabel = t('recompile') + ' PDF' + } else { + compileButtonLabel = t('recompile') + } + + const handleRecompileButtonClick = useCallback(() => { + if (recompileButtonTextVariant != null) { + // Only send the event when the user is targeted by the + // recompile-button-text split test + eventTracking.sendMB('recompile-pdf-clicked') + } + startCompile() + }, [recompileButtonTextVariant, startCompile]) return ( startCompile()} + onClick={handleRecompileButtonClick} aria-label={compileButtonLabel} disabled={compiling} data-ol-loading={compiling}