From 42c29462a794a259c992f26226711fbc84e0e1ad Mon Sep 17 00:00:00 2001 From: Chris Berry Date: Thu, 12 Sep 2019 13:19:19 -0700 Subject: [PATCH] fix(core): ensure filter tag removal removes tags from filter (#7212) --- .../src/filterModel/FilterModelService.ts | 17 ++++--------- .../core/src/filterModel/IFilterModel.ts | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/app/scripts/modules/core/src/filterModel/FilterModelService.ts b/app/scripts/modules/core/src/filterModel/FilterModelService.ts index 60b782ff29c..f8f2d52542b 100644 --- a/app/scripts/modules/core/src/filterModel/FilterModelService.ts +++ b/app/scripts/modules/core/src/filterModel/FilterModelService.ts @@ -1,6 +1,6 @@ import { cloneDeep, size, some, isNil, reduce, forOwn, includes, pick } from 'lodash'; -import { IFilterModel, IFilterConfig } from './IFilterModel'; +import { IFilterModel, IFilterConfig, ITrueKeyModel } from './IFilterModel'; import { ReactInjector } from 'core/reactShims'; export class FilterModelService { @@ -204,17 +204,6 @@ export class FilterModelService { }; } - public static checkCategoryFilters(model: IFilterModel) { - return (target: any) => { - if (this.isFilterable(model.sortFilter.category)) { - const checkedCategories = this.getCheckValues(model.sortFilter.category); - return includes(checkedCategories, target.type) || includes(checkedCategories, target.category); - } else { - return true; - } - }; - } - private static addTagsForSection(model: IFilterModel, property: IFilterConfig) { const key = property.model; const label = property.filterLabel || property.model; @@ -231,7 +220,9 @@ export class FilterModelService { label, value: translator[value] || value, clear() { - delete (modelVal as any)[value]; + // do not reuse the modelVal variable - it's possible it has been reassigned since the tag was created + const toClearFrom: ITrueKeyModel = model.sortFilter[key] as ITrueKeyModel; + delete toClearFrom[value]; model.applyParamsToUrl(); }, }); diff --git a/app/scripts/modules/core/src/filterModel/IFilterModel.ts b/app/scripts/modules/core/src/filterModel/IFilterModel.ts index 7010b5162b2..71e423b206f 100644 --- a/app/scripts/modules/core/src/filterModel/IFilterModel.ts +++ b/app/scripts/modules/core/src/filterModel/IFilterModel.ts @@ -10,37 +10,41 @@ export interface IFilterConfig { array?: boolean; } +export interface ITrueKeyModel { + [key: string]: boolean; +} + // The sortFilter objects are generated, so leaving all fields as required // In addition, there should technically be a few different ISortFilter // sub-interfaces (Clusters, Pipeline, Load Balancer, etc) // but I want to delete all this stuff in favor of router params eventually // anyway, so keeping the interface consolidated for now. export interface ISortFilter { - account: { [key: string]: boolean }; - availabilityZone: { [key: string]: boolean }; + account: ITrueKeyModel; + availabilityZone: ITrueKeyModel; category: { [key: string]: any }; clusters: { [key: string]: any }; count: number; - detail: { [key: string]: boolean }; + detail: ITrueKeyModel; filter: string; groupBy: string; instanceSort: string; - instanceType: { [key: string]: boolean }; - labels: { [key: string]: boolean }; + instanceType: ITrueKeyModel; + labels: ITrueKeyModel; listInstances: boolean; maxInstances: number; minInstances: number; multiselect: boolean; - pipeline: { [key: string]: boolean }; - providerType: { [key: string]: boolean }; - region: { [key: string]: boolean }; + pipeline: ITrueKeyModel; + providerType: ITrueKeyModel; + region: ITrueKeyModel; showAllInstances: boolean; showInstances: boolean; showLoadBalancers: boolean; showServerGroups: boolean; showDurations: boolean; - stack: { [key: string]: boolean }; - status: { [key: string]: boolean }; + stack: ITrueKeyModel; + status: ITrueKeyModel; } export interface IFilterModel {