From 86096805e2ee4ce801e156efbc341268eb3ec75c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com>
Date: Wed, 17 Jan 2024 08:56:18 +0100
Subject: [PATCH] refactor(query selector): improved code readability

---
 src/redux/root/query.selectors.ts | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/redux/root/query.selectors.ts b/src/redux/root/query.selectors.ts
index a8bfdea3..3088b0da 100644
--- a/src/redux/root/query.selectors.ts
+++ b/src/redux/root/query.selectors.ts
@@ -16,25 +16,20 @@ export const queryDataParamsSelector = createSelector(
     { modelId, backgroundId, position },
     activeOverlaysId,
   ): QueryDataParams => {
+    const joinedSearchValue = searchValue.join(';');
+    const shouldIncludeSearchValue = searchValue.length > ZERO && joinedSearchValue;
+
+    const shouldIncludeOverlaysId = activeOverlaysId.length > ZERO;
+
     const queryDataParams: QueryDataParams = {
       perfectMatch,
       modelId,
       backgroundId,
       ...position.last,
+      ...(shouldIncludeSearchValue ? { searchValue: joinedSearchValue } : {}),
+      ...(shouldIncludeOverlaysId ? { overlaysId: activeOverlaysId.join(',') } : {}),
     };
 
-    /** prevent searchValueQuery from being empty */
-    if (searchValue.length > ZERO) {
-      const joinedSearchValue = searchValue.join(';');
-      if (joinedSearchValue) {
-        queryDataParams.searchValue = joinedSearchValue;
-      }
-    }
-
-    if (activeOverlaysId.length > ZERO) {
-      queryDataParams.overlaysId = activeOverlaysId.join(',');
-    }
-
     return queryDataParams;
   },
 );
-- 
GitLab