@@ -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