overleaf/services/web/frontend/js/features/preview/components/preview-logs-pane-max-entries.jsx
Antoine Clausse 30860ae9f9 [web] Migrate PDF Logs to BS5 (#21062)
* [web] Migrate Logs components JSX to Bootstrap 5

* [web] Migrate logs.less to logs.scss

* [web] Remove unused class names

* [storybook] Define default Bootstrap version in Storybook

This prevents some warning in the console

* [storybook] Update pdf-preview.stories.jsx

* [storybook] Add pdf-log-entry.stories.tsx

* [storybook] Force re-renders when switching BS version

* [web] Keep files dropdown menu in bounds

* [web] Make files dropdown items not bold in BS5

* [web] Revert unrelated change

* [web] Fixup PreviewLogsPaneMaxEntries

* [web] Add style for log-entry-content-link

* [web] Replace log-entry by OLNotification in `PdfCodeCheckFailedNotice`

* [web] Use `BootstrapVersionSwitcher` instead of `isBootstrap5`

* [web] Rename `DropdownBS3` to `BS3Dropdown`

* [web] Reuse variables for `toolbar-height` and `toolbar-small-height`

* [web] Set `id` on `DropdownToggle` not `Dropdown`

* [web] Set `log-entry-btn-expand-collapse` in BS3 only

* [web] Remove `block: true` from StartFreeTrialButton in BS3

* [web] Remove unnecessary CSS in `.log-entry-header-link`

* [web] Use semantic color names

* Migrate the downloadable pdf file list to Bootstrap 5

* Remove nested BootstrapVersionSwitcher, fix "key" prop

* Update roles to: `<li role="menuitem">` `<a role="link">`

* Update `log-entry-header-link`: variant ghost and fix colors

---------

Co-authored-by: Rebeka <o.dekany@gmail.com>
GitOrigin-RevId: 89848970ab5d8a8c135335386caf24363f69a34c
2024-10-23 08:06:32 +00:00

90 lines
3.4 KiB
JavaScript

import { useCallback } from 'react'
import PropTypes from 'prop-types'
import { Trans, useTranslation } from 'react-i18next'
import OLButton from '@/features/ui/components/ol/ol-button'
import PreviewLogEntryHeader from './preview-log-entry-header'
import Icon from '../../../shared/components/icon'
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
import MaterialIcon from '@/shared/components/material-icon'
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
function PreviewLogsPaneMaxEntries({ totalEntries, entriesShown, hasErrors }) {
const { t } = useTranslation()
const { startCompile, stoppedOnFirstError, setAnimateCompileDropdownArrow } =
useCompileContext()
const { enableStopOnFirstError } = useStopOnFirstError({
eventSource: 'too-many-logs',
})
const title = t('log_entry_maximum_entries_title', {
total: totalEntries,
displayed: entriesShown,
})
const handleEnableStopOnFirstErrorClick = useCallback(() => {
enableStopOnFirstError()
startCompile({ stopOnFirstError: true })
setAnimateCompileDropdownArrow(true)
}, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
return (
<div className="log-entry" aria-label={t('log_entry_maximum_entries')}>
<PreviewLogEntryHeader level="raw" headerTitle={title} />
<div className="log-entry-content">
<div className="log-entry-formatted-content">
{hasErrors && !stoppedOnFirstError ? (
<>
<p>
<BootstrapVersionSwitcher
bs3={<Icon type="lightbulb-o" />}
bs5={
<MaterialIcon type="lightbulb" className="align-middle" />
}
/>
&nbsp;
<strong>{t('tip')}: </strong>
<Trans
i18nKey="log_entry_maximum_entries_enable_stop_on_first_error"
components={[
<OLButton
variant="info"
size="sm"
key="enable-stop-on-first-error"
bs3Props={{ bsSize: 'xsmall' }}
onClick={handleEnableStopOnFirstErrorClick}
/>,
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
key="learn-more"
href="https://www.overleaf.com/learn/latex/Questions/Tips_and_Tricks_for_Troubleshooting_LaTeX"
/>,
]}
/>{' '}
</p>
<p>{t('log_entry_maximum_entries_see_full_logs')}</p>
</>
) : (
<p>
<BootstrapVersionSwitcher
bs3={<Icon type="lightbulb-o" />}
bs5={<MaterialIcon type="lightbulb" className="align-middle" />}
/>
&nbsp;
<strong>{t('tip')}: </strong>
{t('log_entry_maximum_entries_see_full_logs')}
</p>
)}
</div>
</div>
</div>
)
}
PreviewLogsPaneMaxEntries.propTypes = {
totalEntries: PropTypes.number,
entriesShown: PropTypes.number,
hasErrors: PropTypes.bool,
}
export default PreviewLogsPaneMaxEntries