Query update fix (#728)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov
2021-12-24 10:03:50 +01:00
committed by GitHub
parent ceaadd65ff
commit a40b9331df
8 changed files with 61 additions and 53 deletions
@@ -19,7 +19,6 @@
import type { Viewlet } from '@anticrm/view'
import { Component } from '@anticrm/ui'
export let _class: Ref<Class<Doc>>
export let space: Ref<Space>
export let search: string
@@ -27,16 +26,18 @@
</script>
{#if viewlet}
<div class="container">
<Component is={viewlet.$lookup?.descriptor?.component} props={ {
_class,
space,
open: viewlet.open,
options: viewlet.options,
config: viewlet.config,
search
} } />
</div>
{#key space}
<div class="container">
<Component is={viewlet.$lookup?.descriptor?.component} props={ {
_class,
space,
open: viewlet.open,
options: viewlet.options,
config: viewlet.config,
search
} } />
</div>
{/key}
{/if}
<style lang="scss">
@@ -32,6 +32,7 @@
export let createItemDialog: AnyComponent | undefined
export let search: string
export let viewlet: WithLookup<Viewlet> | undefined
export let viewlets: WithLookup<Viewlet>[] = []
const client = getClient()
const query = createQuery()
@@ -39,27 +40,6 @@
$: query.query(core.class.Space, { _id: spaceId }, result => { space = result[0] })
function onSearch(ev: Event) {
search = (ev.target as HTMLInputElement).value
}
let viewlets: WithLookup<Viewlet>[] = []
async function getViewlets(attachTo: Ref<Class<Doc>>): Promise<void> {
viewlets = await client.findAll(view.class.Viewlet, { attachTo }, { lookup: {
descriptor: core.class.Class
}})
}
$: if (_class) {
getViewlets(_class)
}
function resetSelectedViewlet (_space: Ref<Space> | undefined) {
selectedViewlet = 0
}
$: resetSelectedViewlet(spaceId)
function showCreateDialog(ev: Event) {
showPopup(createItemDialog as AnyComponent, { space: spaceId }, ev.target as HTMLElement)
}
@@ -82,7 +62,7 @@
{/each}
</div>
{/if}
<EditWithIcon icon={IconSearch} placeholder={'Search'} on:change={onSearch}/>
<EditWithIcon icon={IconSearch} placeholder={'Search'} bind:value={search} />
{#if createItemDialog}
<Button label={workbench.string.Create} primary={true} size={'small'} on:click={(ev) => showCreateDialog(ev)}/>
{/if}
@@ -14,9 +14,10 @@
-->
<script lang="ts">
import type { Ref, Space, WithLookup } from '@anticrm/core'
import core, { Class, Doc, Ref, Space, WithLookup } from '@anticrm/core'
import { getClient } from '@anticrm/presentation'
import type { AnyComponent } from '@anticrm/ui'
import type { Viewlet } from '@anticrm/view'
import view, { Viewlet } from '@anticrm/view'
import type { ViewConfiguration } from '@anticrm/workbench'
import SpaceContent from './SpaceContent.svelte'
@@ -28,7 +29,25 @@
let search: string = ''
let viewlet: WithLookup<Viewlet> | undefined = undefined
let space: Ref<Space> | undefined = undefined
let _class: Ref<Class<Doc>> | undefined = undefined
const client = getClient()
let viewlets: WithLookup<Viewlet>[] = []
async function update(attachTo?: Ref<Class<Doc>>, currentSpace?: Ref<Space>): Promise<void> {
if (attachTo) {
viewlets = await client.findAll(view.class.Viewlet, { attachTo }, { lookup: {
descriptor: core.class.Class
}})
_class = attachTo
}
viewlet = viewlets[0]
space = currentSpace
}
$: update(currentView?.class, currentSpace)
function resetSearch (_space: Ref<Space> | undefined): void {
search = ''
@@ -37,7 +56,7 @@
$: resetSearch(currentSpace)
</script>
<SpaceHeader spaceId={currentSpace} _class={currentView?.class} {createItemDialog} bind:search={search} bind:viewlet={viewlet} />
{#if currentView && currentSpace}
<SpaceContent space={currentSpace} _class={currentView.class} {search} {viewlet} />
<SpaceHeader spaceId={space} {_class} {viewlets} {createItemDialog} bind:search={search} bind:viewlet={viewlet} />
{#if _class && space}
<SpaceContent {space} {_class} {search} {viewlet} />
{/if}
@@ -65,8 +65,8 @@
return
}
const space = (await client.findAll(core.class.Space, { _id: currentFolder }))[0]
currentSpace = currentFolder
const space = (await client.findAll(core.class.Space, { _id: currentSpace }))[0]
if (space) {
const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]
const view = client.getHierarchy().as(spaceClass, workbench.mixin.SpaceView)