Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up down navigator #3185

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@
await save()
}
;[issue] = result
title = issue.title
description = issue.description
currentProject = issue.$lookup?.space
if (issue) {
title = issue.title
description = issue.description
currentProject = issue.$lookup?.space
}
},
{ lookup: { attachedTo: tracker.class.Issue, space: tracker.class.Project } }
)
Expand Down
51 changes: 26 additions & 25 deletions plugins/view-resources/src/components/UpDownNavigator.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<script lang="ts">
import { Doc } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import ui, {
Button,
closeTooltip,
IconDownOutline,
IconNavPrev,
IconUpOutline,
navigate,
panelstore
} from '@hcengineering/ui'
import ui, { Button, closeTooltip, IconDownOutline, IconNavPrev, IconUpOutline, navigate } from '@hcengineering/ui'
import { tick } from 'svelte'
import { select } from '../actionImpl'
import view from '../plugin'
import { focusStore } from '../selection'
import { getObjectLinkFragment } from '../utils'

Expand All @@ -22,10 +15,16 @@
async function next (evt: Event, pn: boolean): Promise<void> {
select(evt, pn ? 1 : -1, element, 'vertical')
await tick()
if ($focusStore.focus !== undefined && $panelstore.panel !== undefined) {
if ($focusStore.focus !== undefined) {
const doc = await client.findOne($focusStore.focus._class, { _id: $focusStore.focus._id })
if (doc !== undefined) {
const link = await getObjectLinkFragment(client.getHierarchy(), doc, {}, $panelstore.panel.component)
const component = client.getHierarchy().classHierarchyMixin(doc._class, view.mixin.ObjectPanel)
const link = await getObjectLinkFragment(
client.getHierarchy(),
doc,
{},
component?.component ?? view.component.EditDoc
)
navigate(link)
}
}
Expand All @@ -39,20 +38,22 @@
$: select(undefined, 0, element, 'vertical')
</script>

<Button
focusIndex={10005}
icon={IconDownOutline}
kind={'secondary'}
size={'medium'}
on:click={(evt) => next(evt, true)}
/>
<Button
focusIndex={10006}
icon={IconUpOutline}
kind={'secondary'}
size={'medium'}
on:click={(evt) => next(evt, false)}
/>
{#if $focusStore.focus !== undefined && $focusStore.provider !== undefined}
<Button
focusIndex={10005}
icon={IconDownOutline}
kind={'secondary'}
size={'medium'}
on:click={(evt) => next(evt, true)}
/>
<Button
focusIndex={10006}
icon={IconUpOutline}
kind={'secondary'}
size={'medium'}
on:click={(evt) => next(evt, false)}
/>
{/if}
<Button
focusIndex={10007}
showTooltip={{ label: ui.string.Back, direction: 'bottom' }}
Expand Down
10 changes: 9 additions & 1 deletion plugins/view-resources/src/selection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Doc } from '@hcengineering/core'
import { Doc, Ref } from '@hcengineering/core'
import { panelstore } from '@hcengineering/ui'
import { onDestroy } from 'svelte'
import { Unsubscriber, derived, writable } from 'svelte/store'
Expand Down Expand Up @@ -124,6 +124,14 @@ export class ListSelectionProvider implements SelectionFocusProvider {
}
}

static Find (_id: Ref<Doc>): ListSelectionProvider | undefined {
for (const provider of providers) {
if (provider.docs().findIndex((p) => p._id === _id) !== -1) {
return provider
}
}
}

static Pop (): void {
if (providers.length === 0) return
const last = providers[providers.length - 1]
Expand Down
49 changes: 35 additions & 14 deletions plugins/workbench-resources/src/components/Workbench.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@
showPopup
} from '@hcengineering/ui'
import view from '@hcengineering/view'
import { ActionContext, ActionHandler, NavLink, migrateViewOpttions } from '@hcengineering/view-resources'
import {
ActionContext,
ActionHandler,
ListSelectionProvider,
NavLink,
migrateViewOpttions,
updateFocus
} from '@hcengineering/view-resources'
import type { Application, NavigatorModel, SpecialNavModel, ViewConfiguration } from '@hcengineering/workbench'
import { getContext, onDestroy, onMount, tick } from 'svelte'
import { get } from 'svelte/store'
Expand Down Expand Up @@ -314,25 +321,39 @@
if (fragment !== currentFragment) {
currentFragment = fragment
if (fragment !== undefined && fragment.trim().length > 0) {
const props = decodeURIComponent(fragment).split('|')

if (props.length >= 3) {
openPanel(
props[0] as AnyComponent,
props[1],
props[2],
(props[3] ?? undefined) as PopupAlignment,
(props[4] ?? undefined) as AnyComponent
)
} else {
closePanel(false)
}
setOpenPanelFocus(fragment)
} else {
closePanel()
}
}
}

async function setOpenPanelFocus (fragment: string): Promise<void> {
const props = decodeURIComponent(fragment).split('|')

if (props.length >= 3) {
const doc = await client.findOne(props[2] as Ref<Class<Doc>>, { _id: props[1] as Ref<Doc> })
if (doc !== undefined) {
const provider = ListSelectionProvider.Find(doc._id)
updateFocus({
provider,
focus: doc
})
openPanel(
props[0] as AnyComponent,
props[1],
props[2],
(props[3] ?? undefined) as PopupAlignment,
(props[4] ?? undefined) as AnyComponent
)
} else {
closePanel(false)
}
} else {
closePanel(false)
}
}

function clear (level: number): void {
switch (level) {
case 1:
Expand Down