Board: Update server-plugin for task to subscribe to updates on create & update (#1925)

Signed-off-by: Anna No <anna.no@xored.com>
This commit is contained in:
Anna No 2022-05-30 22:59:14 +07:00 committed by GitHub
parent e97a6cb6f5
commit df9115b75a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 115 deletions

View File

@ -4,6 +4,7 @@
Platform:
- Fix subscribe to updates on Task create / update
- Fix popup window layouts
- Fix table two loading spinners
- Improve full text search performance

View File

@ -16,18 +16,11 @@
import type { Doc, Ref, Tx, TxCollectionCUD, TxCreateDoc, TxRemoveDoc } from '@anticrm/core'
import type { TriggerControl } from '@anticrm/server-core'
import { extractTx } from '@anticrm/server-core'
import type { Attachment } from '@anticrm/attachment'
import attachment from '@anticrm/attachment'
import core, { TxProcessor } from '@anticrm/core'
const extractTx = (tx: Tx): Tx => {
if (tx._class === core.class.TxCollectionCUD) {
return (tx as TxCollectionCUD<Doc, Attachment>).tx
}
return tx
}
const findCreateTx = async (
id: Ref<Attachment>,
findAll: TriggerControl['findAll']

View File

@ -15,7 +15,6 @@
import contact, { Channel } from '@anticrm/contact'
import core, {
AttachedDoc,
Class,
Doc,
DocumentQuery,
@ -24,28 +23,11 @@ import core, {
Hierarchy,
Ref,
Tx,
TxCollectionCUD,
TxCreateDoc,
TxProcessor
} from '@anticrm/core'
import gmail, { Message } from '@anticrm/gmail'
import { TriggerControl } from '@anticrm/server-core'
const extractTx = (tx: Tx): Tx => {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
if (ctx.tx._class === core.class.TxCreateDoc) {
const create = ctx.tx as TxCreateDoc<AttachedDoc>
create.attributes.attachedTo = ctx.objectId
create.attributes.attachedToClass = ctx.objectClass
create.attributes.collection = ctx.collection
return create
}
return ctx.tx
}
return tx
}
import { extractTx, TriggerControl } from '@anticrm/server-core'
/**
* @public

View File

@ -13,31 +13,15 @@
// limitations under the License.
//
import core, { AttachedDoc, Doc, Tx, TxCollectionCUD, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core'
import core, { Doc, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core'
import inventory, { Product } from '@anticrm/inventory'
import login from '@anticrm/login'
import { getMetadata } from '@anticrm/platform'
import { TriggerControl } from '@anticrm/server-core'
import { extractTx, TriggerControl } from '@anticrm/server-core'
import { getUpdateLastViewTx } from '@anticrm/server-notification'
import view from '@anticrm/view'
import workbench from '@anticrm/workbench'
const extractTx = (tx: Tx): Tx => {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
if (ctx.tx._class === core.class.TxCreateDoc) {
const create = ctx.tx as TxCreateDoc<AttachedDoc>
create.attributes.attachedTo = ctx.objectId
create.attributes.attachedToClass = ctx.objectClass
create.attributes.collection = ctx.collection
return create
}
return ctx.tx
}
return tx
}
/**
* @public
*/

View File

@ -35,25 +35,10 @@ import core, {
import notification, { EmailNotification, Notification, NotificationStatus } from '@anticrm/notification'
import { getResource } from '@anticrm/platform'
import type { TriggerControl } from '@anticrm/server-core'
import { extractTx } from '@anticrm/server-core'
import { getUpdateLastViewTx } from '@anticrm/server-notification'
import view, { HTMLPresenter, TextPresenter } from '@anticrm/view'
const extractTx = (tx: Tx): Tx => {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
if (ctx.tx._class === core.class.TxCreateDoc) {
const create = ctx.tx as TxCreateDoc<AttachedDoc>
create.attributes.attachedTo = ctx.objectId
create.attributes.attachedToClass = ctx.objectClass
create.attributes.collection = ctx.collection
return create
}
return ctx.tx
}
return tx
}
/**
* @public
*/

View File

@ -14,7 +14,6 @@
//
import core, {
AttachedDoc,
Class,
Doc,
DocumentQuery,
@ -23,31 +22,14 @@ import core, {
Hierarchy,
Ref,
Tx,
TxCollectionCUD,
TxCreateDoc,
TxCUD,
TxProcessor,
TxRemoveDoc
} from '@anticrm/core'
import { TriggerControl } from '@anticrm/server-core'
import { extractTx, TriggerControl } from '@anticrm/server-core'
import tags, { TagElement, TagReference } from '@anticrm/tags'
const extractTx = (tx: Tx): Tx => {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
if (ctx.tx._class === core.class.TxCreateDoc) {
const create = ctx.tx as TxCreateDoc<AttachedDoc>
create.attributes.attachedTo = ctx.objectId
create.attributes.attachedToClass = ctx.objectClass
create.attributes.collection = ctx.collection
return create
}
return ctx.tx
}
return tx
}
/**
* @public
*/

View File

@ -16,7 +16,7 @@
import core, { Doc, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core'
import login from '@anticrm/login'
import { getMetadata } from '@anticrm/platform'
import { TriggerControl } from '@anticrm/server-core'
import { extractTx, TriggerControl } from '@anticrm/server-core'
import { getUpdateLastViewTx } from '@anticrm/server-notification'
import task, { Issue, Task } from '@anticrm/task'
import view from '@anticrm/view'
@ -43,11 +43,12 @@ export function issueTextPresenter (doc: Doc): string {
* @public
*/
export async function OnTaskCreate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
if (tx._class !== core.class.TxCreateDoc) {
const actualTx = extractTx(tx)
if (actualTx._class !== core.class.TxCreateDoc) {
return []
}
const createTx = tx as TxCreateDoc<Task>
const createTx = actualTx as TxCreateDoc<Task>
if (!control.hierarchy.isDerived(createTx.objectClass, task.class.Task)) {
return []
@ -89,11 +90,12 @@ export async function OnTaskCreate (tx: Tx, control: TriggerControl): Promise<Tx
* @public
*/
export async function OnTaskUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
if (tx._class !== core.class.TxUpdateDoc) {
const actualTx = extractTx(tx)
if (actualTx._class !== core.class.TxUpdateDoc) {
return []
}
const updateTx = tx as TxUpdateDoc<Task>
const updateTx = actualTx as TxUpdateDoc<Task>
if (!control.hierarchy.isDerived(updateTx.objectClass, task.class.Task)) {
return []

View File

@ -15,7 +15,6 @@
import contact, { Channel } from '@anticrm/contact'
import core, {
AttachedDoc,
Class,
Doc,
DocumentQuery,
@ -24,29 +23,12 @@ import core, {
Hierarchy,
Ref,
Tx,
TxCollectionCUD,
TxCreateDoc,
TxProcessor
} from '@anticrm/core'
import { TriggerControl } from '@anticrm/server-core'
import { extractTx, TriggerControl } from '@anticrm/server-core'
import telegram, { TelegramMessage } from '@anticrm/telegram'
const extractTx = (tx: Tx): Tx => {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
if (ctx.tx._class === core.class.TxCreateDoc) {
const create = ctx.tx as TxCreateDoc<AttachedDoc>
create.attributes.attachedTo = ctx.objectId
create.attributes.attachedToClass = ctx.objectClass
create.attributes.collection = ctx.collection
return create
}
return ctx.tx
}
return tx
}
/**
* @public
*/

View File

@ -19,4 +19,5 @@ export * from './types'
export * from './fulltext'
export * from './storage'
export * from './pipeline'
export * from './utils'
export { default } from './plugin'

View File

@ -52,6 +52,7 @@ import { FullTextIndex } from './fulltext'
import serverCore from './plugin'
import { Triggers } from './triggers'
import type { FullTextAdapter, FullTextAdapterFactory, ObjectDDParticipant } from './types'
import { extractTx } from './utils'
/**
* @public
@ -230,17 +231,8 @@ class TServerStorage implements ServerStorage {
return doc
}
extractTx (tx: Tx): Tx {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
return ctx.tx
}
return tx
}
async processRemove (ctx: MeasureContext, tx: Tx): Promise<Tx[]> {
const actualTx = this.extractTx(tx)
const actualTx = extractTx(tx)
if (!this.hierarchy.isDerived(actualTx._class, core.class.TxRemoveDoc)) return []
const rtx = actualTx as TxRemoveDoc<Doc>
const result: Tx[] = []
@ -316,7 +308,7 @@ class TServerStorage implements ServerStorage {
}
async processMove (ctx: MeasureContext, tx: Tx): Promise<Tx[]> {
const actualTx = this.extractTx(tx)
const actualTx = extractTx(tx)
if (!this.hierarchy.isDerived(actualTx._class, core.class.TxUpdateDoc)) return []
const rtx = actualTx as TxUpdateDoc<Doc>
if (rtx.operations.space === undefined || rtx.operations.space === rtx.objectSpace) return []

20
server/core/src/utils.ts Normal file
View File

@ -0,0 +1,20 @@
import core, { AttachedDoc, Doc, Tx, TxCollectionCUD, TxCreateDoc } from '@anticrm/core'
/**
* @public
*/
export function extractTx (tx: Tx): Tx {
if (tx._class === core.class.TxCollectionCUD) {
const ctx = tx as TxCollectionCUD<Doc, AttachedDoc>
if (ctx.tx._class === core.class.TxCreateDoc) {
const create = ctx.tx as TxCreateDoc<AttachedDoc>
create.attributes.attachedTo = ctx.objectId
create.attributes.attachedToClass = ctx.objectClass
create.attributes.collection = ctx.collection
return create
}
return ctx.tx
}
return tx
}