mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-09 09:20:54 +00:00
Fix query clone respect mixins (#1631)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
dfbf2d5263
commit
e4e2af93dc
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,6 @@
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anticrm/platform": "~0.6.6",
|
||||
"just-clone": "^3.2.1"
|
||||
"@anticrm/platform": "~0.6.6"
|
||||
}
|
||||
}
|
||||
|
@ -380,6 +380,31 @@ export class Hierarchy {
|
||||
}
|
||||
return vResult
|
||||
}
|
||||
|
||||
clone (obj: any): any {
|
||||
if (typeof obj === 'function') {
|
||||
return obj
|
||||
}
|
||||
const result: any = Array.isArray(obj) ? [] : {}
|
||||
for (const key in obj) {
|
||||
// include prototype properties
|
||||
const value = obj[key]
|
||||
const type = {}.toString.call(value).slice(8, -1)
|
||||
if (type === 'Array') {
|
||||
result[key] = this.clone(value)
|
||||
}
|
||||
if (type === 'Object') {
|
||||
const m = Hierarchy.mixinClass(value)
|
||||
const valClone = this.clone(value)
|
||||
result[key] = m !== undefined ? this.as(valClone, m) : valClone
|
||||
} else if (type === 'Date') {
|
||||
result[key] = new Date(value.getTime())
|
||||
} else {
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
function addNew<T> (val: Set<T>, value: T): boolean {
|
||||
|
@ -14,7 +14,6 @@
|
||||
//
|
||||
|
||||
import { PlatformError, Severity, Status } from '@anticrm/platform'
|
||||
import clone from 'just-clone'
|
||||
import { Lookup, ReverseLookups } from '.'
|
||||
import type { Class, Doc, Ref } from './classes'
|
||||
import core from './component'
|
||||
@ -157,7 +156,7 @@ export abstract class MemDb extends TxProcessor {
|
||||
if (options?.sort !== undefined) resultSort(result, options?.sort)
|
||||
const total = result.length
|
||||
result = result.slice(0, options?.limit)
|
||||
const tresult = clone(result) as WithLookup<T>[]
|
||||
const tresult = this.hierarchy.clone(result) as WithLookup<T>[]
|
||||
const res = tresult.map((it) => this.hierarchy.updateLookupMixin(_class, it, options))
|
||||
return toFindResult(res, total)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
const typeClass = hierarchy.getClass(typeClassId)
|
||||
const editorMixin = hierarchy.as(typeClass, view.mixin.AttributeEditor)
|
||||
editor = getResource(editorMixin.editor).catch((cause) => {
|
||||
console.error('failed to find editor for', _class, attribute, typeClassId)
|
||||
console.error(`failed to find editor for ${_class} ${attribute} ${typeClassId} cause: ${cause}`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,13 @@
|
||||
<div class="ac-header__icon"><Avatar size={'medium'} /></div>
|
||||
<span class="ac-header__title">{name}</span>
|
||||
</div>
|
||||
<ActionIcon icon={IconClose} size={'medium'} action={() => dispatch('close')} />
|
||||
<ActionIcon
|
||||
icon={IconClose}
|
||||
size={'medium'}
|
||||
action={(_) => {
|
||||
dispatch('close')
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if contentType && contentType.startsWith('image/')}
|
||||
|
@ -29,7 +29,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@anticrm/platform": "~0.6.6",
|
||||
"@anticrm/core": "~0.6.16",
|
||||
"just-clone": "^3.2.1"
|
||||
"@anticrm/core": "~0.6.16"
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ import core, {
|
||||
WithLookup,
|
||||
toFindResult
|
||||
} from '@anticrm/core'
|
||||
import justClone from 'just-clone'
|
||||
|
||||
interface Query {
|
||||
_class: Ref<Class<Doc>>
|
||||
@ -325,13 +324,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
||||
* Clone document with respect to mixin inner document cloning.
|
||||
*/
|
||||
private clone<T extends Doc>(results: T[]): T[] {
|
||||
const result: T[] = []
|
||||
const h = this.getHierarchy()
|
||||
for (const doc of results) {
|
||||
const m = Hierarchy.mixinClass(doc)
|
||||
result.push(m !== undefined ? h.as(Hierarchy.toDoc(doc), m) : justClone(doc))
|
||||
}
|
||||
return result
|
||||
return this.getHierarchy().clone(results) as T[]
|
||||
}
|
||||
|
||||
private async refresh (q: Query): Promise<void> {
|
||||
|
@ -39,7 +39,6 @@
|
||||
"@anticrm/activity-resources": "~0.6.0",
|
||||
"@anticrm/activity": "~0.6.0",
|
||||
"@anticrm/contact": "~0.6.5",
|
||||
"just-clone": "^3.2.1",
|
||||
"@anticrm/core": "~0.6.16"
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
import presentation, { createQuery, getClient } from '@anticrm/presentation'
|
||||
import { Button, Grid, Icon, Label, ToggleWithLabel } from '@anticrm/ui'
|
||||
import notification from '../plugin'
|
||||
import justClone from 'just-clone'
|
||||
|
||||
const accountId = getCurrentAccount()._id
|
||||
const typeQuery = createQuery()
|
||||
@ -42,7 +41,7 @@
|
||||
providersQuery.query(notification.class.NotificationProvider, {}, (res) => (providers = res))
|
||||
settingsQuery.query(notification.class.NotificationSetting, { space }, (res) => {
|
||||
settings = convertToMap(res)
|
||||
oldSettings = convertToMap(justClone(res))
|
||||
oldSettings = convertToMap(client.getHierarchy().clone(res))
|
||||
})
|
||||
|
||||
function convertToMap (
|
||||
|
@ -160,7 +160,7 @@ function ShowPopup (
|
||||
props?: Record<string, any>
|
||||
}
|
||||
): void {
|
||||
const docs = Array.isArray(doc) ? doc : [doc]
|
||||
const docs = Array.isArray(doc) ? doc : doc !== undefined ? [doc] : []
|
||||
evt.preventDefault()
|
||||
let cprops = {
|
||||
...(props?.props ?? {})
|
||||
|
@ -98,8 +98,7 @@ export async function doNavigate (
|
||||
if (ex === undefined) {
|
||||
const r = await client.findOne(props.spaceClass, {})
|
||||
if (r !== undefined) {
|
||||
loc.path[3] = r._id
|
||||
navigate(loc)
|
||||
loc.path[2] = r._id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user