mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
[ide-react] Address some migration TODOs (#16033)
* Add type for externalUpdate * Log clientTracking.getConnectedUsers error * Remove update debugging code * Use ErrorMetadata type * Use Message type * Remove unused document:opened event GitOrigin-RevId: 3a1d1e785dca37d6b91cd650fbcb4e5decb6343b
This commit is contained in:
@@ -11,6 +11,8 @@ export interface Meta {
|
|||||||
users: Nullable<User>[]
|
users: Nullable<User>[]
|
||||||
start_ts: number
|
start_ts: number
|
||||||
end_ts: number
|
end_ts: number
|
||||||
|
type?: 'external' // TODO
|
||||||
|
source?: 'git-bridge' // TODO
|
||||||
origin?: {
|
origin?: {
|
||||||
kind:
|
kind:
|
||||||
| 'dropbox'
|
| 'dropbox'
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { debugConsole } from '@/utils/debugging'
|
|||||||
import { Document } from '@/features/ide-react/editor/document'
|
import { Document } from '@/features/ide-react/editor/document'
|
||||||
import { useLayoutContext } from '@/shared/context/layout-context'
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
||||||
import { GotoLineOptions } from '@/features/ide-react/types/goto-line-options'
|
import { GotoLineOptions } from '@/features/ide-react/types/goto-line-options'
|
||||||
import _ from 'lodash'
|
|
||||||
import { Doc } from '../../../../../types/doc'
|
import { Doc } from '../../../../../types/doc'
|
||||||
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
||||||
import { findDocEntityById } from '@/features/ide-react/util/find-doc-entity-by-id'
|
import { findDocEntityById } from '@/features/ide-react/util/find-doc-entity-by-id'
|
||||||
@@ -30,6 +29,7 @@ import customLocalStorage from '@/infrastructure/local-storage'
|
|||||||
import useEventListener from '@/shared/hooks/use-event-listener'
|
import useEventListener from '@/shared/hooks/use-event-listener'
|
||||||
import { EditorType } from '@/features/ide-react/editor/types/editor-type'
|
import { EditorType } from '@/features/ide-react/editor/types/editor-type'
|
||||||
import { DocId } from '../../../../../types/project-settings'
|
import { DocId } from '../../../../../types/project-settings'
|
||||||
|
import { Update } from '@/features/history/services/types/update'
|
||||||
|
|
||||||
interface GotoOffsetOptions {
|
interface GotoOffsetOptions {
|
||||||
gotoOffset: number
|
gotoOffset: number
|
||||||
@@ -237,14 +237,13 @@ export const EditorManagerProvider: FC = ({ children }) => {
|
|||||||
(doc: Doc, document: Document) => {
|
(doc: Doc, document: Document) => {
|
||||||
attachErrorHandlerToDocument(doc, document)
|
attachErrorHandlerToDocument(doc, document)
|
||||||
|
|
||||||
// TODO: MIGRATION: Add a type for `update`
|
document.on('externalUpdate', (update: Update) => {
|
||||||
document.on('externalUpdate', (update: any) => {
|
|
||||||
if (ignoringExternalUpdates) {
|
if (ignoringExternalUpdates) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
_.property(['meta', 'type'])(update) === 'external' &&
|
update.meta.type === 'external' &&
|
||||||
_.property(['meta', 'source'])(update) === 'git-bridge'
|
update.meta.source === 'git-bridge'
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { Doc } from '../../../../../types/doc'
|
|||||||
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
||||||
import { findDocEntityById } from '@/features/ide-react/util/find-doc-entity-by-id'
|
import { findDocEntityById } from '@/features/ide-react/util/find-doc-entity-by-id'
|
||||||
import useSocketListener from '@/features/ide-react/hooks/use-socket-listener'
|
import useSocketListener from '@/features/ide-react/hooks/use-socket-listener'
|
||||||
|
import { debugConsole } from '@/utils/debugging'
|
||||||
|
|
||||||
type OnlineUser = {
|
type OnlineUser = {
|
||||||
id: string
|
id: string
|
||||||
@@ -176,9 +177,12 @@ export const OnlineUsersProvider: FC = ({ children }) => {
|
|||||||
const handleProjectJoined = () => {
|
const handleProjectJoined = () => {
|
||||||
socket.emit(
|
socket.emit(
|
||||||
'clientTracking.getConnectedUsers',
|
'clientTracking.getConnectedUsers',
|
||||||
// eslint-disable-next-line n/handle-callback-err
|
|
||||||
(error: Error, connectedUsers: ConnectedUser[]) => {
|
(error: Error, connectedUsers: ConnectedUser[]) => {
|
||||||
// TODO: MIGRATION: Handle error (although the original code doesn't)
|
if (error) {
|
||||||
|
// TODO: handle this error or ignore it?
|
||||||
|
debugConsole.error(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
const newOnlineUsers: OnlineUsersContextValue['onlineUsers'] = {}
|
const newOnlineUsers: OnlineUsersContextValue['onlineUsers'] = {}
|
||||||
for (const user of connectedUsers) {
|
for (const user of connectedUsers) {
|
||||||
if (user.client_id === socket.publicId) {
|
if (user.client_id === socket.publicId) {
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ import { FileTreeFindResult } from '@/features/ide-react/types/file-tree'
|
|||||||
|
|
||||||
export type IdeEvents = {
|
export type IdeEvents = {
|
||||||
'project:joined': [{ project: Project; permissionsLevel: PermissionsLevel }]
|
'project:joined': [{ project: Project; permissionsLevel: PermissionsLevel }]
|
||||||
|
|
||||||
// TODO: MIGRATION: This doesn't seem to be used. Investigate whether it can be removed
|
|
||||||
'document:opened': [doc: ShareJsDoc]
|
|
||||||
|
|
||||||
'document:closed': [doc: ShareJsDoc]
|
'document:closed': [doc: ShareJsDoc]
|
||||||
'doc:changed': [{ doc_id: string }]
|
'doc:changed': [{ doc_id: string }]
|
||||||
'doc:saved': [{ doc_id: string }]
|
'doc:saved': [{ doc_id: string }]
|
||||||
@@ -27,7 +23,6 @@ export type IdeEvents = {
|
|||||||
'comment:start_adding': []
|
'comment:start_adding': []
|
||||||
'references:should-reindex': []
|
'references:should-reindex': []
|
||||||
'history:toggle': []
|
'history:toggle': []
|
||||||
|
|
||||||
'entity:deleted': [entity: FileTreeFindResult]
|
'entity:deleted': [entity: FileTreeFindResult]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,24 @@ const MAX_PENDING_OP_SIZE = 64
|
|||||||
type JoinCallback = (error?: Error) => void
|
type JoinCallback = (error?: Error) => void
|
||||||
type LeaveCallback = JoinCallback
|
type LeaveCallback = JoinCallback
|
||||||
|
|
||||||
type Update = Record<string, any>
|
type Update =
|
||||||
|
| {
|
||||||
|
v: number
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
v: number
|
||||||
|
doc: string
|
||||||
|
op: AnyOperation[]
|
||||||
|
meta: {
|
||||||
|
type?: string
|
||||||
|
source: string
|
||||||
|
user_id: string
|
||||||
|
ts: number
|
||||||
|
}
|
||||||
|
hash?: string
|
||||||
|
lastV?: number
|
||||||
|
}
|
||||||
|
|
||||||
type Message = {
|
type Message = {
|
||||||
meta: {
|
meta: {
|
||||||
@@ -101,9 +118,6 @@ export class Document extends EventEmitter {
|
|||||||
if (this.cm6) {
|
if (this.cm6) {
|
||||||
this.cm6.on('change', this.checkConsistency)
|
this.cm6.on('change', this.checkConsistency)
|
||||||
}
|
}
|
||||||
if (this.doc) {
|
|
||||||
this.ideEventEmitter.emit('document:opened', this.doc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detachFromCM6() {
|
detachFromCM6() {
|
||||||
@@ -183,8 +197,7 @@ export class Document extends EventEmitter {
|
|||||||
|
|
||||||
private onUpdateAppliedHandler = (update: any) => this.onUpdateApplied(update)
|
private onUpdateAppliedHandler = (update: any) => this.onUpdateApplied(update)
|
||||||
|
|
||||||
// TODO: MIGRATION: Create proper types for error and message
|
private onErrorHandler = (error: Error, message: ErrorMetadata) => {
|
||||||
private onErrorHandler = (error: Error, message: { doc_id: string }) => {
|
|
||||||
// 'otUpdateError' are emitted per doc socket.io room, hence we can be
|
// 'otUpdateError' are emitted per doc socket.io room, hence we can be
|
||||||
// sure that message.doc_id exists.
|
// sure that message.doc_id exists.
|
||||||
if (message.doc_id !== this.doc_id) {
|
if (message.doc_id !== this.doc_id) {
|
||||||
|
|||||||
@@ -65,20 +65,6 @@ export class ShareJsDoc extends EventEmitter {
|
|||||||
this.connection = {
|
this.connection = {
|
||||||
send: (update: Update) => {
|
send: (update: Update) => {
|
||||||
this.startInflightOpTimeout(update)
|
this.startInflightOpTimeout(update)
|
||||||
// TODO: MIGRATION: Work out whether we can get rid of this. It looks as
|
|
||||||
// though it's here for debugging and isn't used
|
|
||||||
|
|
||||||
// if (
|
|
||||||
// window.disconnectOnUpdate != null &&
|
|
||||||
// Math.random() < window.disconnectOnUpdate
|
|
||||||
// ) {
|
|
||||||
// debugConsole.log('Disconnecting on update', update)
|
|
||||||
// this.socket.disconnect()
|
|
||||||
// }
|
|
||||||
// if (window.dropUpdates != null && Math.random() < window.dropUpdates) {
|
|
||||||
// debugConsole.log('Simulating a lost update', update)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
if (this.track_changes && this.track_changes_id_seeds) {
|
if (this.track_changes && this.track_changes_id_seeds) {
|
||||||
if (update.meta == null) {
|
if (update.meta == null) {
|
||||||
update.meta = {}
|
update.meta = {}
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ export type ShareJsOperation = AnyOperation[]
|
|||||||
|
|
||||||
export type TrackChangesIdSeeds = { inflight: string; pending: string }
|
export type TrackChangesIdSeeds = { inflight: string; pending: string }
|
||||||
|
|
||||||
export type Message = Record<string, any>
|
// TODO: check the properties of this type
|
||||||
// TODO: MIGRATION: Make an accurate and more specific type
|
export type Message = {
|
||||||
// {
|
v: Version
|
||||||
// v: Version
|
open?: boolean
|
||||||
// open?: boolean
|
meta?: {
|
||||||
// meta?: {
|
type?: string
|
||||||
// type: string
|
}
|
||||||
// }
|
doc?: string
|
||||||
// doc?: string
|
snapshot?: string
|
||||||
// snapshot?: string
|
}
|
||||||
// }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user