Fix "SortableList" drag n drop with descending sorting (#2591)

Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@xored.com>
This commit is contained in:
Sergei Ogorelkov 2023-02-06 21:34:52 +06:00 committed by GitHub
parent f79b42c2c8
commit 59c53a09f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Doc, DocumentQuery, FindOptions, FindResult, Ref } from '@hcengineering/core'
import { Class, Doc, DocumentQuery, FindOptions, FindResult, Ref, SortingOrder } from '@hcengineering/core'
import { Asset, getResource, IntlString } from '@hcengineering/platform'
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
import { calcRank, DocWithRank } from '@hcengineering/task'
@ -49,6 +49,7 @@
export let icon: Asset | undefined = undefined
export let iconSize: IconSize = 'small'
const SORTING_ORDER = SortingOrder.Ascending
const client = getClient()
const hierarchy = client.getHierarchy()
const itemsQuery = createQuery()
@ -121,9 +122,12 @@
items[draggingIndex < itemIndex ? itemIndex + 1 : itemIndex] as DocWithRank
]
const sortingOrder = queryOptions?.sort?.rank ?? SORTING_ORDER
const rank = sortingOrder === SortingOrder.Ascending ? calcRank(prev, next) : calcRank(next, prev)
try {
areItemsSorting = true
await client.update(item, { rank: calcRank(prev, next) })
await client.update(item, { rank })
} finally {
areItemsSorting = false
}
@ -149,7 +153,11 @@
$: !$$slots.object && updatePresenter(_class)
$: updateObjectFactory(_class)
$: itemsQuery.query(_class, query, updateItems, { ...queryOptions, limit: Math.max(queryOptions?.limit ?? 0, 200) })
$: itemsQuery.query(_class, query, updateItems, {
...(isSortable ? { sort: { rank: SORTING_ORDER } } : {}),
...(queryOptions ?? {}),
limit: Math.max(queryOptions?.limit ?? 0, 200)
})
$: isLoading = isPresenterLoading || areItemsloading
$: isSortable = hierarchy.getAllAttributes(_class).has('rank')