Skip to content

Commit

Permalink
UBERF-5418: Fix status editing
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Feb 9, 2024
1 parent 5e4040c commit 4646896
Show file tree
Hide file tree
Showing 30 changed files with 768 additions and 402 deletions.
2 changes: 2 additions & 0 deletions dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ services:
- MINIO_SECRET_KEY=minioadmin
- TITLE=DevPlatform
- DEFAULT_LANGUAGE=ru
- LAST_NAME_FIRST=true
restart: unless-stopped
collaborator:
image: hardcoreeng/collaborator
Expand Down Expand Up @@ -156,6 +157,7 @@ services:
# - APM_SERVER_URL=http://apm-server:8200
- SERVER_PROVIDER=ws
- ACCOUNTS_URL=http://account:3000
- LAST_NAME_FIRST=true
restart: unless-stopped
rekoni:
image: hardcoreeng/rekoni-service
Expand Down
3 changes: 2 additions & 1 deletion dev/prod/public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"GMAIL_URL": "http://localhost:8088",
"CALENDAR_URL": "http://localhost:8095",
"REKONI_URL": "http://localhost:4004",
"COLLABORATOR_URL": "ws://localhost:3078"
"COLLABORATOR_URL": "ws://localhost:3078",
"LAST_NAME_FIRST": "true"
}
8 changes: 1 addition & 7 deletions dev/storage/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,11 @@ class InMemoryTxAdapter extends DummyDbAdapter implements TxAdapter {
return await this.txdb.findAll(_class, query, options)
}

async tx (...tx: Tx[]): Promise<TxResult> {
async tx (...tx: Tx[]): Promise<TxResult[]> {
const r: TxResult[] = []
for (const t of tx) {
r.push(await this.txdb.tx(t))
}
if (r.length === 1) {
return r[0]
}
if (r.length === 0) {
return {}
}
return r
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/memdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ export class TxDb extends MemDb {
throw new Error('Method not implemented.')
}

async tx (tx: Tx): Promise<TxResult> {
async tx (tx: Tx): Promise<TxResult[]> {
this.addDoc(tx)
return {}
return []
}
}

Expand Down
28 changes: 15 additions & 13 deletions packages/core/src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import type {
DocumentQuery,
FindOptions,
FindResult,
SearchQuery,
SearchOptions,
SearchQuery,
SearchResult,
TxResult,
WithLookup
} from './storage'
import { DocumentClassQuery, Tx, TxCUD, TxFactory, TxProcessor } from './tx'
import { DocumentClassQuery, Tx, TxApplyResult, TxCUD, TxFactory, TxProcessor } from './tx'

/**
* @public
Expand Down Expand Up @@ -464,17 +464,19 @@ export class ApplyOperations extends TxOperations {

async commit (notify: boolean = true, extraNotify: Ref<Class<Doc>>[] = []): Promise<boolean> {
if (this.txes.length > 0) {
return await ((await this.ops.tx(
this.ops.txFactory.createTxApplyIf(
core.space.Tx,
this.scope,
this.matches,
this.notMatches,
this.txes,
notify,
extraNotify
)
)) as Promise<boolean>)
return (
await ((await this.ops.tx(
this.ops.txFactory.createTxApplyIf(
core.space.Tx,
this.scope,
this.matches,
this.notMatches,
this.txes,
notify,
extraNotify
)
)) as Promise<TxApplyResult>)
).success
}
return true
}
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ export interface TxApplyIf extends Tx {
extraNotify?: Ref<Class<Doc>>[]
}

export interface TxApplyResult {
success: boolean
derived: Tx[] // Some derived transactions to handle.
}

/**
* @public
*/
Expand Down Expand Up @@ -318,14 +323,14 @@ export const DOMAIN_TX = 'tx' as Domain
* @public
*/
export interface WithTx {
tx: (...txs: Tx[]) => Promise<TxResult>
tx: (...txs: Tx[]) => Promise<TxResult[]>
}

/**
* @public
*/
export abstract class TxProcessor implements WithTx {
async tx (...txes: Tx[]): Promise<TxResult> {
async tx (...txes: Tx[]): Promise<TxResult[]> {
const result: TxResult[] = []
for (const tx of txes) {
switch (tx._class) {
Expand All @@ -346,15 +351,9 @@ export abstract class TxProcessor implements WithTx {
break
case core.class.TxApplyIf:
// Apply if processed on server
return await Promise.resolve({})
return await Promise.resolve([])
}
}
if (result.length === 0) {
return {}
}
if (result.length === 1) {
return result[0]
}
return result
}

Expand Down
49 changes: 34 additions & 15 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,18 @@ export class LiveQuery extends TxProcessor implements Client {
}
}

private triggerRefresh (q: Query): void {
const r: Promise<FindResult<Doc>> | FindResult<Doc> = this.client.findAll(q._class, q.query, q.options)
q.result = r
void r.then(async (qr) => {
const oldResult = q.result
if (!deepEqual(qr, oldResult) || (qr.total !== q.total && q.options?.total === true)) {
q.total = qr.total
await this.callback(q)
}
})
}

// Check if query is partially matched.
private async matchQuery (q: Query, tx: TxUpdateDoc<Doc>, docCache?: Map<string, Doc>): Promise<boolean> {
const clazz = this.getHierarchy().isMixin(q._class) ? this.getHierarchy().getBaseClass(q._class) : q._class
Expand Down Expand Up @@ -1056,24 +1068,31 @@ export class LiveQuery extends TxProcessor implements Client {
return result
}

async tx (tx: Tx): Promise<TxResult> {
if (tx._class === core.class.TxWorkspaceEvent) {
await this.checkUpdateFulltextQueries(tx)
await this.changePrivateHandler(tx)
return {}
async tx (...txes: Tx[]): Promise<TxResult[]> {
const result: TxResult[] = []
for (const tx of txes) {
if (tx._class === core.class.TxWorkspaceEvent) {
await this.checkUpdateEvents(tx)
await this.changePrivateHandler(tx)
}
result.push(...(await super.tx(tx)))
}
return await super.tx(tx)
return result
}

private async checkUpdateFulltextQueries (tx: Tx): Promise<void> {
private async checkUpdateEvents (tx: Tx): Promise<void> {
const evt = tx as TxWorkspaceEvent
const h = this.client.getHierarchy()
function hasClass (q: Query, classes: Ref<Class<Doc>>[]): boolean {
return classes.includes(q._class) || classes.some((it) => h.isDerived(q._class, it) || h.isDerived(it, q._class))
}
if (evt.event === WorkspaceEvent.IndexingUpdate) {
const indexingParam = evt.params as IndexingUpdateEvent
for (const q of [...this.queue]) {
if (indexingParam._class.includes(q._class) && q.query.$search !== undefined) {
if (hasClass(q, indexingParam._class) && q.query.$search !== undefined) {
if (!this.removeFromQueue(q)) {
try {
await this.refresh(q)
this.triggerRefresh(q)
} catch (err) {
console.error(err)
}
Expand All @@ -1082,9 +1101,9 @@ export class LiveQuery extends TxProcessor implements Client {
}
for (const v of this.queries.values()) {
for (const q of v) {
if (indexingParam._class.includes(q._class) && q.query.$search !== undefined) {
if (hasClass(q, indexingParam._class) && q.query.$search !== undefined) {
try {
await this.refresh(q)
this.triggerRefresh(q)
} catch (err) {
console.error(err)
}
Expand All @@ -1095,10 +1114,10 @@ export class LiveQuery extends TxProcessor implements Client {
if (evt.event === WorkspaceEvent.BulkUpdate) {
const params = evt.params as BulkUpdateEvent
for (const q of [...this.queue]) {
if (params._class.includes(q._class)) {
if (hasClass(q, params._class)) {
if (!this.removeFromQueue(q)) {
try {
await this.refresh(q)
this.triggerRefresh(q)
} catch (err) {
console.error(err)
}
Expand All @@ -1107,9 +1126,9 @@ export class LiveQuery extends TxProcessor implements Client {
}
for (const v of this.queries.values()) {
for (const q of v) {
if (params._class.includes(q._class)) {
if (hasClass(q, params._class)) {
try {
await this.refresh(q)
this.triggerRefresh(q)
} catch (err) {
console.error(err)
}
Expand Down
39 changes: 30 additions & 9 deletions plugins/client-resources/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ import core, {
FindOptions,
FindResult,
LoadModelResponse,
MeasureDoneOperation,
Ref,
SearchOptions,
SearchQuery,
SearchResult,
Timestamp,
Tx,
TxApplyIf,
TxApplyResult,
TxHandler,
TxResult,
TxWorkspaceEvent,
WorkspaceEvent,
generateId,
SearchQuery,
SearchOptions,
SearchResult,
MeasureDoneOperation
generateId
} from '@hcengineering/core'
import { PlatformError, UNAUTHORIZED, broadcastEvent, getMetadata, unknownError } from '@hcengineering/platform'

Expand All @@ -57,7 +58,8 @@ class RequestPromise {
reconnect?: () => void
constructor (
readonly method: string,
readonly params: any[]
readonly params: any[],
readonly handleResult?: (result: any) => Promise<void>
) {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve
Expand Down Expand Up @@ -263,7 +265,13 @@ class Connection implements ClientConnection {
)
promise.reject(new PlatformError(resp.error))
} else {
promise.resolve(resp.result)
if (request?.handleResult !== undefined) {
void request.handleResult(resp.result).then(() => {
promise.resolve(resp.result)
})
} else {
promise.resolve(resp.result)
}
}
void broadcastEvent(client.event.NetworkRequests, this.requests.size)
} else {
Expand Down Expand Up @@ -336,13 +344,14 @@ class Connection implements ClientConnection {
params: any[]
// If not defined, on reconnect with timeout, will retry automatically.
retry?: () => Promise<boolean>
handleResult?: (result: any) => Promise<void>
}): Promise<any> {
if (this.closed) {
throw new PlatformError(unknownError('connection closed'))
}

const id = this.lastId++
const promise = new RequestPromise(data.method, data.params)
const promise = new RequestPromise(data.method, data.params, data.handleResult)

const sendData = async (): Promise<void> => {
if (this.websocket instanceof Promise) {
Expand Down Expand Up @@ -423,7 +432,19 @@ class Connection implements ClientConnection {
return (await this.findAll(core.class.Tx, { _id: (tx as TxApplyIf).txes[0]._id }, { limit: 1 })).length === 0
}
return (await this.findAll(core.class.Tx, { _id: tx._id }, { limit: 1 })).length === 0
}
},
handleResult:
tx._class === core.class.TxApplyIf
? async (result) => {
if (tx._class === core.class.TxApplyIf) {
// We need to check extra broadcast's and perform them before
const r = result as TxApplyResult
for (const d of r?.derived ?? []) {
this.handler(d)
}
}
}
: undefined
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@
import { ObjectPresenter } from '@hcengineering/view-resources'
export let object: Doc | Doc[]
export let deleteAction: () => void
export let deleteAction: () => void | Promise<void>
export let skipCheck: boolean = false
export let canDeleteExtra: boolean = true
const objectArray = Array.isArray(object) ? object : [object]
const owners: PersonAccount[] = Array.from($personAccountByIdStore.values()).filter(
(acc) => acc.role === AccountRole.Owner
)
const dispatch = createEventDispatcher()
$: creators = [...new Set(objectArray.map((obj) => obj.createdBy as Ref<PersonAccount>))]
$: canDelete =
skipCheck ||
(creators.length === 1 && creators.includes(getCurrentAccount()._id as Ref<PersonAccount>)) ||
getCurrentAccount().role === AccountRole.Owner
(skipCheck ||
(creators.length === 1 && creators.includes(getCurrentAccount()._id as Ref<PersonAccount>)) ||
getCurrentAccount().role === AccountRole.Owner) &&
canDeleteExtra
$: label = canDelete ? view.string.DeleteObject : view.string.DeletePopupNoPermissionTitle
</script>

Expand All @@ -56,9 +58,11 @@
{#if canDelete}
<div class="mb-2">
<Label label={view.string.DeleteObjectConfirm} params={{ count: objectArray.length }} />
{#if objectArray.length === 1}
<ObjectPresenter _class={objectArray[0]._class} objectId={objectArray[0]._id} value={objectArray[0]} />
{/if}
<div class="mt-2">
{#if objectArray.length === 1}
<ObjectPresenter _class={objectArray[0]._class} objectId={objectArray[0]._id} value={objectArray[0]} />
{/if}
</div>
</div>
{:else}
<div class="mb-2">
Expand All @@ -82,4 +86,5 @@
</div>
{/if}
</div>
<slot />
</Card>
4 changes: 3 additions & 1 deletion plugins/contact-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export {
EmployeeArrayEditor,
EmployeeEditor,
PersonAccountRefPresenter,
PersonAccountPresenter,
MembersPresenter,
EditPerson,
EmployeeRefPresenter,
Expand Down Expand Up @@ -168,7 +169,8 @@ export {
UsersList,
SelectUsersPopup,
IconAddMember,
UserDetails
UserDetails,
DeleteConfirmationPopup
}

const toObjectSearchResult = (e: WithLookup<Contact>): ObjectSearchResult => ({
Expand Down
Loading

0 comments on commit 4646896

Please sign in to comment.