Cloud collaborator refactoring (#6424)

This commit is contained in:
Alexander Onnikov
2024-08-29 15:10:37 +07:00
committed by GitHub
parent 42b19c39c7
commit 4ff8a4559f
52 changed files with 762 additions and 998 deletions
@@ -16,7 +16,7 @@
import { Class, Doc, Ref } from '@hcengineering/core'
import notification from '@hcengineering/notification'
import { Panel } from '@hcengineering/panel'
import { getResource } from '@hcengineering/platform'
import { getResource, setPlatformStatus, unknownError } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import { Collaboration } from '@hcengineering/text-editor-resources'
import {
@@ -218,15 +218,19 @@
const project = await getLatestProjectId($controlledDocument.space)
if (project !== undefined) {
const id = await createNewDraftForControlledDoc(
client,
$controlledDocument,
$controlledDocument.space,
version,
project
)
const loc = getProjectDocumentLink(id, project)
navigate(loc)
try {
const id = await createNewDraftForControlledDoc(
client,
$controlledDocument,
$controlledDocument.space,
version,
project
)
const loc = getProjectDocumentLink(id, project)
navigate(loc)
} catch (err) {
await setPlatformStatus(unknownError(err))
}
} else {
console.warn('No document project found for space', $controlledDocument.space)
}
@@ -237,7 +241,11 @@
async function onEditDocument (): Promise<void> {
if ($controlledDocument != null && $canCreateNewSnapshot && $isProjectEditable) {
await createDocumentSnapshotAndEdit(client, $controlledDocument)
try {
await createDocumentSnapshotAndEdit(client, $controlledDocument)
} catch (err) {
await setPlatformStatus(unknownError(err))
}
} else {
console.warn('Unexpected document state', $documentState)
}
@@ -5,10 +5,9 @@
import { CollaborationIds, type Ydoc } from '@hcengineering/text-editor'
import {
CollaborationDiffViewer,
Provider,
StringDiffViewer,
TiptapCollabProvider,
createTiptapCollaborationData,
formatCollaborativeDocumentId
createTiptapCollaborationData
} from '@hcengineering/text-editor-resources'
import { Dropdown, Label, ListItem, Loading, Scroller, themeStore } from '@hcengineering/ui'
import documents, {
@@ -25,7 +24,7 @@
$documentComparisonVersions as documentComparisonVersions,
comparisonRequested
} from '../../stores/editors/document'
import { COLLABORATOR_URL, TOKEN, getTranslatedControlledDocStates, getTranslatedDocumentStates } from '../../utils'
import { getTranslatedControlledDocStates, getTranslatedDocumentStates } from '../../utils'
import DocumentTitle from './DocumentTitle.svelte'
const client = getClient()
@@ -33,7 +32,7 @@
const ydoc = getContext<Ydoc>(CollaborationIds.Doc)
let comparedYdoc: Ydoc | undefined = undefined
let comparedProvider: TiptapCollabProvider | undefined = undefined
let comparedProvider: Provider | undefined = undefined
let loading = true
const handleSelect = (event: CustomEvent<ListItem>) => {
@@ -86,23 +85,20 @@
}))
$: if ($compareTo) {
if (comparedProvider) {
comparedProvider.disconnect()
comparedProvider.destroy()
}
loading = true
const collaborativeDoc = $compareTo.content
const data = createTiptapCollaborationData({
collaboratorURL: COLLABORATOR_URL,
token: TOKEN,
documentId: formatCollaborativeDocumentId(collaborativeDoc)
document: $compareTo.content
})
comparedYdoc = data.ydoc
comparedProvider = data.provider
comparedProvider.loaded.then(() => (loading = false))
void comparedProvider.loaded.then(() => (loading = false))
}
onDestroy(() => {
comparedProvider?.destroy()
void comparedProvider?.destroy()
})
</script>
@@ -25,7 +25,7 @@ import {
type MixinData
} from '@hcengineering/core'
import { translate } from '@hcengineering/platform'
import { copyDocument, takeSnapshot } from '@hcengineering/presentation'
import { copyDocument } from '@hcengineering/presentation'
import { themeStore } from '@hcengineering/ui'
import documents, {
type ControlledDocument,
@@ -55,6 +55,18 @@ export async function createNewDraftForControlledDoc (
newDraftDocId = newDraftDocId ?? generateId()
const collaborativeDoc = getCollaborativeDocForDocument(
`DOC-${document.prefix}`,
document.seqNumber,
document.major,
document.minor,
true
)
if (document.content !== undefined) {
await copyDocument(document.content, collaborativeDoc)
}
// Create new change control for new version
const newCCId = generateId<ChangeControl>()
const newCCSpec: Data<ChangeControl> = {
@@ -66,14 +78,6 @@ export async function createNewDraftForControlledDoc (
await createChangeControl(client, newCCId, newCCSpec, document.space)
const collaborativeDoc = getCollaborativeDocForDocument(
`DOC-${document.prefix}`,
document.seqNumber,
document.major,
document.minor,
true
)
// TODO: copy labels?
const docSpec: AttachedData<ControlledDocument> = {
...(document.template != null ? { template: document.template } : {}),
@@ -133,10 +137,6 @@ export async function createNewDraftForControlledDoc (
})
}
if (document.content !== undefined) {
await copyDocument(document.content, collaborativeDoc)
}
const documentTraining = getDocumentTraining(hierarchy, document)
if (documentTraining !== undefined) {
const newDraftDoc = await client.findOne(document._class, { _id: newDraftDocId })
@@ -158,10 +158,19 @@ export async function createNewDraftForControlledDoc (
}
export async function createDocumentSnapshotAndEdit (client: TxOperations, document: ControlledDocument): Promise<void> {
const collaborativeDoc = getCollaborativeDocForDocument(
`DOC-${document.prefix}`,
document.seqNumber,
document.major,
document.minor,
true
)
await copyDocument(document.content, collaborativeDoc)
const language = get(themeStore).language
const namePrefix = await translate(documents.string.DraftRevision, {}, language)
const name = `${namePrefix} ${(document.snapshots ?? 0) + 1}`
const snapshot = await takeSnapshot(document.content, name)
const newSnapshotId = generateId<ControlledDocumentSnapshot>()
const op = client.apply(document._id)
@@ -176,7 +185,7 @@ export async function createDocumentSnapshotAndEdit (client: TxOperations, docum
name,
state: document.state,
controlledState: document.controlledState,
content: snapshot
content: collaborativeDoc
},
newSnapshotId
)
@@ -27,11 +27,10 @@ import core, {
getCurrentAccount,
checkPermission
} from '@hcengineering/core'
import { type IntlString, getMetadata, translate } from '@hcengineering/platform'
import presentation, { getClient } from '@hcengineering/presentation'
import { type IntlString, translate } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import { type Person, type Employee, type PersonAccount } from '@hcengineering/contact'
import request, { RequestStatus } from '@hcengineering/request'
import textEditor from '@hcengineering/text-editor'
import { isEmptyMarkup } from '@hcengineering/text'
import { showPopup, getUserTimezone, type Location } from '@hcengineering/ui'
import { type KeyFilter } from '@hcengineering/view'
@@ -62,9 +61,6 @@ import { wizardOpened } from './stores/wizards/create-document'
export type TranslatedDocumentStates = Readonly<Record<DocumentState, string>>
export const TOKEN = getMetadata(presentation.metadata.Token) ?? ''
export const COLLABORATOR_URL = getMetadata(textEditor.metadata.CollaboratorUrl) ?? ''
export const isDocumentCommentAttachedTo = (
value: DocumentComment | null | undefined,
location: { nodeId?: string | null }