Merge pull request #17450 from overleaf/msm-fix-sp-welcome-page

[web] Make wiki and template links configurable in welcome page

GitOrigin-RevId: fab1b8a11f518c5907a5bfa9365ff8e8a130b7c6
This commit is contained in:
Miguel Serrano 2024-03-07 17:26:14 +01:00 committed by Copybot
parent 058b40ae70
commit cf227e2d08
5 changed files with 97 additions and 22 deletions

View file

@ -413,6 +413,9 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) {
templateLinks: Settings.templateLinks, templateLinks: Settings.templateLinks,
labsEnabled: Settings.labs && Settings.labs.enable, labsEnabled: Settings.labs && Settings.labs.enable,
groupSSOEnabled: Settings.groupSSO?.enabled, groupSSOEnabled: Settings.groupSSO?.enabled,
wikiEnabled: Settings.overleaf != null || Settings.proxyLearn,
templatesEnabled:
Settings.overleaf != null || Settings.templates?.user_id != null,
} }
next() next()
}) })

View file

@ -4,6 +4,7 @@ import type { PortalTemplate } from '../../../../../../types/portal-template'
import { sendMB } from '../../../../infrastructure/event-tracking' import { sendMB } from '../../../../infrastructure/event-tracking'
import getMeta from '../../../../utils/meta' import getMeta from '../../../../utils/meta'
import { NewProjectButtonModalVariant } from '../new-project-button/new-project-button-modal' import { NewProjectButtonModalVariant } from '../new-project-button/new-project-button-modal'
import { ExposedSettings } from '../../../../../../types/exposed-settings'
type WelcomeMessageCreateNewProjectDropdownProps = { type WelcomeMessageCreateNewProjectDropdownProps = {
setActiveModal: (modal: NewProjectButtonModalVariant) => void setActiveModal: (modal: NewProjectButtonModalVariant) => void
@ -18,6 +19,8 @@ function WelcomeMessageCreateNewProjectDropdown({
| PortalTemplate[] | PortalTemplate[]
| undefined | undefined
const { isOverleaf } = getMeta('ol-ExposedSettings') as ExposedSettings
const handleClick = useCallback(() => { const handleClick = useCallback(() => {
sendMB('welcome-page-create-first-project-click', { sendMB('welcome-page-create-first-project-click', {
dropdownMenu: 'main-button', dropdownMenu: 'main-button',
@ -119,6 +122,7 @@ function WelcomeMessageCreateNewProjectDropdown({
> >
{t('upload_project')} {t('upload_project')}
</button> </button>
{isOverleaf && (
<button <button
onClick={e => onClick={e =>
handleDropdownItemClick( handleDropdownItemClick(
@ -130,6 +134,7 @@ function WelcomeMessageCreateNewProjectDropdown({
> >
{t('import_from_github')} {t('import_from_github')}
</button> </button>
)}
{(portalTemplates?.length ?? 0) > 0 ? ( {(portalTemplates?.length ?? 0) > 0 ? (
<> <>
<hr /> <hr />

View file

@ -5,12 +5,18 @@ import type { NewProjectButtonModalVariant } from './new-project-button/new-proj
import type { Nullable } from '../../../../../types/utils' import type { Nullable } from '../../../../../types/utils'
import WelcomeMessageLink from './welcome-message-new/welcome-message-link' import WelcomeMessageLink from './welcome-message-new/welcome-message-link'
import WelcomeMessageCreateNewProjectDropdown from './welcome-message-new/welcome-message-create-new-project-dropdown' import WelcomeMessageCreateNewProjectDropdown from './welcome-message-new/welcome-message-create-new-project-dropdown'
import getMeta from '@/utils/meta'
import { ExposedSettings } from '../../../../../types/exposed-settings'
export default function WelcomeMessage() { export default function WelcomeMessage() {
const { t } = useTranslation() const { t } = useTranslation()
const [activeModal, setActiveModal] = const [activeModal, setActiveModal] =
useState<Nullable<NewProjectButtonModalVariant>>(null) useState<Nullable<NewProjectButtonModalVariant>>(null)
const { wikiEnabled, templatesEnabled } = getMeta(
'ol-ExposedSettings'
) as ExposedSettings
return ( return (
<> <>
<div className="card welcome-new-wrapper"> <div className="card welcome-new-wrapper">
@ -20,17 +26,21 @@ export default function WelcomeMessage() {
<WelcomeMessageCreateNewProjectDropdown <WelcomeMessageCreateNewProjectDropdown
setActiveModal={modal => setActiveModal(modal)} setActiveModal={modal => setActiveModal(modal)}
/> />
{wikiEnabled && (
<WelcomeMessageLink <WelcomeMessageLink
imgSrc="/img/welcome-page/learn-latex.svg" imgSrc="/img/welcome-page/learn-latex.svg"
title="Learn LaTeX with a tutorial" title="Learn LaTeX with a tutorial"
href="/learn/latex/Learn_LaTeX_in_30_minutes" href="/learn/latex/Learn_LaTeX_in_30_minutes"
target="_blank" target="_blank"
/> />
)}
{templatesEnabled && (
<WelcomeMessageLink <WelcomeMessageLink
imgSrc="/img/welcome-page/browse-templates.svg" imgSrc="/img/welcome-page/browse-templates.svg"
title="Browse templates" title="Browse templates"
href="/templates" href="/templates"
/> />
)}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,8 +1,19 @@
import { fireEvent, render, screen } from '@testing-library/react' import { fireEvent, render, screen } from '@testing-library/react'
import WelcomeMessage from '../../../../../frontend/js/features/project-list/components/welcome-message' import WelcomeMessage from '../../../../../frontend/js/features/project-list/components/welcome-message'
import { expect } from 'chai' import { expect } from 'chai'
import { ExposedSettings } from '../../../../../types/exposed-settings'
describe('<WelcomeMessage />', function () { describe('<WelcomeMessage />', function () {
const exposedSettings: Partial<ExposedSettings> = {}
beforeEach(function () {
window.metaAttributesCache = new Map()
window.metaAttributesCache.set('ol-ExposedSettings', exposedSettings)
exposedSettings.isOverleaf = true
exposedSettings.wikiEnabled = true
exposedSettings.templatesEnabled = true
})
afterEach(function () { afterEach(function () {
window.metaAttributesCache = new Map() window.metaAttributesCache = new Map()
}) })
@ -101,4 +112,48 @@ describe('<WelcomeMessage />', function () {
expect(link.getAttribute('href')).to.equal('/templates') expect(link.getAttribute('href')).to.equal('/templates')
}) })
describe('when not in SaaS', function () {
beforeEach(function () {
exposedSettings.isOverleaf = false
})
it('renders welcome page correctly', function () {
render(<WelcomeMessage />)
screen.getByText('Welcome to Overleaf')
screen.getByText('Create a new project')
screen.getByText('Learn LaTeX with a tutorial')
screen.getByText('Browse templates')
})
it("doesn't display github in the dropdown when clicking create a new project", function () {
render(<WelcomeMessage />)
const button = screen.getByRole('button', {
name: 'Create a new project',
})
fireEvent.click(button)
screen.getByText('Blank Project')
screen.getByText('Example Project')
screen.getByText('Upload Project')
expect(screen.queryByText('Import from GitHub')).to.not.exist
})
it('does not render the tutorial link when the learn wiki is not configured', function () {
exposedSettings.wikiEnabled = false
render(<WelcomeMessage />)
expect(screen.queryByText('Learn LaTeX with a tutorial')).to.not.exist
})
it('does not render the templates link when templates are not configured', function () {
exposedSettings.templatesEnabled = false
render(<WelcomeMessage />)
expect(screen.queryByText('Browse templates')).to.not.exist
})
})
}) })

View file

@ -47,4 +47,6 @@ export type ExposedSettings = {
labsEnabled: boolean labsEnabled: boolean
managedUsersEnabled?: boolean managedUsersEnabled?: boolean
groupSSOEnabled?: boolean groupSSOEnabled?: boolean
wikiEnabled?: boolean
templatesEnabled?: boolean
} }