Skip to content

Commit 143cbe6

Browse files
dev4ndymcnielsen
authored andcommitted
ENG-48511 - Add setDefaultFiltersByParams function to allow setting active filters based on query parameters
1 parent f65dc5b commit 143cbe6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@al/core",
3-
"version": "1.0.197",
3+
"version": "1.0.198",
44
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
55
"main": "./dist/index.cjs.js",
66
"types": "./dist/index.d.ts",

src/common/cardstack/al-cardstack-view.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,37 @@ export abstract class AlCardstackView< EntityType=any,
423423
*/
424424
public decoratePropertyValue?( entity:EntityType, property:AlCardstackPropertyDescriptor, value:AlCardstackValueDescriptor );
425425

426+
/**
427+
* Sets the active filters based on the specified query parameters.
428+
* This function is useful when using deep links.
429+
*
430+
* @param {Object} params - The query parameters object.
431+
* @throws {Error} If `characteristics` is not configured, an error will be thrown.
432+
* @returns {void}
433+
*/
434+
public setDefaultFiltersByParams(params: {[key:string]: string}) {
435+
if(!this.characteristics){
436+
throw new Error("characteristics must be configured to activate filters via query parameters.");
437+
}
438+
const filterableBy = this.characteristics.filterableBy;
439+
if (filterableBy.length > 0) {
440+
for (let i = 0; i < filterableBy.length; i++) {
441+
const filterProperty = filterableBy[i] as string;
442+
if (filterProperty in params && params[filterProperty] && filterProperty in this.characteristics.definitions) {
443+
const values = params[filterProperty].split(',');
444+
const activeFilters: AlCardstackValueDescriptor[] = [];
445+
values.forEach(value => {
446+
const filter = this.characteristics.definitions[filterProperty].values.find(characteristicValue => characteristicValue.value === value);
447+
if (filter) {
448+
activeFilters.push(filter);
449+
}
450+
});
451+
this.applyMultipleFilterBy(activeFilters);
452+
}
453+
}
454+
}
455+
}
456+
426457
/**
427458
* Protected Internal Methods
428459
*/
@@ -732,6 +763,7 @@ export abstract class AlCardstackView< EntityType=any,
732763
}
733764
});
734765
}
766+
// debugger;
735767
existing.values.push( vDescriptor );
736768
existing.rawValues = existing.values.map( vDescr => vDescr.value );
737769
} else {

0 commit comments

Comments
 (0)