mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Updates to the AI error assistant (#19107)
GitOrigin-RevId: 7ffc1e32d331fa8bab1ea25919e706bf8b59800f
This commit is contained in:
parent
dfaed70297
commit
26d7524c93
9 changed files with 66 additions and 24 deletions
|
@ -617,6 +617,7 @@
|
||||||
"in_order_to_match_institutional_metadata_associated": "",
|
"in_order_to_match_institutional_metadata_associated": "",
|
||||||
"include_caption": "",
|
"include_caption": "",
|
||||||
"include_label": "",
|
"include_label": "",
|
||||||
|
"include_the_error_message_and_ai_response": "",
|
||||||
"increased_compile_timeout": "",
|
"increased_compile_timeout": "",
|
||||||
"inr_discount_modal_info": "",
|
"inr_discount_modal_info": "",
|
||||||
"inr_discount_modal_title": "",
|
"inr_discount_modal_title": "",
|
||||||
|
|
|
@ -42,6 +42,7 @@ interface OpenDocOptions
|
||||||
Partial<GotoOffsetOptions> {
|
Partial<GotoOffsetOptions> {
|
||||||
gotoOffset?: number
|
gotoOffset?: number
|
||||||
forceReopen?: boolean
|
forceReopen?: boolean
|
||||||
|
keepCurrentView?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EditorManager = {
|
export type EditorManager = {
|
||||||
|
@ -431,7 +432,10 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
||||||
// store position of previous doc before switching docs
|
// store position of previous doc before switching docs
|
||||||
eventEmitter.emit('store-doc-position')
|
eventEmitter.emit('store-doc-position')
|
||||||
}
|
}
|
||||||
setView('editor')
|
|
||||||
|
if (!options.keepCurrentView) {
|
||||||
|
setView('editor')
|
||||||
|
}
|
||||||
|
|
||||||
const done = (isNewDoc: boolean) => {
|
const done = (isNewDoc: boolean) => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
|
|
|
@ -73,7 +73,7 @@ export const FileTreeOpenProvider: FC = ({ children }) => {
|
||||||
|
|
||||||
setOpenEntity(selected)
|
setOpenEntity(selected)
|
||||||
if (selected.type === 'doc' && fileTreeReady) {
|
if (selected.type === 'doc' && fileTreeReady) {
|
||||||
openDocWithId(selected.entity._id)
|
openDocWithId(selected.entity._id, { keepCurrentView: true })
|
||||||
if (selected.entity.name.endsWith('.bib')) {
|
if (selected.entity.name.endsWith('.bib')) {
|
||||||
sendMB('open-bib-file', {
|
sendMB('open-bib-file', {
|
||||||
projectOwner: owner._id,
|
projectOwner: owner._id,
|
||||||
|
|
|
@ -48,31 +48,12 @@ function PdfLogEntry({
|
||||||
[level, onSourceLocationClick, ruleId, sourceLocation]
|
[level, onSourceLocationClick, ruleId, sourceLocation]
|
||||||
)
|
)
|
||||||
|
|
||||||
const logEntryRef = useCallback(
|
|
||||||
element => {
|
|
||||||
if (element) {
|
|
||||||
window.addEventListener('editor:view-compile-log-entry', event => {
|
|
||||||
if (event.detail.id === id) {
|
|
||||||
element.scrollIntoView({ block: 'start', inline: 'nearest' })
|
|
||||||
|
|
||||||
if (event.detail.suggestFix) {
|
|
||||||
element
|
|
||||||
.querySelector('button[data-action="suggest-fix"]')
|
|
||||||
?.click()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[id]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames('log-entry', customClass)}
|
className={classNames('log-entry', customClass)}
|
||||||
aria-label={entryAriaLabel}
|
aria-label={entryAriaLabel}
|
||||||
data-ruleid={ruleId}
|
data-ruleid={ruleId}
|
||||||
ref={logEntryRef}
|
data-log-entry-id={id}
|
||||||
>
|
>
|
||||||
<PreviewLogEntryHeader
|
<PreviewLogEntryHeader
|
||||||
level={level}
|
level={level}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hook adds an event listener for events dispatched from the editor to the compile logs pane
|
||||||
|
*/
|
||||||
|
export const useLogEvents = (setShowLogs: (show: boolean) => void) => {
|
||||||
|
const { pdfLayout, setView } = useLayoutContext()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const listener = (event: Event) => {
|
||||||
|
const { id, suggestFix } = (
|
||||||
|
event as CustomEvent<{ id: string; suggestFix?: boolean }>
|
||||||
|
).detail
|
||||||
|
|
||||||
|
setShowLogs(true)
|
||||||
|
|
||||||
|
if (pdfLayout === 'flat') {
|
||||||
|
setView('pdf')
|
||||||
|
}
|
||||||
|
|
||||||
|
window.setTimeout(() => {
|
||||||
|
const element = document.querySelector(
|
||||||
|
`.log-entry[data-log-entry-id="${id}"]`
|
||||||
|
)
|
||||||
|
|
||||||
|
if (element) {
|
||||||
|
element.scrollIntoView({
|
||||||
|
block: 'start',
|
||||||
|
inline: 'nearest',
|
||||||
|
})
|
||||||
|
|
||||||
|
if (suggestFix) {
|
||||||
|
element
|
||||||
|
.querySelector<HTMLButtonElement>(
|
||||||
|
'button[data-action="suggest-fix"]'
|
||||||
|
)
|
||||||
|
?.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('editor:view-compile-log-entry', listener)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('editor:view-compile-log-entry', listener)
|
||||||
|
}
|
||||||
|
}, [pdfLayout, setView, setShowLogs])
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import { CompileContext, useLocalCompileContext } from './local-compile-context'
|
||||||
import useDetachStateWatcher from '../hooks/use-detach-state-watcher'
|
import useDetachStateWatcher from '../hooks/use-detach-state-watcher'
|
||||||
import useDetachAction from '../hooks/use-detach-action'
|
import useDetachAction from '../hooks/use-detach-action'
|
||||||
import useCompileTriggers from '../../features/pdf-preview/hooks/use-compile-triggers'
|
import useCompileTriggers from '../../features/pdf-preview/hooks/use-compile-triggers'
|
||||||
|
import { useLogEvents } from '@/features/pdf-preview/hooks/use-log-events'
|
||||||
|
|
||||||
export const DetachCompileContext = createContext<CompileContext | undefined>(
|
export const DetachCompileContext = createContext<CompileContext | undefined>(
|
||||||
undefined
|
undefined
|
||||||
|
@ -363,6 +364,7 @@ export const DetachCompileProvider: FC = ({ children }) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
useCompileTriggers(startCompile, setChangedAt)
|
useCompileTriggers(startCompile, setChangedAt)
|
||||||
|
useLogEvents(setShowLogs)
|
||||||
|
|
||||||
const value = useMemo(
|
const value = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
|
|
@ -96,7 +96,7 @@ export type CompileContext = {
|
||||||
stopCompile: () => void
|
stopCompile: () => void
|
||||||
setChangedAt: (value: any) => void
|
setChangedAt: (value: any) => void
|
||||||
clearCache: () => void
|
clearCache: () => void
|
||||||
syncToEntry: (value: any) => void
|
syncToEntry: (value: any, keepCurrentView?: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LocalCompileContext = createContext<CompileContext | undefined>(
|
export const LocalCompileContext = createContext<CompileContext | undefined>(
|
||||||
|
@ -573,13 +573,14 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
}, [compiler])
|
}, [compiler])
|
||||||
|
|
||||||
const syncToEntry = useCallback(
|
const syncToEntry = useCallback(
|
||||||
entry => {
|
(entry, keepCurrentView = false) => {
|
||||||
const result = findEntityByPath(entry.file)
|
const result = findEntityByPath(entry.file)
|
||||||
|
|
||||||
if (result && result.type === 'doc') {
|
if (result && result.type === 'doc') {
|
||||||
openDocId(result.entity._id, {
|
openDocId(result.entity._id, {
|
||||||
gotoLine: entry.line ?? undefined,
|
gotoLine: entry.line ?? undefined,
|
||||||
gotoColumn: entry.column ?? undefined,
|
gotoColumn: entry.column ?? undefined,
|
||||||
|
keepCurrentView,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -888,6 +888,7 @@
|
||||||
"in_order_to_match_institutional_metadata_associated": "In order to match your institutional metadata, your account is associated with the email <b>__email__</b>.",
|
"in_order_to_match_institutional_metadata_associated": "In order to match your institutional metadata, your account is associated with the email <b>__email__</b>.",
|
||||||
"include_caption": "Include caption",
|
"include_caption": "Include caption",
|
||||||
"include_label": "Include label",
|
"include_label": "Include label",
|
||||||
|
"include_the_error_message_and_ai_response": "Include the error message and AI response",
|
||||||
"increased_compile_timeout": "Increased compile timeout",
|
"increased_compile_timeout": "Increased compile timeout",
|
||||||
"individuals": "Individuals",
|
"individuals": "Individuals",
|
||||||
"indvidual_plans": "Individual Plans",
|
"indvidual_plans": "Individual Plans",
|
||||||
|
|
|
@ -92,6 +92,7 @@ describe('<PdfLogsEntries/>', function () {
|
||||||
{
|
{
|
||||||
gotoLine: 9,
|
gotoLine: 9,
|
||||||
gotoColumn: 8,
|
gotoColumn: 8,
|
||||||
|
keepCurrentView: false,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -130,6 +131,7 @@ describe('<PdfLogsEntries/>', function () {
|
||||||
{
|
{
|
||||||
gotoLine: 7,
|
gotoLine: 7,
|
||||||
gotoColumn: 6,
|
gotoColumn: 6,
|
||||||
|
keepCurrentView: false,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue