Merge pull request #11332 from overleaf/td-remove-ace-split-test

Add handling for source-editor-legacy split test

GitOrigin-RevId: 9575087c34bc3f2e8b490846984bc97641c560aa
This commit is contained in:
Tim Down 2023-01-24 14:24:59 +00:00 committed by Copybot
parent c59b28d315
commit a05438d9c7
7 changed files with 31 additions and 58 deletions

View file

@ -981,16 +981,15 @@ const ProjectController = {
}
)
},
newSourceEditorAssignment(cb) {
legacySourceEditorAssignment(cb) {
SplitTestHandler.getAssignment(
req,
res,
'source-editor',
{},
'source-editor-legacy',
(error, assignment) => {
// do not fail editor load if assignment fails
if (error) {
cb(null)
cb(null, { variant: 'default' })
} else {
cb(null, assignment)
}
@ -1159,7 +1158,7 @@ const ProjectController = {
isTokenMember,
isInvitedMember,
brandVariation,
newSourceEditorAssignment,
legacySourceEditorAssignment,
pdfjsAssignment,
editorLeftMenuAssignment,
richTextAssignment,
@ -1239,10 +1238,10 @@ const ProjectController = {
const detachRole = req.params.detachRole
const showNewSourceEditorOption =
newSourceEditorAssignment?.variant === 'codemirror' ||
user.betaProgram ||
shouldDisplayFeature('new_source_editor', false) // also allow override via ?new_source_editor=true
const showLegacySourceEditor =
legacySourceEditorAssignment.variant === 'default' ||
// Also allow override via legacy_source_editor=true in query string
shouldDisplayFeature('legacy_source_editor')
const editorLeftMenuReact =
editorLeftMenuAssignment?.variant === 'react'
@ -1335,7 +1334,7 @@ const ProjectController = {
showSupport: Features.hasFeature('support'),
pdfjsVariant: pdfjsAssignment.variant,
debugPdfDetach,
showNewSourceEditorOption,
showLegacySourceEditor,
showSymbolPalette,
galileoEnabled,
galileoFeatures,

View file

@ -22,7 +22,7 @@ meta(name="ol-useShareJsHash" data-type="boolean" content=true)
meta(name="ol-wsRetryHandshake" data-type="json" content=settings.wsRetryHandshake)
meta(name="ol-pdfjsVariant" content=pdfjsVariant)
meta(name="ol-debugPdfDetach" data-type="boolean" content=debugPdfDetach)
meta(name="ol-showNewSourceEditorOption" data-type="boolean" content=showNewSourceEditorOption)
meta(name="ol-showLegacySourceEditor", data-type="boolean" content=showLegacySourceEditor)
meta(name="ol-showSymbolPalette" data-type="boolean" content=showSymbolPalette)
meta(name="ol-galileoEnabled" data-type="string" content=galileoEnabled)
meta(name="ol-galileoPromptWords" data-type="string" content=galileoPromptWords)

View file

@ -1,7 +1,6 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { Button } from 'react-bootstrap'
import useScopeValue from '../../../shared/hooks/use-scope-value'
import getMeta from '../../../utils/meta'
import {
hasSeenCM6SwitchAwaySurvey,
setHasSeenCM6SwitchAwaySurvey,
@ -17,11 +16,6 @@ export default function CM6SwitchAwaySurvey() {
const initialRichTextPreference = useRef<boolean>(richText)
useEffect(() => {
// If cm6 is not available, don't show the survey
if (!getMeta('ol-showNewSourceEditorOption')) {
return
}
// If the user has previously seen any switch-away survey, then don't show
// the current one
if (hasSeenCM6SwitchAwaySurvey()) return

View file

@ -38,6 +38,8 @@ function Badge() {
)
}
const showLegacySourceEditor: boolean = getMeta('ol-showLegacySourceEditor')
function EditorSwitch() {
const [newSourceEditor, setNewSourceEditor] = useScopeValue(
'editor.newSourceEditor'
@ -103,6 +105,8 @@ function EditorSwitch() {
<span>Source</span>
</label>
{showLegacySourceEditor ? (
<>
<input
type="radio"
name="editor"
@ -115,6 +119,8 @@ function EditorSwitch() {
<label htmlFor="editor-switch-ace" className="toggle-switch-label">
<span>Source (legacy)</span>
</label>
</>
) : null}
<input
type="radio"

View file

@ -4,7 +4,6 @@ import { Nullable } from '../../../../../types/utils'
import customLocalStorage from '../../../infrastructure/local-storage'
import useScopeValue from '../../../shared/hooks/use-scope-value'
import grammarlyExtensionPresent from '../../../shared/utils/grammarly'
import getMeta from '../../../utils/meta'
type GrammarlyWarningProps = {
delay: number
@ -55,10 +54,6 @@ export default function GrammarlyWarning({ delay }: GrammarlyWarningProps) {
customLocalStorage.setItem('editor.has_dismissed_grammarly_warning', true)
}, [])
if (!getMeta('ol-showNewSourceEditorOption')) {
return null
}
if (!show) {
return null
}

View file

@ -195,9 +195,9 @@ export default EditorManager = (function () {
}
newSourceEditor() {
// only use the new source editor if the option to switch is available
if (!getMeta('ol-showNewSourceEditorOption')) {
return false
// Use the new source editor if the legacy editor is disabled
if (!getMeta('ol-showLegacySourceEditor')) {
return true
}
const storedPrefIsCM6 = () => {

View file

@ -27,7 +27,6 @@ describe('<GrammarlyWarning />', function () {
it('shows warning when grammarly is available', async function () {
grammarlyStub.returns(true)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', true)
renderWithEditorContext(<GrammarlyWarning delay={100} />, {
scope: {
@ -46,7 +45,6 @@ describe('<GrammarlyWarning />', function () {
it('does not show warning when grammarly is not available', async function () {
grammarlyStub.returns(false)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', true)
renderWithEditorContext(<GrammarlyWarning delay={100} />, {
scope: {
@ -68,7 +66,6 @@ describe('<GrammarlyWarning />', function () {
it('does not show warning when user has dismissed the warning', async function () {
grammarlyStub.returns(true)
localStorage.setItem('editor.has_dismissed_grammarly_warning', true)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', true)
renderWithEditorContext(<GrammarlyWarning delay={100} />, {
scope: {
@ -87,24 +84,8 @@ describe('<GrammarlyWarning />', function () {
})
})
it('does not show warning when user does not have CM6', async function () {
grammarlyStub.returns(true)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', false)
renderWithEditorContext(<GrammarlyWarning delay={100} />)
await waitFor(() => {
expect(
screen.queryByText(
'A browser extension, for example Grammarly, may be slowing down Overleaf.'
)
).to.not.exist
})
})
it('does not show warning when user have ace as their preference', async function () {
grammarlyStub.returns(true)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', true)
renderWithEditorContext(<GrammarlyWarning delay={100} />, {
scope: {
@ -125,7 +106,6 @@ describe('<GrammarlyWarning />', function () {
it('does not show warning when user have rich text as their preference', async function () {
grammarlyStub.returns(true)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', true)
renderWithEditorContext(<GrammarlyWarning delay={100} />, {
scope: {
@ -147,7 +127,6 @@ describe('<GrammarlyWarning />', function () {
it('hides warning if close button is pressed', async function () {
grammarlyStub.returns(true)
window.metaAttributesCache.set('ol-showNewSourceEditorOption', true)
renderWithEditorContext(<GrammarlyWarning delay={100} />, {
scope: {