UBER-880 Use space presenter for starred spaces (#3717)

Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2023-09-20 00:21:22 +07:00 committed by GitHub
parent 7e0fe4e91f
commit fd5436536d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 31 deletions

View File

@ -1,5 +1,5 @@
<!--
// Copyright © 2022 Hardcore Engineering Inc.
// Copyright © 2022, 2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
@ -162,7 +162,15 @@
on:select={(res) => (menuSelection = res.detail)}
/>
{#if starred.length}
<StarredNav label={preference.string.Starred} spaces={starred} on:space {currentSpace} />
<StarredNav
label={preference.string.Starred}
spaces={starred}
models={model.spaces}
on:space
{currentSpace}
{currentSpecial}
deselect={menuSelection}
/>
{/if}
{#each model.spaces as m, i (m.label)}

View File

@ -1,5 +1,6 @@
<!--
// Copyright © 2020 Anticrm Platform Contributors.
// Copyright © 2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
@ -13,7 +14,7 @@
// limitations under the License.
-->
<script lang="ts">
import type { Class, Doc, Ref, Space } from '@hcengineering/core'
import type { Doc, Ref, Space } from '@hcengineering/core'
import core from '@hcengineering/core'
import { DocUpdates } from '@hcengineering/notification'
import { NotificationClientImpl } from '@hcengineering/notification-resources'
@ -23,7 +24,6 @@
import {
Action,
AnyComponent,
AnySvelteComponent,
IconAdd,
IconEdit,
IconSearch,
@ -31,12 +31,11 @@
navigate,
showPopup
} from '@hcengineering/ui'
import view from '@hcengineering/view'
import { NavLink, TreeItem, TreeNode, getActions as getContributedActions } from '@hcengineering/view-resources'
import { SpacesNavModel } from '@hcengineering/workbench'
import { createEventDispatcher } from 'svelte'
import plugin from '../../plugin'
import { classIcon, getSpaceName } from '../../utils'
import { classIcon, getSpaceName, getSpacePresenter } from '../../utils'
import TreeSeparator from './TreeSeparator.svelte'
export let model: SpacesNavModel
@ -100,7 +99,6 @@
const notificationClient = NotificationClientImpl.getClient()
const docUpdates = notificationClient.docUpdatesStore
const hierarchy = client.getHierarchy()
function isChanged (space: Space, docUpdates: Map<Ref<Doc>, DocUpdates>): boolean {
const update = docUpdates.get(space._id)
@ -116,13 +114,6 @@
return result
}
async function getPresenter (_class: Ref<Class<Doc>>): Promise<AnySvelteComponent | undefined> {
const value = hierarchy.classHierarchyMixin(_class, view.mixin.SpacePresenter)
if (value?.presenter !== undefined) {
return await getResource(value.presenter)
}
}
let visibleIf: ((space: Space) => Promise<boolean>) | undefined
$: if (model.visibleIf) {
@ -157,7 +148,7 @@
shortDropbox={model.specials !== undefined}
>
{#each filteredSpaces as space, i (space._id)}
{#await getPresenter(space._class) then presenter}
{#await getSpacePresenter(client, space._class) then presenter}
{#if separate && model.specials && i !== 0}<TreeSeparator line />{/if}
{#if model.specials && presenter}
<svelte:component this={presenter} {space} {model} {currentSpace} {currentSpecial} {getActions} {deselect} />

View File

@ -1,5 +1,5 @@
<!--
// Copyright © 2022 Hardcore Engineering Inc.
// Copyright © 2022, 2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
@ -23,11 +23,16 @@
import { Action, IconEdit } from '@hcengineering/ui'
import view from '@hcengineering/view'
import { NavLink, TreeItem, TreeNode, getActions as getContributedActions } from '@hcengineering/view-resources'
import { classIcon, getSpaceName } from '../../utils'
import { SpacesNavModel } from '@hcengineering/workbench'
import { classIcon, getSpaceName, getSpacePresenter } from '../../utils'
export let label: IntlString
export let currentSpace: Ref<Space> | undefined
export let spaces: Space[]
export let models: SpacesNavModel[]
export let currentSpace: Ref<Space> | undefined
export let currentSpecial: string | undefined
export let deselect: boolean = false
const client = getClient()
const unStarSpace: Action = {
@ -85,18 +90,25 @@
<TreeNode {label} parent actions={async () => [unStarAll]}>
{#each spaces as space (space._id)}
{#await getSpaceName(client, space) then name}
<NavLink space={space._id}>
<TreeItem
indent={'ml-2'}
_id={space._id}
title={name}
icon={classIcon(client, space._class)}
selected={currentSpace === space._id}
actions={() => getActions(space)}
bold={isChanged(space, $docUpdates)}
/>
</NavLink>
{@const model = models.find((p) => p.spaceClass === space._class)}
{#await getSpacePresenter(client, space._class) then presenter}
{#if presenter && model}
<svelte:component this={presenter} {space} {model} {currentSpace} {currentSpecial} {getActions} {deselect} />
{:else}
{#await getSpaceName(client, space) then name}
<NavLink space={space._id}>
<TreeItem
indent={'ml-2'}
_id={space._id}
title={name}
icon={classIcon(client, space._class)}
selected={currentSpace === space._id}
actions={() => getActions(space)}
bold={isChanged(space, $docUpdates)}
/>
</NavLink>
{/await}
{/if}
{/await}
{/each}
</TreeNode>

View File

@ -1,6 +1,6 @@
//
// Copyright © 2020, 2021 Anticrm Platform Contributors.
// Copyright © 2021 Hardcore Engineering Inc.
// Copyright © 2021, 2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
@ -22,6 +22,7 @@ import { getResource, setMetadata } from '@hcengineering/platform'
import preference from '@hcengineering/preference'
import { closeClient, getClient } from '@hcengineering/presentation'
import {
AnySvelteComponent,
closePanel,
fetchMetadataLocalStorage,
getCurrentLocation,
@ -205,3 +206,13 @@ export function signOut (): void {
void closeClient()
navigate({ path: [loginId] })
}
export async function getSpacePresenter (
client: Client,
_class: Ref<Class<Doc>>
): Promise<AnySvelteComponent | undefined> {
const value = client.getHierarchy().classHierarchyMixin(_class, view.mixin.SpacePresenter)
if (value?.presenter !== undefined) {
return await getResource(value.presenter)
}
}