From 2c89008374f7dda124f9984cf33d78297f1f3cdf Mon Sep 17 00:00:00 2001
From: Alexander Onnikov <Alexander.Onnikov@xored.com>
Date: Thu, 23 May 2024 00:03:20 +0700
Subject: [PATCH] UBERF-7007 Show folders first in drive (#5645)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
---
 models/drive/src/index.ts                          | 12 ++++++++++--
 plugins/view-resources/src/components/Table.svelte |  4 ++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/models/drive/src/index.ts b/models/drive/src/index.ts
index 5781269186..0bc5efd3a8 100644
--- a/models/drive/src/index.ts
+++ b/models/drive/src/index.ts
@@ -23,6 +23,7 @@ import core, {
   AccountRole,
   IndexKind,
   Ref,
+  SortingOrder,
   DOMAIN_MODEL
 } from '@hcengineering/core'
 import { type Drive, type File, type Folder, type Resource, driveId } from '@hcengineering/drive'
@@ -259,18 +260,25 @@ function defineResource (builder: Builder): void {
         {
           key: '',
           presenter: drive.component.ResourcePresenter,
-          label: drive.string.Name
+          label: drive.string.Name,
+          sortingKey: 'name'
         },
         {
           key: '$lookup.file.size',
           presenter: drive.component.FileSizePresenter,
-          label: drive.string.Size
+          label: drive.string.Size,
+          sortingKey: '$lookup.file.size'
         },
         {
           key: '$lookup.file.modifiedOn'
         },
         'createdBy'
       ],
+      options: {
+        sort: {
+          _class: SortingOrder.Descending
+        }
+      },
       configOptions: {
         hiddenKeys: ['name', 'file', 'parent', 'path'],
         sortable: true
diff --git a/plugins/view-resources/src/components/Table.svelte b/plugins/view-resources/src/components/Table.svelte
index 9633410f65..ecf6fe2a20 100644
--- a/plugins/view-resources/src/components/Table.svelte
+++ b/plugins/view-resources/src/components/Table.svelte
@@ -139,7 +139,7 @@
         objectsRecieved = true
         loading = 0
       },
-      { sort: getSort(sortKey), limit, ...options, lookup, total: false }
+      { limit, ...options, sort: getSort(sortKey), lookup, total: false }
     )
       ? 1
       : 0
@@ -155,7 +155,7 @@
     (result) => {
       total = result.total
     },
-    { sort: getSort(_sortKey), limit: 1, ...options, lookup, total: true }
+    { limit: 1, ...options, sort: getSort(_sortKey), lookup, total: true }
   )
 
   const showContextMenu = async (ev: MouseEvent, object: Doc, row: number): Promise<void> => {