From e92918c6c7220a9eba99f70bc8fbd2a7b8f7c6ff Mon Sep 17 00:00:00 2001
From: Andrey Sobolev <haiodo@users.noreply.github.com>
Date: Mon, 14 Aug 2023 19:34:56 +0700
Subject: [PATCH] Fix listview (#3586)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
---
 .../src/components/list/List.svelte              | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/plugins/view-resources/src/components/list/List.svelte b/plugins/view-resources/src/components/list/List.svelte
index 7f8df629aa..9a8fa1d435 100644
--- a/plugins/view-resources/src/components/list/List.svelte
+++ b/plugins/view-resources/src/components/list/List.svelte
@@ -57,16 +57,23 @@
     resultQuery = { ...p, ...query }
   })
 
+  $: queryNoLookup = noLookup(resultQuery)
+
   $: if (documents === undefined) {
     docsQuery.query(
       _class,
-      noLookup(resultQuery),
+      queryNoLookup,
       (res) => {
         docs = res
       },
       {
         ...resultOptions,
-        projection: { ...resultOptions.projection, _id: 1, _class: 1, ...getProjection(viewOptions.groupBy) }
+        projection: {
+          ...resultOptions.projection,
+          _id: 1,
+          _class: 1,
+          ...getProjection(viewOptions.groupBy, queryNoLookup)
+        }
       }
     )
   } else {
@@ -74,11 +81,14 @@
     docs = documents
   }
 
-  function getProjection (fields: string[]): Record<string, number> {
+  function getProjection (fields: string[], query: DocumentQuery<Doc>): Record<string, number> {
     const res: Record<string, number> = {}
     for (const f of fields) {
       res[f] = 1
     }
+    for (const f of Object.keys(query)) {
+      res[f] = 1
+    }
     return res
   }