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,
labsEnabled: Settings.labs && Settings.labs.enable,
groupSSOEnabled: Settings.groupSSO?.enabled,
wikiEnabled: Settings.overleaf != null || Settings.proxyLearn,
templatesEnabled:
Settings.overleaf != null || Settings.templates?.user_id != null,
}
next()
})

View file

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

View file

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

View file

@ -1,8 +1,19 @@
import { fireEvent, render, screen } from '@testing-library/react'
import WelcomeMessage from '../../../../../frontend/js/features/project-list/components/welcome-message'
import { expect } from 'chai'
import { ExposedSettings } from '../../../../../types/exposed-settings'
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 () {
window.metaAttributesCache = new Map()
})
@ -101,4 +112,48 @@ describe('<WelcomeMessage />', function () {
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
managedUsersEnabled?: boolean
groupSSOEnabled?: boolean
wikiEnabled?: boolean
templatesEnabled?: boolean
}