Files
Rebeka DekanyandCopilot Autofix powered by AI f30c23cacc Update in-product doc links to point to docs.overleaf.com (#35184)
* update doc links to point to docs.overleaf.com instead of the old learn wiki

* fix broken link to LaTeX positioning wiki article in figure modal help

* point figure positioning help link to the docs.overleaf.com page

* point figure/table label help links to specific anchors on the captioning-and-referencing-figures doc page

* point figure modal error-help link to the graphicx-loading doc page

* normalize target/rel on docs.overleaf.com links opened in a new tab

* open figure modal and SSO help links in a new tab now that they point off-site

* add eslint rule enforcing rel=noopener noreferrer on docs.overleaf.com links

* extend require-rel-for-docs-links to also check OLButton

* add lint script catching missing rel on docs.overleaf.com links in pug templates

* fix require-rel-for-docs-links autofix crash on valueless rel attribute

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* add regression test for require-rel-for-docs-links valueless-rel autofix

* revert `target=_blank` on figure modal and SSO help links

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitOrigin-RevId: b6111341e1080fd7e4b42f6a1a18c27ea0fd7d8c
2026-09-17 11:18:47 +00:00

238 lines
5.5 KiB
TypeScript

import { useCallback, useState, ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import OLBadge from '@/shared/components/ol/ol-badge'
import getMeta from '../../../../utils/meta'
import { sendMB } from '../../../../infrastructure/event-tracking'
import OLButton from '@/shared/components/ol/ol-button'
import {
OLModal,
OLModalBody,
OLModalFooter,
OLModalHeader,
OLModalTitle,
} from '@/shared/components/ol/ol-modal'
function trackUpgradeClick(integration: string) {
sendMB('settings-upgrade-click', { integration })
}
function trackLinkingClick(integration: string) {
sendMB('link-integration-click', { integration, location: 'Settings' })
}
type IntegrationLinkingWidgetProps = {
id: string
logo: ReactNode
title: string
description: string
helpPath: string
hasFeature?: boolean
statusIndicator?: ReactNode
linked?: boolean
linkPath: string
unlinkPath: string
unlinkConfirmationTitle: string
unlinkConfirmationText: string
disabled?: boolean
}
export function IntegrationLinkingWidget({
id,
logo,
title,
description,
helpPath,
hasFeature,
statusIndicator,
linked,
linkPath,
unlinkPath,
unlinkConfirmationTitle,
unlinkConfirmationText,
disabled,
}: IntegrationLinkingWidgetProps) {
const { t } = useTranslation()
const [showModal, setShowModal] = useState(false)
const handleUnlinkClick = useCallback(() => {
setShowModal(true)
}, [])
const handleModalHide = useCallback(() => {
setShowModal(false)
}, [])
return (
<div className="settings-widget-container">
<div>{logo}</div>
<div className="description-container">
<div className="title-row">
<h4 id={id}>{title}</h4>
{!hasFeature && <OLBadge bg="info">{t('premium_feature')}</OLBadge>}
</div>
<p className="small">
{description}{' '}
<a href={helpPath} target="_blank" rel="noopener noreferrer">
{t('learn_more_about', { appName: title })}
</a>
</p>
{hasFeature && statusIndicator}
</div>
<div>
<ActionButton
titleId={id}
integration={title}
hasFeature={hasFeature}
linked={linked}
handleUnlinkClick={handleUnlinkClick}
linkPath={linkPath}
disabled={disabled}
/>
</div>
<UnlinkConfirmationModal
integration={title}
show={showModal}
title={unlinkConfirmationTitle}
content={unlinkConfirmationText}
unlinkPath={unlinkPath}
handleHide={handleModalHide}
/>
</div>
)
}
type ActionButtonProps = {
integration: string
hasFeature?: boolean
linked?: boolean
handleUnlinkClick: () => void
linkPath: string
disabled?: boolean
titleId: string
}
function ActionButton({
hasFeature,
linked,
handleUnlinkClick,
linkPath,
disabled,
integration,
titleId,
}: ActionButtonProps) {
const { t } = useTranslation()
const upgradeTextId = `${titleId}-upgrade`
const linkTextId = `${titleId}-link`
const unlinkTextId = `${titleId}-unlink`
if (!hasFeature) {
return (
<OLButton
variant="primary"
href="/user/subscription/plans"
onClick={() => trackUpgradeClick(integration)}
aria-labelledby={`${titleId} ${upgradeTextId}`}
>
<span id={upgradeTextId}>{t('upgrade')}</span>
</OLButton>
)
} else if (linked) {
return (
<OLButton
variant="danger-ghost"
aria-labelledby={`${unlinkTextId} ${titleId}`}
onClick={handleUnlinkClick}
disabled={disabled}
id={unlinkTextId}
>
{t('unlink')}
</OLButton>
)
} else {
return (
<>
{disabled ? (
<OLButton
disabled
variant="secondary"
aria-labelledby={`${linkTextId} ${titleId}`}
id={linkTextId}
>
{t('link')}
</OLButton>
) : (
<OLButton
variant="secondary"
href={linkPath}
onClick={() => trackLinkingClick(integration)}
aria-labelledby={`${linkTextId} ${titleId}`}
id={linkTextId}
>
{t('link')}
</OLButton>
)}
</>
)
}
}
type UnlinkConfirmModalProps = {
show: boolean
title: string
integration: string
content: string
unlinkPath: string
handleHide: () => void
}
function UnlinkConfirmationModal({
show,
title,
integration,
content,
unlinkPath,
handleHide,
}: UnlinkConfirmModalProps) {
const { t } = useTranslation()
const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault()
handleHide()
}
const handleConfirm = () => {
sendMB('unlink-integration-click', {
integration,
})
}
return (
<OLModal show={show} onHide={handleHide}>
<OLModalHeader>
<OLModalTitle>{title}</OLModalTitle>
</OLModalHeader>
<OLModalBody>
<p>{content}</p>
</OLModalBody>
<OLModalFooter>
<form action={unlinkPath} method="POST" className="form-inline">
<input type="hidden" name="_csrf" value={getMeta('ol-csrfToken')} />
<OLButton variant="secondary" onClick={handleCancel}>
{t('cancel')}
</OLButton>
<OLButton
type="submit"
variant="danger-ghost"
onClick={handleConfirm}
>
{t('unlink')}
</OLButton>
</form>
</OLModalFooter>
</OLModal>
)
}