Let's take a look at the updateFilter
queryFilter.updateFilter = function (filter) {
const mergedFilter = _.assign({}, filter.source, filter.model);
mergedFilter.meta.alias = filter.alias;
//If the filter type is changed we want to discard the old type
//when merging changes back in
const filterTypeReplaced = filter.model[filter.type] !== mergedFilter[filter.type];
if (filterTypeReplaced) {
delete mergedFilter[filter.type];
}
return angular.copy(mergedFilter, filter.source);
};
To me the comment seems like it wants to make sure if you are changing the filter type from the source then it will remove it from the mergedFilter. However, look at how it's deleting from mergedFilter. It will only remove a property from it that matches the passed in filter's type. This seems wrong when I see filter.type and think that it identifies the filter's type when in reality it looks like it represents the source filter's type. The only way I have been able to update filters is to incorrectly set the type value of the passed in filter to the property I want removed from the merge with the filter source. So if I have a filter of geo_polygon and want to update it to geo_shape I have to set the filter type of the passed in value to geo_polygon (i.e. The type of the original source and not the type it will end up being). Does this seem completely confusing to anyone else? It's like the type property of the passed in filter is suppose to represent the source filter type. It should be named as such if that is the case.