Skip to content

Commit

Permalink
Merge pull request #287 from webitel/hotfix/add-multiple-value-in-filter
Browse files Browse the repository at this point in the history
Hotfix/add multiple value in filter
  • Loading branch information
Lera24 authored Sep 5, 2024
2 parents 4d414de + 4225135 commit 0223c67
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "24.10.2",
"version": "24.10.3",
"private": false,
"scripts": {
"dev": "vite",
Expand Down
2 changes: 2 additions & 0 deletions src/modules/Filters/classes/BaseFilterSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class BaseFilterSchema {
get = ['value', 'query'],
set = ['value', 'query'],
restore = ['query'],
multiple = false,
...rest
} = {}) {
if (!name) throw new Error('Filter name is required');
Expand All @@ -94,6 +95,7 @@ export default class BaseFilterSchema {
name,
value,
defaultValue,
multiple,
}, rest);

this.setupGetters(get);
Expand Down
8 changes: 7 additions & 1 deletion src/modules/Filters/scripts/getters/queryGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const queryGetter = (context) => (router) => () => {
const query = router.currentRoute.value?.query || router.currentRoute.query ||
{};

return query[context.name];
const value = query[context.name];

if(value && context?.multiple && !Array.isArray(value)) {
return [value];
}

return value;
};

export default queryGetter;
3 changes: 1 addition & 2 deletions src/modules/Filters/scripts/getters/valueGetter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// context === filter "this"
const valueGetter = (context) => () => {
const { value, storedProp, multiple } = context;
if (multiple) return value.map((item) => item[storedProp]); // if arr, map
const { value, storedProp } = context;
if (storedProp) return value[storedProp]; // if object and has specific prop, return this prop
return value; // else return val
};
Expand Down

0 comments on commit 0223c67

Please sign in to comment.