Skip to content

Commit

Permalink
Merge pull request #33 from rdytech/NEP-17878-add-dasboard-filter-tit…
Browse files Browse the repository at this point in the history
…le-equals

NEP-17878 add title equals filter for dashboard listing
  • Loading branch information
jbat authored Aug 27, 2024
2 parents 308d159 + 5a4ec83 commit 864b931
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change Log

## 0.1.7 - 2024-08-27

* adds filter title_equals to dashboard list class - https://github.com/rdytech/superset-client/pull/33

## 0.1.6 - 2024-07-10

* added a class **WarmUpCache** to hit the 'api/v1/dataset/warm_up_cache' endpoint to warm up the cache of all the datasets for a particular dashaboard being passed to the class - https://github.com/rdytech/superset-client/pull/28
Expand Down
7 changes: 5 additions & 2 deletions lib/superset/dashboard/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
module Superset
module Dashboard
class List < Superset::Request
attr_reader :title_contains, :tags_equal, :ids_not_in
attr_reader :title_contains, :title_equals, :tags_equal, :ids_not_in

def initialize(page_num: 0, title_contains: '', tags_equal: [], ids_not_in: [])
def initialize(page_num: 0, title_contains: '', title_equals: '', tags_equal: [], ids_not_in: [])
@title_contains = title_contains
@title_equals = title_equals
@tags_equal = tags_equal
@ids_not_in = ids_not_in
super(page_num: page_num)
Expand Down Expand Up @@ -69,6 +70,7 @@ def filters
# TODO filtering across all list classes can be refactored to support multiple options in a more flexible way
filter_set = []
filter_set << "(col:dashboard_title,opr:ct,value:'#{title_contains}')" if title_contains.present?
filter_set << "(col:dashboard_title,opr:eq,value:'#{title_equals}')" if title_equals.present?
filter_set << tag_filters if tags_equal.present?
filter_set << ids_not_in_filters if ids_not_in.present?
unless filter_set.empty?
Expand All @@ -90,6 +92,7 @@ def list_attributes

def validate_constructor_args
raise InvalidParameterError, "title_contains must be a String type" unless title_contains.is_a?(String)
raise InvalidParameterError, "title_equals must be a String type" unless title_equals.is_a?(String)
raise InvalidParameterError, "tags_equal must be an Array type" unless tags_equal.is_a?(Array)
raise InvalidParameterError, "tags_equal array must contain string only values" unless tags_equal.all? { |item| item.is_a?(String) }
raise InvalidParameterError, "ids_not_in must be an Array type" unless ids_not_in.is_a?(Array)
Expand Down
2 changes: 1 addition & 1 deletion lib/superset/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Superset
VERSION = "0.1.6"
VERSION = "0.1.7"
end
3 changes: 2 additions & 1 deletion spec/superset/dashboard/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@
end

context 'with multiple filter set and multiple tags' do
subject { described_class.new(page_num: 3, title_contains: 'birth', tags_equal: ['template', 'client:acme', 'product:turbo-charged-feet']) }
subject { described_class.new(page_num: 3, title_contains: 'birth', title_equals: 'births in aust', tags_equal: ['template', 'client:acme', 'product:turbo-charged-feet']) }

specify do
expect(subject.query_params).to eq(
"filters:!(" \
"(col:dashboard_title,opr:ct,value:'birth')," \
"(col:dashboard_title,opr:eq,value:'births in aust')," \
"(col:tags,opr:dashboard_tags,value:'template')," \
"(col:tags,opr:dashboard_tags,value:'client:acme')," \
"(col:tags,opr:dashboard_tags,value:'product:turbo-charged-feet')" \
Expand Down

0 comments on commit 864b931

Please sign in to comment.