From 359f24348887cd854fc9b59382865e9a00160b20 Mon Sep 17 00:00:00 2001
From: Martin Koerwien <martin.koerwien@fokus.fraunhofer.de>
Date: Fri, 21 Feb 2025 11:21:41 +0100
Subject: [PATCH] fix: initialize sort from query params in modules search
 pages

---
 .../lib/catalogues/Catalogues.vue             |  1 +
 .../lib/datasets/Datasets.vue                 | 46 +++++++++++--------
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/packages/piveau-hub-ui-modules/lib/catalogues/Catalogues.vue b/packages/piveau-hub-ui-modules/lib/catalogues/Catalogues.vue
index 3832de651..2996a5eac 100755
--- a/packages/piveau-hub-ui-modules/lib/catalogues/Catalogues.vue
+++ b/packages/piveau-hub-ui-modules/lib/catalogues/Catalogues.vue
@@ -285,6 +285,7 @@
           if (sort === 'modified+desc') this.sortSelectedLabel = this.$t('message.sort.lastUpdated');
           if (sort === 'issued+desc') this.sortSelectedLabel = this.$t('message.sort.lastCreated');
           this.sortSelected = this.$route.query.sort;
+          this.setSort(sort);
         }
       },
       initFacetOperator() {
diff --git a/packages/piveau-hub-ui-modules/lib/datasets/Datasets.vue b/packages/piveau-hub-ui-modules/lib/datasets/Datasets.vue
index 80e86e3f4..b855b75db 100644
--- a/packages/piveau-hub-ui-modules/lib/datasets/Datasets.vue
+++ b/packages/piveau-hub-ui-modules/lib/datasets/Datasets.vue
@@ -264,6 +264,7 @@ export default {
       'loadDatasets',
       'loadAdditionalDatasets',
       'setPage',
+      'setSort',
       'addFacet',
       'removeFacet',
       'setFacets',
@@ -308,26 +309,30 @@ export default {
               this.$Progress.fail();
             });
         });
-      },
-      initLimit() {
-        const limit = parseInt(this.$route.query.limit, 10);
-        if (limit > 0) this.setLimit(limit);
-      },
-      setPageLimit(value) {
-        this.setLimit(value);
-        this.initDatasets();
-      },
-      initDataScope() {
-        this.setDataScope(this.dataScope);
-      },
-      /**
-       * @description Determines the current page.
-       */
-      initPage() {
-        const page = parseInt(this.$route.query.page, 10);
-        if (page > 0) this.setPage(page);
-        else this.setPage(1);
-      },
+    },
+    initLimit() {
+      const limit = parseInt(this.$route.query.limit, 10);
+      if (limit > 0) this.setLimit(limit);
+    },
+    initSort() {
+      const sort = this.$route.query.sort;
+      if (sort) this.setSort(sort);
+    },
+    setPageLimit(value) {
+      this.setLimit(value);
+      this.initDatasets();
+    },
+    initDataScope() {
+      this.setDataScope(this.dataScope);
+    },
+    /**
+     * @description Determines the current page.
+     */
+    initPage() {
+      const page = parseInt(this.$route.query.page, 10);
+      if (page > 0) this.setPage(page);
+      else this.setPage(1);
+    },
     /**
      * @descritption Initialize the active facets by checking the route parameters
      */
@@ -434,6 +439,7 @@ export default {
   created() {
     this.initDataScope();
     this.initLimit();
+    this.initSort();
     this.initPage();
     this.initFacetOperator();
     this.initFacetGroupOperator();
-- 
GitLab