Space view select viewlet with custom header (#1378)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-04-12 21:33:38 +06:00 committed by GitHub
parent 13750963c8
commit 17ef11daf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,11 +16,10 @@
<script lang="ts">
import core, { Class, Doc, Ref, Space, WithLookup } from '@anticrm/core'
import { IntlString } from '@anticrm/platform'
import { createQuery, getClient } from '@anticrm/presentation'
import { AnyComponent, Component } from '@anticrm/ui'
import view, { Viewlet } from '@anticrm/view'
import { getClient } from '@anticrm/presentation'
import { AnyComponent,Component } from '@anticrm/ui'
import view,{ Viewlet } from '@anticrm/view'
import type { ViewConfiguration } from '@anticrm/workbench'
import SpaceContent from './SpaceContent.svelte'
import SpaceHeader from './SpaceHeader.svelte'
@ -33,34 +32,38 @@
let viewlet: WithLookup<Viewlet> | undefined = undefined
let space: Space | undefined
let _class: Ref<Class<Doc>> | undefined = undefined
let header: AnyComponent | undefined
const client = getClient()
let viewlets: WithLookup<Viewlet>[] = []
async function update (attachTo?: Ref<Class<Doc>>): Promise<void> {
$: update(currentSpace, currentView?.class)
async function update (currentSpace?: Ref<Space>, attachTo?: Ref<Class<Doc>>): Promise<void> {
if (currentSpace === undefined) {
space = undefined
return
}
space = await client.findOne(core.class.Space, { _id: currentSpace })
if (space === undefined) {
header = undefined
} else {
header = await getHeader(space._class)
}
if (attachTo) {
viewlets = await client.findAll(view.class.Viewlet, { attachTo }, {
lookup: {
descriptor: core.class.Class
}
})
if (header !== undefined) {
viewlet = viewlets[0]
}
_class = attachTo
}
}
$: update(currentView?.class)
const query = createQuery()
$: currentSpace && query.query(core.class.Space, {
_id: currentSpace
}, (res) => {
space = res[0]
}, {
limit: 1
})
const hierarchy = client.getHierarchy()
async function getHeader (_class: Ref<Class<Space>>): Promise<AnyComponent | undefined> {
const clazz = hierarchy.getClass(_class)
@ -71,12 +74,10 @@
</script>
{#if _class && space}
{#await getHeader(space._class) then header}
{#if header}
<Component is={header} props={{ spaceId: space._id, viewlets, createItemDialog, createItemLabel }} />
{:else}
<SpaceHeader spaceId={space._id} {viewlets} {createItemDialog} {createItemLabel} bind:search={search} bind:viewlet={viewlet} />
{/if}
{/await}
{#if header}
<Component is={header} props={{ spaceId: space._id, viewlets, createItemDialog, createItemLabel }} />
{:else}
<SpaceHeader spaceId={space._id} {viewlets} {createItemDialog} {createItemLabel} bind:search={search} bind:viewlet={viewlet} />
{/if}
<SpaceContent space={space._id} {_class} {search} {viewlet} />
{/if}