From cc518d5a80d4734a2a7c750f07032796e74b5f33 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 24 Jul 2024 10:33:22 +0200 Subject: [PATCH] perf: refs #7717 right menu filter --- src/filters/getParamWhere.js | 21 +++++++++++ src/filters/index.js | 2 + src/pages/Order/Card/OrderCatalog.vue | 3 -- src/pages/Order/Card/OrderCatalogFilter.vue | 41 ++------------------- 4 files changed, 27 insertions(+), 40 deletions(-) create mode 100644 src/filters/getParamWhere.js diff --git a/src/filters/getParamWhere.js b/src/filters/getParamWhere.js new file mode 100644 index 000000000..48cd9c479 --- /dev/null +++ b/src/filters/getParamWhere.js @@ -0,0 +1,21 @@ +// parsing JSON safely +function parseJSON(str, fallback) { + try { + return JSON.parse(str ?? '{}'); + } catch (e) { + console.error('Error parsing JSON:', e); + return fallback; + } +} +export default function (route, param) { + // catch route query params + const params = parseJSON(route?.query?.params, {}); + + // extract and parse filter from params + const { filter: filterStr = '{}' } = params; + const where = parseJSON(filterStr, {})?.where; + if (where && where[param] !== undefined) { + return where[param]; + } + return null; +} diff --git a/src/filters/index.js b/src/filters/index.js index 940788ed1..5f08f19c7 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -11,6 +11,7 @@ import dashIfEmpty from './dashIfEmpty'; import dateRange from './dateRange'; import toHour from './toHour'; import dashOrCurrency from './dashOrCurrency'; +import getParamWhere from './getParamWhere'; export { toLowerCase, @@ -26,4 +27,5 @@ export { toPercentage, dashIfEmpty, dateRange, + getParamWhere, }; diff --git a/src/pages/Order/Card/OrderCatalog.vue b/src/pages/Order/Card/OrderCatalog.vue index cb3e9a8eb..dc7115422 100644 --- a/src/pages/Order/Card/OrderCatalog.vue +++ b/src/pages/Order/Card/OrderCatalog.vue @@ -53,8 +53,6 @@ function extractValueTags(items) {