From e329d72e8b6357ab75332bb3405337664c5f79fa Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 27 Mar 2022 23:47:53 -0700 Subject: [PATCH] Clarify query var transformation code --- .../document-list/document-list.component.ts | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index e8eb7684f..19ada6785 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -128,43 +128,40 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit { this.unmodifiedFilterRules = view.filter_rules }) - const filterQueryVars: string[] = FILTER_RULE_TYPES.map( + const allFilterRuleQueryParams: string[] = FILTER_RULE_TYPES.map( (rt) => rt.filtervar ) this.route.queryParamMap .pipe( - filter((qp) => !this.route.snapshot.paramMap.has('id')), // only when not on saved view + filter(() => !this.route.snapshot.paramMap.has('id')), // only when not on saved view takeUntil(this.unsubscribeNotifier) ) .subscribe((queryParams) => { - const queryVarsFilterRules = [] + // transform query params to filter rules + let filterRulesFromQueryParams: FilterRule[] = [] + allFilterRuleQueryParams + .filter((frqp) => queryParams.has(frqp)) + .forEach((filterQueryParamName) => { + const filterQueryParamValues: string[] = queryParams + .get(filterQueryParamName) + .split(',') - filterQueryVars.forEach((filterQueryVar) => { - if (queryParams.has(filterQueryVar)) { - const value = queryParams.get(filterQueryVar) - if (value.split(',').length > 1) { - value.split(',').forEach((splitVal) => { - queryVarsFilterRules.push({ + filterRulesFromQueryParams = filterRulesFromQueryParams.concat( + // map all values to filter rules + filterQueryParamValues.map((val) => { + return { rule_type: FILTER_RULE_TYPES.find( - (rt) => rt.filtervar == filterQueryVar + (rt) => rt.filtervar == filterQueryParamName ).id, - value: splitVal, - }) + value: val, + } }) - } else { - queryVarsFilterRules.push({ - rule_type: FILTER_RULE_TYPES.find( - (rt) => rt.filtervar == filterQueryVar - ).id, - value: value, - }) - } - } - }) + ) + }) this.list.activateSavedView(null) - this.list.filterRules = queryVarsFilterRules + this.list.filterRules = filterRulesFromQueryParams this.list.reload() this.unmodifiedFilterRules = [] })