diff --git a/plugins/tracker-resources/src/components/issues/IssuesList.svelte b/plugins/tracker-resources/src/components/issues/IssuesList.svelte index c7eef63b03..fa38a5d090 100644 --- a/plugins/tracker-resources/src/components/issues/IssuesList.svelte +++ b/plugins/tracker-resources/src/components/issues/IssuesList.svelte @@ -108,32 +108,6 @@ dispatch('row-focus', object) } - export const onElementSelected = (offset: 1 | -1 | 0, docObject?: Doc) => { - let position = - (docObject !== undefined ? combinedGroupedIssues.findIndex((x) => x._id === docObject?._id) : selectedRowIndex) ?? - -1 - - position += offset - - if (position < 0) { - position = 0 - } - - if (position >= combinedGroupedIssues.length) { - position = combinedGroupedIssues.length - 1 - } - - const objectRef = objectRefs[position] - - selectedRowIndex = position - - handleRowFocused(combinedGroupedIssues[position]) - - if (objectRef) { - objectRef.scrollIntoView({ behavior: 'auto', block: 'nearest' }) - } - } - const handleNewIssueAdded = (event: MouseEvent, category: any) => { if (!currentSpace) { return diff --git a/plugins/tracker-resources/src/components/issues/IssuesListBrowser.svelte b/plugins/tracker-resources/src/components/issues/IssuesListBrowser.svelte index af423c929c..39e11009d0 100644 --- a/plugins/tracker-resources/src/components/issues/IssuesListBrowser.svelte +++ b/plugins/tracker-resources/src/components/issues/IssuesListBrowser.svelte @@ -41,11 +41,7 @@ export let groupedIssues: { [key: string | number | symbol]: Issue[] } = {} export let loadingProps: LoadingProps | undefined = undefined - const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => { - if (dir === 'vertical') { - issuesList.onElementSelected(offset, of) - } - }) + const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => {}) let issuesList: IssuesList diff --git a/plugins/tracker-resources/src/components/issues/IssuesView.svelte b/plugins/tracker-resources/src/components/issues/IssuesView.svelte index 48f1f6ad1b..c19410e5ed 100644 --- a/plugins/tracker-resources/src/components/issues/IssuesView.svelte +++ b/plugins/tracker-resources/src/components/issues/IssuesView.svelte @@ -24,7 +24,6 @@ function updateSearchQuery (search: string): void { searchQuery = search === '' ? { ...query } : { ...query, $search: search } } - $: updateSearchQuery(search) $: if (query) updateSearchQuery(search) let resultQuery: DocumentQuery = { ...searchQuery } diff --git a/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte b/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte index 43db074c03..e645b0256c 100644 --- a/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte +++ b/plugins/tracker-resources/src/components/issues/edit/EditIssue.svelte @@ -20,7 +20,7 @@ import { getResource } from '@hcengineering/platform' import presentation, { createQuery, getClient, MessageViewer } from '@hcengineering/presentation' import setting, { settingId } from '@hcengineering/setting' - import type { Issue, IssueStatus, Team } from '@hcengineering/tracker' + import type { Issue, IssuesGrouping, IssuesOrdering, IssueStatus, Team } from '@hcengineering/tracker' import { Button, EditBox, @@ -34,7 +34,14 @@ showPopup, Spinner } from '@hcengineering/ui' - import { ContextMenu, UpDownNavigator } from '@hcengineering/view-resources' + import { + ContextMenu, + focusStore, + ListSelectionProvider, + SelectDirection, + UpDownNavigator, + viewOptionsStore + } from '@hcengineering/view-resources' import { createEventDispatcher, onDestroy, onMount } from 'svelte' import { generateIssueShortLink, getIssueId } from '../../../issues' import tracker from '../../../plugin' @@ -43,13 +50,15 @@ import CopyToClipboard from './CopyToClipboard.svelte' import SubIssues from './SubIssues.svelte' import SubIssueSelector from './SubIssueSelector.svelte' + import { groupBy as groupByFunc, issuesOrderKeyMap, issuesSortOrderMap } from '../../../utils' + import contact from '@hcengineering/contact' export let _id: Ref export let _class: Ref> let lastId: Ref = _id let lastClass: Ref> = _class - const query = createQuery() + const queryClient = createQuery() const statusesQuery = createQuery() const dispatch = createEventDispatcher() const client = getClient() @@ -63,6 +72,14 @@ let isEditing = false let descriptionBox: AttachmentStyledBox + let groupBy: IssuesGrouping + let orderBy: IssuesOrdering + let shouldShowSubIssues: boolean + $: ({ groupBy, orderBy, shouldShowSubIssues } = $viewOptionsStore) + $: orderByKey = issuesOrderKeyMap[orderBy] + $: subIssuesQuery = shouldShowSubIssues ? {} : { attachedTo: tracker.ids.NoParent } + $: query = { space: issue?.space } + const notificationClient = getResource(notification.function.GetNotificationClient).then((res) => res()) $: read(_id) @@ -82,7 +99,7 @@ $: _id && _class && - query.query( + queryClient.query( _class, { _id }, async (result) => { @@ -110,6 +127,72 @@ $: isDescriptionEmpty = !new DOMParser().parseFromString(description, 'text/html').documentElement.innerText?.trim() $: parentIssue = issue?.$lookup?.attachedTo + let issues: WithLookup[] = [] + let neighbourIssues: Issue[] = [] + const issuesQuery = createQuery() + const subIssuesQueryClient = createQuery() + + $: if (parentIssue) { + subIssuesQueryClient.query( + tracker.class.Issue, + { attachedTo: parentIssue?._id }, + async (result) => (neighbourIssues = result ?? []), + { + sort: { rank: SortingOrder.Descending } + } + ) + } else { + issuesQuery.query( + tracker.class.Issue, + { ...subIssuesQuery, ...query }, + (result) => { + issues = result + }, + { + sort: { [orderByKey]: issuesSortOrderMap[orderByKey] }, + lookup: { + assignee: contact.class.Employee, + status: tracker.class.IssueStatus, + space: tracker.class.Team, + sprint: tracker.class.Sprint, + _id: { + subIssues: tracker.class.Issue + } + } + } + ) + } + + $: groupedIssues = groupByFunc(issues, groupBy) + $: flatGroupedIssues = Object.values(groupedIssues ?? {}).flat(1) + $: issuesToNavigate = parentIssue ? neighbourIssues : flatGroupedIssues + + const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => { + if (dir === 'vertical') { + if (groupedIssues) { + const selectedRowIndex = listProvider.current($focusStore) + let position = + (of !== undefined ? issuesToNavigate.findIndex((x) => x._id === of?._id) : selectedRowIndex) ?? -1 + + position -= offset + + if (position < 0) { + position = 0 + } + + if (position >= issuesToNavigate.length) { + position = issuesToNavigate.length - 1 + } + + listProvider.updateFocus(issuesToNavigate[position]) + } + } + }) + + $: if (issue) listProvider.updateFocus(issue) + + $: listProvider.update(issuesToNavigate) + function edit (ev: MouseEvent) { ev.preventDefault() @@ -265,7 +348,6 @@ {#if currentTeam !== undefined && issueStatuses !== undefined} diff --git a/plugins/tracker-resources/src/components/issues/edit/SubIssues.svelte b/plugins/tracker-resources/src/components/issues/edit/SubIssues.svelte index 1bab7f83f6..3e45e31f8a 100644 --- a/plugins/tracker-resources/src/components/issues/edit/SubIssues.svelte +++ b/plugins/tracker-resources/src/components/issues/edit/SubIssues.svelte @@ -13,11 +13,10 @@ // limitations under the License. -->
@@ -125,15 +90,7 @@ {#if hasSubIssues}
- { - listProvider.updateFocus(event.detail ?? undefined) - }} - /> +
{/if}