From 473e57d3283465e37d1e1b085450ee39809dd144 Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Tue, 1 Oct 2024 16:19:07 +0400 Subject: [PATCH 1/7] ezqms-1213: gets rid of tosorted (#6775) Signed-off-by: Alexey Zinoviev --- .../src/components/document/DocumentHistory.svelte | 2 +- plugins/questions-resources/package.json | 1 + .../src/components/OrderingAnswerDataEditor.svelte | 6 +++--- .../src/functions/MultipleChoiceAssessmentAssess.ts | 4 +++- .../recruit-resources/src/components/EditVacancy.svelte | 4 ++-- .../src/components/NotificationApplicantPresenter.svelte | 8 ++++++-- .../src/components/OptimizeSkills.svelte | 5 +++-- .../recruit-resources/src/components/icons/Vacancy.svelte | 4 +++- .../src/components/team/calendar/TeamCalendarDay.svelte | 4 ++-- plugins/training-resources/package.json | 1 + .../src/components/SentRequestCompletionPopup.svelte | 2 +- .../src/functions/trainingAttemptStateSort.ts | 6 +++--- .../training-resources/src/functions/trainingStateSort.ts | 4 +++- plugins/workbench-resources/package.json | 1 + .../src/components/statistics/MetricsInfo.svelte | 2 +- 15 files changed, 34 insertions(+), 20 deletions(-) diff --git a/plugins/controlled-documents-resources/src/components/document/DocumentHistory.svelte b/plugins/controlled-documents-resources/src/components/document/DocumentHistory.svelte index ea9293a2ec..e616ca62d4 100644 --- a/plugins/controlled-documents-resources/src/components/document/DocumentHistory.svelte +++ b/plugins/controlled-documents-resources/src/components/document/DocumentHistory.svelte @@ -52,7 +52,7 @@ (doc.major === $controlledDocument.major && doc.minor <= $controlledDocument.minor) ) }) - .toSorted(documentCompareFn) + .sort(documentCompareFn) function getDescription (cc: ChangeControl | undefined): string { if (cc === undefined) { diff --git a/plugins/questions-resources/package.json b/plugins/questions-resources/package.json index 2784c503e5..50662e7667 100644 --- a/plugins/questions-resources/package.json +++ b/plugins/questions-resources/package.json @@ -7,6 +7,7 @@ "build": "compile ui", "build:watch": "compile ui", "format": "format src", + "svelte-check": "do-svelte-check", "_phase:build": "compile ui", "_phase:format": "format src", "_phase:validate": "compile validate" diff --git a/plugins/questions-resources/src/components/OrderingAnswerDataEditor.svelte b/plugins/questions-resources/src/components/OrderingAnswerDataEditor.svelte index 3b7a3b64ac..70e2291ea6 100644 --- a/plugins/questions-resources/src/components/OrderingAnswerDataEditor.svelte +++ b/plugins/questions-resources/src/components/OrderingAnswerDataEditor.svelte @@ -45,12 +45,12 @@ $: if (showDiff && assessmentData !== null) { indices = assessmentData.correctOrder .map((position, index) => [position, index]) - .toSorted(([aPosition], [bPosition]) => (aPosition > bPosition ? 1 : aPosition < bPosition ? -1 : 0)) + .sort(([aPosition], [bPosition]) => (aPosition > bPosition ? 1 : aPosition < bPosition ? -1 : 0)) .map(([_, index]) => index) as [number, ...number[]] } else if (answerData !== null) { indices = answerData.order .map((position, index) => [position, index]) - .toSorted(([aPosition], [bPosition]) => (aPosition > bPosition ? 1 : aPosition < bPosition ? -1 : 0)) + .sort(([aPosition], [bPosition]) => (aPosition > bPosition ? 1 : aPosition < bPosition ? -1 : 0)) .map(([_, index]) => index) as [number, ...number[]] } else { indices = questionData.options.map((_, index) => index) as [number, ...number[]] @@ -67,7 +67,7 @@ indices = moveItem(indices, from, to) const order = indices .map((initialIndex, index) => [initialIndex, index]) - .toSorted(([aInitialIndex], [bInitialIndex]) => + .sort(([aInitialIndex], [bInitialIndex]) => aInitialIndex > bInitialIndex ? 1 : aInitialIndex < bInitialIndex ? -1 : 0 ) .map(([_, index]) => index + 1) as [OrderingPosition, ...OrderingPosition[]] diff --git a/plugins/questions-resources/src/functions/MultipleChoiceAssessmentAssess.ts b/plugins/questions-resources/src/functions/MultipleChoiceAssessmentAssess.ts index 5fe41d4070..c5d51863b3 100644 --- a/plugins/questions-resources/src/functions/MultipleChoiceAssessmentAssess.ts +++ b/plugins/questions-resources/src/functions/MultipleChoiceAssessmentAssess.ts @@ -16,6 +16,8 @@ MultipleChoiceAssessmentAnswer return { score: // eslint-disable-next-line @typescript-eslint/require-array-sort-compare - answerData.selectedIndices.toSorted().join('~') === assessmentData.correctIndices.toSorted().join('~') ? 100 : 0 + answerData.selectedIndices.slice().sort().join('~') === assessmentData.correctIndices.slice().sort().join('~') + ? 100 + : 0 } } diff --git a/plugins/recruit-resources/src/components/EditVacancy.svelte b/plugins/recruit-resources/src/components/EditVacancy.svelte index 0aed8ae7ed..ede94190d3 100644 --- a/plugins/recruit-resources/src/components/EditVacancy.svelte +++ b/plugins/recruit-resources/src/components/EditVacancy.svelte @@ -15,7 +15,7 @@ --> diff --git a/plugins/recruit-resources/src/components/OptimizeSkills.svelte b/plugins/recruit-resources/src/components/OptimizeSkills.svelte index 14ad404157..2b726016cd 100644 --- a/plugins/recruit-resources/src/components/OptimizeSkills.svelte +++ b/plugins/recruit-resources/src/components/OptimizeSkills.svelte @@ -232,7 +232,8 @@ goodTagMap = toIdMap(goodTags) const goodSortedTags = goodTags - .toSorted((a, b) => b.title.length - a.title.length) + .slice() + .sort((a, b) => b.title.length - a.title.length) .filter((t) => t.title.length > 2) const goodSortedTagsTitles = new Map, string>() processed = -1 @@ -251,7 +252,7 @@ const tagElementIds = new Map, TagUpdatePlan['elements'][0]>() - for (const tag of tagElements.toSorted((a, b) => prepareTitle(a.title).length - prepareTitle(b.title).length)) { + for (const tag of tagElements.slice().sort((a, b) => prepareTitle(a.title).length - prepareTitle(b.title).length)) { processed++ const refs = allRefs.filter((it) => it.tag === tag._id) if (goodTagMap.has(tag._id)) { diff --git a/plugins/recruit-resources/src/components/icons/Vacancy.svelte b/plugins/recruit-resources/src/components/icons/Vacancy.svelte index 82205374d1..e6d5113fc7 100644 --- a/plugins/recruit-resources/src/components/icons/Vacancy.svelte +++ b/plugins/recruit-resources/src/components/icons/Vacancy.svelte @@ -14,7 +14,9 @@ // limitations under the License. --> diff --git a/plugins/time-resources/src/components/team/calendar/TeamCalendarDay.svelte b/plugins/time-resources/src/components/team/calendar/TeamCalendarDay.svelte index 4981733440..c0a22b32d2 100644 --- a/plugins/time-resources/src/components/team/calendar/TeamCalendarDay.svelte +++ b/plugins/time-resources/src/components/team/calendar/TeamCalendarDay.svelte @@ -143,14 +143,14 @@ ...gitem.events, ...gitem.busyEvents, ...gitem.busy.slots - ].toSorted((a, b) => a.date - b.date)} + ].sort((a, b) => a.date - b.date)}
{#each Array.from(Array(24).keys()) as hour} {@const _slots = slots .filter((it) => new Date(it.date).getHours() === hour) - .toSorted((a, b) => a.date - b.date)} + .sort((a, b) => a.date - b.date)} {@const cwidth = hourWidths[hour]}
{#each _slots as m, i} diff --git a/plugins/training-resources/package.json b/plugins/training-resources/package.json index 6d851b1da0..727af338fc 100644 --- a/plugins/training-resources/package.json +++ b/plugins/training-resources/package.json @@ -7,6 +7,7 @@ "build": "compile ui", "build:watch": "compile ui", "format": "format src", + "svelte-check": "do-svelte-check", "_phase:build": "compile ui", "_phase:format": "format src", "_phase:validate": "compile validate" diff --git a/plugins/training-resources/src/components/SentRequestCompletionPopup.svelte b/plugins/training-resources/src/components/SentRequestCompletionPopup.svelte index 736716eb1f..ed157c2ced 100644 --- a/plugins/training-resources/src/components/SentRequestCompletionPopup.svelte +++ b/plugins/training-resources/src/components/SentRequestCompletionPopup.svelte @@ -43,7 +43,7 @@ _id: employee._id as Ref, completion: completionMap.get(employee._id) as CompletionMapValue })) - .toSorted((item1, item2) => compareCompletionMapValueState(item1.completion.state, item2.completion.state)) + .sort((item1, item2) => compareCompletionMapValueState(item1.completion.state, item2.completion.state)) }, { sort: { diff --git a/plugins/training-resources/src/functions/trainingAttemptStateSort.ts b/plugins/training-resources/src/functions/trainingAttemptStateSort.ts index 4a67a36802..0ad9eb7aed 100644 --- a/plugins/training-resources/src/functions/trainingAttemptStateSort.ts +++ b/plugins/training-resources/src/functions/trainingAttemptStateSort.ts @@ -9,7 +9,7 @@ export async function trainingAttemptStateSort ( _: TxOperations, states: TrainingAttemptState[] ): Promise { - return states.toSorted( - (state1, state2) => trainingAttemptStateOrder.indexOf(state2) - trainingAttemptStateOrder.indexOf(state1) - ) + return states + .slice() + .sort((state1, state2) => trainingAttemptStateOrder.indexOf(state2) - trainingAttemptStateOrder.indexOf(state1)) } diff --git a/plugins/training-resources/src/functions/trainingStateSort.ts b/plugins/training-resources/src/functions/trainingStateSort.ts index e08898a44e..4c2f0fb14a 100644 --- a/plugins/training-resources/src/functions/trainingStateSort.ts +++ b/plugins/training-resources/src/functions/trainingStateSort.ts @@ -17,5 +17,7 @@ import type { TxOperations } from '@hcengineering/core' import { type TrainingState, trainingStateOrder } from '@hcengineering/training' export async function trainingStateSort (_: TxOperations, states: TrainingState[]): Promise { - return states.toSorted((state1, state2) => trainingStateOrder.indexOf(state1) - trainingStateOrder.indexOf(state2)) + return states + .slice() + .sort((state1, state2) => trainingStateOrder.indexOf(state1) - trainingStateOrder.indexOf(state2)) } diff --git a/plugins/workbench-resources/package.json b/plugins/workbench-resources/package.json index 4e371ccab9..0291371717 100644 --- a/plugins/workbench-resources/package.json +++ b/plugins/workbench-resources/package.json @@ -8,6 +8,7 @@ "build": "compile ui", "build:docs": "api-extractor run --local", "format": "format src", + "svelte-check": "do-svelte-check", "build:watch": "compile ui", "_phase:build": "compile ui", "_phase:format": "format src", diff --git a/plugins/workbench-resources/src/components/statistics/MetricsInfo.svelte b/plugins/workbench-resources/src/components/statistics/MetricsInfo.svelte index 714b0fe849..f862aa7c32 100644 --- a/plugins/workbench-resources/src/components/statistics/MetricsInfo.svelte +++ b/plugins/workbench-resources/src/components/statistics/MetricsInfo.svelte @@ -98,7 +98,7 @@ {/each} {#each Object.entries(metrics.params) as [k, v], i}
- {#each Object.entries(v).toSorted((a, b) => b[1].value / (b[1].operations + 1) - a[1].value / (a[1].operations + 1)) as [kk, vv]} + {#each Object.entries(v).sort((a, b) => b[1].value / (b[1].operations + 1) - a[1].value / (a[1].operations + 1)) as [kk, vv]} {@const childExpandable = vv.topResult !== undefined && vv.topResult.length > 0 && From 47d14885e53875b937954bd9c461e311bebe6ba4 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 2 Oct 2024 12:46:05 +0700 Subject: [PATCH 2/7] UBERF-8324: Fix null in external sync and todos (#6777) Signed-off-by: Andrey Sobolev --- services/github/pod-github/src/sync/pullrequests.ts | 10 ++++++---- services/github/pod-github/src/sync/utils.ts | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/github/pod-github/src/sync/pullrequests.ts b/services/github/pod-github/src/sync/pullrequests.ts index 6851996840..f3a38c9fe5 100644 --- a/services/github/pod-github/src/sync/pullrequests.ts +++ b/services/github/pod-github/src/sync/pullrequests.ts @@ -700,10 +700,12 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS const approvedOrChangesRequested = new Map, PullRequestReviewState>() const reviewStates = new Map, PullRequestReviewState[]>() - const sortedReviews: (Review & { date: number })[] = external.reviews.nodes.map((it) => ({ - ...it, - date: new Date(it.updatedAt ?? it.submittedAt ?? it.createdAt).getTime() - })) + const sortedReviews: (Review & { date: number })[] = external.reviews.nodes + .filter((it) => it != null) + .map((it) => ({ + ...it, + date: new Date(it.updatedAt ?? it.submittedAt ?? it.createdAt).getTime() + })) for (const it of external.latestReviews.nodes) { if (sortedReviews.some((qt) => it.id === qt.id)) { diff --git a/services/github/pod-github/src/sync/utils.ts b/services/github/pod-github/src/sync/utils.ts index dd62c13f0c..21ba8041d7 100644 --- a/services/github/pod-github/src/sync/utils.ts +++ b/services/github/pod-github/src/sync/utils.ts @@ -346,7 +346,7 @@ export async function syncDerivedDocuments ( }) const processed = new Set>() - const _docs = docs(ext) + const _docs = docs(ext).filter((it) => it != null) for (const r of _docs) { const existing = childDocsOfClass.find((it) => it.url.toLowerCase() === r.url.toLowerCase()) if (existing === undefined) { From 99749f30fb70099dfdeee9e427ab0b9c96f1818e Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 2 Oct 2024 11:00:17 +0400 Subject: [PATCH 3/7] Add chat and inbox fixes (#6779) Signed-off-by: Kristina Fefelova --- .../components/ActivityMessageAction.svelte | 2 +- plugins/chunter-assets/lang/ru.json | 2 +- .../src/components/ChannelScrollView.svelte | 2 +- plugins/chunter-resources/src/navigation.ts | 2 +- .../src/components/inbox/Inbox.svelte | 43 +++++++++++++++---- plugins/notification-resources/src/utils.ts | 8 +++- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/plugins/activity-resources/src/components/ActivityMessageAction.svelte b/plugins/activity-resources/src/components/ActivityMessageAction.svelte index 5ca696292a..b8bcfae1fd 100644 --- a/plugins/activity-resources/src/components/ActivityMessageAction.svelte +++ b/plugins/activity-resources/src/components/ActivityMessageAction.svelte @@ -40,6 +40,6 @@ kind="tertiary" pressed={opened} {dataId} - tooltip={{ label }} + tooltip={{ label, direction: 'bottom' }} on:click={onClick} /> diff --git a/plugins/chunter-assets/lang/ru.json b/plugins/chunter-assets/lang/ru.json index efdecade4d..5a0e3d671c 100644 --- a/plugins/chunter-assets/lang/ru.json +++ b/plugins/chunter-assets/lang/ru.json @@ -81,7 +81,7 @@ "Reacted": "Отреагировал(а)", "Docs": "Documents", "NewestFirst": "Сначала новые", - "ReplyToThread": "Ответить в канале", + "ReplyToThread": "Ответить в теме", "SentMessage": "Отправил(а) сообщение", "Direct": "Личные сообщения", "RepliedToThread": "Ответил(а) в канале", diff --git a/plugins/chunter-resources/src/components/ChannelScrollView.svelte b/plugins/chunter-resources/src/components/ChannelScrollView.svelte index 0544d9356d..7d94424e32 100644 --- a/plugins/chunter-resources/src/components/ChannelScrollView.svelte +++ b/plugins/chunter-resources/src/components/ChannelScrollView.svelte @@ -379,7 +379,7 @@ function messageInView (msgElement: Element, containerRect: DOMRect): boolean { const messageRect = msgElement.getBoundingClientRect() - return messageRect.top >= containerRect.top && messageRect.bottom - messageRect.height / 2 <= containerRect.bottom + return messageRect.top >= containerRect.top && messageRect.top <= containerRect.bottom && messageRect.bottom >= 0 } const messagesToReadAccumulator: Set = new Set() diff --git a/plugins/chunter-resources/src/navigation.ts b/plugins/chunter-resources/src/navigation.ts index 95d3b97eea..48111482d4 100644 --- a/plugins/chunter-resources/src/navigation.ts +++ b/plugins/chunter-resources/src/navigation.ts @@ -151,7 +151,7 @@ export async function buildThreadLink ( loc.path[2] = chunterId } - loc.query = { message: '' } + loc.query = { ...loc.query, message: '' } loc.path[3] = objectURI loc.path[4] = threadParent loc.fragment = undefined diff --git a/plugins/notification-resources/src/components/inbox/Inbox.svelte b/plugins/notification-resources/src/components/inbox/Inbox.svelte index f66650eb87..8f751f3e42 100644 --- a/plugins/notification-resources/src/components/inbox/Inbox.svelte +++ b/plugins/notification-resources/src/components/inbox/Inbox.svelte @@ -15,7 +15,7 @@ {#each _documents as doc} - {@const desc = _descendants.get(doc._id) ?? []} - {#if doc} - getMoreActions(doc)} - shouldTooltip - on:click={() => { - handleDocumentSelected(doc._id) - }} - > - {#if desc.length} - + {@const desc = _descendants.get(doc._id) ?? []} + {@const isDraggedOver = draggedOver === doc._id} +
+ {#if isDraggedOver} + {/if} - + + getMoreActions(doc)} + shouldTooltip + on:click={() => { + handleDocumentSelected(doc._id) + }} + on:dragstart={(evt) => { + onDragStart(evt, doc._id) + }} + on:dragover={(evt) => { + onDragOver(evt, doc._id) + }} + on:dragend={(evt) => { + onDragEnd(evt, doc._id) + }} + on:drop={(evt) => { + onDrop(evt, doc._id) + }} + > + {#if desc.length} + + {/if} + +
{/if} {/each} diff --git a/plugins/document-resources/src/components/navigator/DocTreeElement.svelte b/plugins/document-resources/src/components/navigator/DocTreeElement.svelte index e9c7694b96..43d3d8382e 100644 --- a/plugins/document-resources/src/components/navigator/DocTreeElement.svelte +++ b/plugins/document-resources/src/components/navigator/DocTreeElement.svelte @@ -64,6 +64,11 @@ showMenu={hovered} {shouldTooltip} {forciblyСollapsed} + draggable + on:dragstart + on:dragover + on:dragend + on:drop on:click={() => { selectDocument() dispatch('click') @@ -95,4 +100,5 @@ + diff --git a/plugins/document-resources/src/components/navigator/DropArea.svelte b/plugins/document-resources/src/components/navigator/DropArea.svelte new file mode 100644 index 0000000000..0d623e0634 --- /dev/null +++ b/plugins/document-resources/src/components/navigator/DropArea.svelte @@ -0,0 +1,29 @@ + + +
+ + diff --git a/plugins/document-resources/src/components/navigator/DropMarker.svelte b/plugins/document-resources/src/components/navigator/DropMarker.svelte new file mode 100644 index 0000000000..ff849a72e5 --- /dev/null +++ b/plugins/document-resources/src/components/navigator/DropMarker.svelte @@ -0,0 +1,33 @@ + + + +
+ + diff --git a/plugins/document-resources/src/components/navigator/TeamspaceSpacePresenter.svelte b/plugins/document-resources/src/components/navigator/TeamspaceSpacePresenter.svelte index 23dc3f7c5c..a887faf0e2 100644 --- a/plugins/document-resources/src/components/navigator/TeamspaceSpacePresenter.svelte +++ b/plugins/document-resources/src/components/navigator/TeamspaceSpacePresenter.svelte @@ -13,6 +13,7 @@ // limitations under the License. --> - getActions(space)} - {forciblyСollapsed} -> - +
+ {#if draggedOver === document.ids.NoParent} + + {/if} - - {#if (selected || forciblyСollapsed) && visibleItem} - {@const item = visibleItem} - getMoreActions(item)} - forciblyСollapsed - /> - {/if} - - + {#if draggedOver && draggedOverPos} + + {/if} + + getActions(space)} + selected={draggedOver === document.ids.NoParent} + {forciblyСollapsed} + draggable + on:drop={(evt) => { + onDrop(evt, document.ids.NoParent) + }} + on:dragover={(evt) => { + onDragOver(evt, document.ids.NoParent) + }} + on:dragstart={(evt) => { + evt.preventDefault() + }} + > + + + {#if (selected || forciblyСollapsed) && visibleItem} + {@const item = visibleItem} + getMoreActions(item)} + forciblyСollapsed + /> + {/if} + + +
diff --git a/plugins/document-resources/src/utils.ts b/plugins/document-resources/src/utils.ts index 317330f7a2..74349bcb7f 100644 --- a/plugins/document-resources/src/utils.ts +++ b/plugins/document-resources/src/utils.ts @@ -13,17 +13,57 @@ // limitations under the License. // -import { type AttachedData, type Client, type Ref, type TxOperations, makeCollaborativeDoc } from '@hcengineering/core' -import { type Document, type Teamspace, documentId } from '@hcengineering/document' +import { + type AttachedData, + type Client, + type QuerySelector, + type Ref, + SortingOrder, + type TxOperations, + makeCollaborativeDoc +} from '@hcengineering/core' +import { type Document, type Teamspace, documentId, getFirstRank } from '@hcengineering/document' import { getMetadata, translate } from '@hcengineering/platform' import presentation, { getClient } from '@hcengineering/presentation' +import { makeRank } from '@hcengineering/rank' import { getCurrentResolvedLocation, getPanelURI, type Location, type ResolvedLocation } from '@hcengineering/ui' +import { accessDeniedStore } from '@hcengineering/view-resources' import { workbenchId } from '@hcengineering/workbench' import slugify from 'slugify' -import { accessDeniedStore } from '@hcengineering/view-resources' import document from './plugin' +export async function moveDocument (doc: Document, space: Ref, parent: Ref): Promise { + const client = getClient() + + const prevRank = await getFirstRank(client, space, parent) + const rank = makeRank(prevRank, undefined) + + await client.update(doc, { space, attachedTo: parent, rank }) +} + +export async function moveDocumentBefore (doc: Document, before: Document): Promise { + const client = getClient() + + const { space, attachedTo } = before + const query = { rank: { $lt: before.rank } as unknown as QuerySelector } + const lastRank = await getFirstRank(client, space, attachedTo, SortingOrder.Descending, query) + const rank = makeRank(lastRank, before.rank) + + await client.update(doc, { space, attachedTo, rank }) +} + +export async function moveDocumentAfter (doc: Document, after: Document): Promise { + const client = getClient() + + const { space, attachedTo } = after + const query = { rank: { $gt: after.rank } as unknown as QuerySelector } + const nextRank = await getFirstRank(client, space, attachedTo, SortingOrder.Ascending, query) + const rank = makeRank(after.rank, nextRank) + + await client.update(doc, { space, attachedTo, rank }) +} + export async function createEmptyDocument ( client: TxOperations, id: Ref, @@ -33,6 +73,9 @@ export async function createEmptyDocument ( ): Promise { const name = await translate(document.string.Untitled, {}) + const lastRank = await getFirstRank(client, space, parent) + const rank = makeRank(lastRank, undefined) + const object: AttachedData = { name, content: makeCollaborativeDoc(id, 'content'), @@ -42,6 +85,7 @@ export async function createEmptyDocument ( labels: 0, comments: 0, references: 0, + rank, ...data } diff --git a/plugins/document/src/index.ts b/plugins/document/src/index.ts index 1c712bf3c8..1a3cbecad8 100644 --- a/plugins/document/src/index.ts +++ b/plugins/document/src/index.ts @@ -15,8 +15,9 @@ import { documentId, documentPlugin } from './plugin' -export * from './types' export * from './analytics' +export * from './types' +export * from './utils' export { documentId } export default documentPlugin diff --git a/plugins/document/src/types.ts b/plugins/document/src/types.ts index ab2b64d3e5..16a1d5bbe0 100644 --- a/plugins/document/src/types.ts +++ b/plugins/document/src/types.ts @@ -14,7 +14,7 @@ // import { Attachment } from '@hcengineering/attachment' -import { Account, AttachedDoc, Class, CollaborativeDoc, Ref, TypedSpace } from '@hcengineering/core' +import { Account, AttachedDoc, Class, CollaborativeDoc, Rank, Ref, TypedSpace } from '@hcengineering/core' import { Preference } from '@hcengineering/preference' import { IconProps } from '@hcengineering/view' @@ -37,6 +37,8 @@ export interface Document extends AttachedDoc, embeddings?: number labels?: number references?: number + + rank: Rank } /** @public */ diff --git a/plugins/document/src/utils.ts b/plugins/document/src/utils.ts new file mode 100644 index 0000000000..6a6cb701aa --- /dev/null +++ b/plugins/document/src/utils.ts @@ -0,0 +1,35 @@ +// +// Copyright © 2023, 2024 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 +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import { type DocumentQuery, type Rank, type Ref, SortingOrder, TxOperations } from '@hcengineering/core' + +import document from './plugin' +import { type Document, type Teamspace } from './types' + +export async function getFirstRank ( + client: TxOperations, + space: Ref, + attachedTo: Ref, + sort: SortingOrder = SortingOrder.Descending, + extra: DocumentQuery = {} +): Promise { + const doc = await client.findOne( + document.class.Document, + { space, attachedTo, ...extra }, + { sort: { rank: sort }, projection: { rank: 1 } } + ) + + return doc?.rank +} diff --git a/plugins/view-resources/src/components/navigator/TreeElement.svelte b/plugins/view-resources/src/components/navigator/TreeElement.svelte index 66d9e372ed..391e5a7cf8 100644 --- a/plugins/view-resources/src/components/navigator/TreeElement.svelte +++ b/plugins/view-resources/src/components/navigator/TreeElement.svelte @@ -55,6 +55,7 @@ export let showNotify: boolean = false export let forciblyСollapsed: boolean = false export let actions: (originalEvent?: MouseEvent) => Promise = async () => [] + export let draggable: boolean = false let pressed: boolean = false let inlineActions: Action[] = [] @@ -103,7 +104,11 @@ {shouldTooltip} showMenu={showMenu || pressed} {noDivider} + {draggable} on:click + on:dragstart + on:dragover + on:drop on:toggle={(ev) => { if (ev.detail !== undefined) collapsed = !ev.detail }} @@ -166,8 +171,12 @@ {forciblyСollapsed} {level} {shouldTooltip} + {draggable} showMenu={showMenu || pressed} on:click + on:dragstart + on:dragover + on:drop > diff --git a/plugins/view-resources/src/components/navigator/TreeNode.svelte b/plugins/view-resources/src/components/navigator/TreeNode.svelte index 0dd830b6de..65118e0f7d 100644 --- a/plugins/view-resources/src/components/navigator/TreeNode.svelte +++ b/plugins/view-resources/src/components/navigator/TreeNode.svelte @@ -39,6 +39,7 @@ export let noDivider: boolean = false export let shouldTooltip: boolean = false export let forciblyСollapsed: boolean = false + export let draggable: boolean = false