mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-11 21:11:57 +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"
|
"typescript": "^4.3.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anticrm/platform": "~0.6.6",
|
"@anticrm/platform": "~0.6.6"
|
||||||
"just-clone": "^3.2.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,6 +380,31 @@ export class Hierarchy {
|
|||||||
}
|
}
|
||||||
return vResult
|
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 {
|
function addNew<T> (val: Set<T>, value: T): boolean {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import { PlatformError, Severity, Status } from '@anticrm/platform'
|
import { PlatformError, Severity, Status } from '@anticrm/platform'
|
||||||
import clone from 'just-clone'
|
|
||||||
import { Lookup, ReverseLookups } from '.'
|
import { Lookup, ReverseLookups } from '.'
|
||||||
import type { Class, Doc, Ref } from './classes'
|
import type { Class, Doc, Ref } from './classes'
|
||||||
import core from './component'
|
import core from './component'
|
||||||
@ -157,7 +156,7 @@ export abstract class MemDb extends TxProcessor {
|
|||||||
if (options?.sort !== undefined) resultSort(result, options?.sort)
|
if (options?.sort !== undefined) resultSort(result, options?.sort)
|
||||||
const total = result.length
|
const total = result.length
|
||||||
result = result.slice(0, options?.limit)
|
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))
|
const res = tresult.map((it) => this.hierarchy.updateLookupMixin(_class, it, options))
|
||||||
return toFindResult(res, total)
|
return toFindResult(res, total)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
const typeClass = hierarchy.getClass(typeClassId)
|
const typeClass = hierarchy.getClass(typeClassId)
|
||||||
const editorMixin = hierarchy.as(typeClass, view.mixin.AttributeEditor)
|
const editorMixin = hierarchy.as(typeClass, view.mixin.AttributeEditor)
|
||||||
editor = getResource(editorMixin.editor).catch((cause) => {
|
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>
|
<div class="ac-header__icon"><Avatar size={'medium'} /></div>
|
||||||
<span class="ac-header__title">{name}</span>
|
<span class="ac-header__title">{name}</span>
|
||||||
</div>
|
</div>
|
||||||
<ActionIcon icon={IconClose} size={'medium'} action={() => dispatch('close')} />
|
<ActionIcon
|
||||||
|
icon={IconClose}
|
||||||
|
size={'medium'}
|
||||||
|
action={(_) => {
|
||||||
|
dispatch('close')
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if contentType && contentType.startsWith('image/')}
|
{#if contentType && contentType.startsWith('image/')}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anticrm/platform": "~0.6.6",
|
"@anticrm/platform": "~0.6.6",
|
||||||
"@anticrm/core": "~0.6.16",
|
"@anticrm/core": "~0.6.16"
|
||||||
"just-clone": "^3.2.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ import core, {
|
|||||||
WithLookup,
|
WithLookup,
|
||||||
toFindResult
|
toFindResult
|
||||||
} from '@anticrm/core'
|
} from '@anticrm/core'
|
||||||
import justClone from 'just-clone'
|
|
||||||
|
|
||||||
interface Query {
|
interface Query {
|
||||||
_class: Ref<Class<Doc>>
|
_class: Ref<Class<Doc>>
|
||||||
@ -325,13 +324,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
* Clone document with respect to mixin inner document cloning.
|
* Clone document with respect to mixin inner document cloning.
|
||||||
*/
|
*/
|
||||||
private clone<T extends Doc>(results: T[]): T[] {
|
private clone<T extends Doc>(results: T[]): T[] {
|
||||||
const result: T[] = []
|
return this.getHierarchy().clone(results) as 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refresh (q: Query): Promise<void> {
|
private async refresh (q: Query): Promise<void> {
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
"@anticrm/activity-resources": "~0.6.0",
|
"@anticrm/activity-resources": "~0.6.0",
|
||||||
"@anticrm/activity": "~0.6.0",
|
"@anticrm/activity": "~0.6.0",
|
||||||
"@anticrm/contact": "~0.6.5",
|
"@anticrm/contact": "~0.6.5",
|
||||||
"just-clone": "^3.2.1",
|
|
||||||
"@anticrm/core": "~0.6.16"
|
"@anticrm/core": "~0.6.16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
import presentation, { createQuery, getClient } from '@anticrm/presentation'
|
import presentation, { createQuery, getClient } from '@anticrm/presentation'
|
||||||
import { Button, Grid, Icon, Label, ToggleWithLabel } from '@anticrm/ui'
|
import { Button, Grid, Icon, Label, ToggleWithLabel } from '@anticrm/ui'
|
||||||
import notification from '../plugin'
|
import notification from '../plugin'
|
||||||
import justClone from 'just-clone'
|
|
||||||
|
|
||||||
const accountId = getCurrentAccount()._id
|
const accountId = getCurrentAccount()._id
|
||||||
const typeQuery = createQuery()
|
const typeQuery = createQuery()
|
||||||
@ -42,7 +41,7 @@
|
|||||||
providersQuery.query(notification.class.NotificationProvider, {}, (res) => (providers = res))
|
providersQuery.query(notification.class.NotificationProvider, {}, (res) => (providers = res))
|
||||||
settingsQuery.query(notification.class.NotificationSetting, { space }, (res) => {
|
settingsQuery.query(notification.class.NotificationSetting, { space }, (res) => {
|
||||||
settings = convertToMap(res)
|
settings = convertToMap(res)
|
||||||
oldSettings = convertToMap(justClone(res))
|
oldSettings = convertToMap(client.getHierarchy().clone(res))
|
||||||
})
|
})
|
||||||
|
|
||||||
function convertToMap (
|
function convertToMap (
|
||||||
|
@ -160,7 +160,7 @@ function ShowPopup (
|
|||||||
props?: Record<string, any>
|
props?: Record<string, any>
|
||||||
}
|
}
|
||||||
): void {
|
): void {
|
||||||
const docs = Array.isArray(doc) ? doc : [doc]
|
const docs = Array.isArray(doc) ? doc : doc !== undefined ? [doc] : []
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
let cprops = {
|
let cprops = {
|
||||||
...(props?.props ?? {})
|
...(props?.props ?? {})
|
||||||
|
@ -98,8 +98,7 @@ export async function doNavigate (
|
|||||||
if (ex === undefined) {
|
if (ex === undefined) {
|
||||||
const r = await client.findOne(props.spaceClass, {})
|
const r = await client.findOne(props.spaceClass, {})
|
||||||
if (r !== undefined) {
|
if (r !== undefined) {
|
||||||
loc.path[3] = r._id
|
loc.path[2] = r._id
|
||||||
navigate(loc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user