Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
module ForestAdminDatasourceCustomizer
class CollectionCustomizer
include ForestAdminDatasourceToolkit::Validations
attr_reader :datasource_customizer, :stack, :name

def initialize(datasource_customizer, stack, name)
Expand DownExpand Up@@ -60,6 +61,21 @@ def emulate_field_operator(name, operator)
end
end

def emulate_field_filtering(name)
push_customization do
collection = @stack.late_op_emulate.get_collection(@name)
field = collection.schema[:fields][name]

if field.column_type.is_a?(String)
operators = Rules.get_allowed_operators_for_column_type[field.column_type]

operators.each do |operator|
emulate_field_operator(name, operator) unless field.filter_operators&.include?(operator)
end
end
end
end

def replace_field_operator(name, operator, &replacer)
push_customization do
collection = if @stack.early_op_emulate.get_collection(@name).schema[:fields].key?(name)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,6 +388,23 @@ module ForestAdminDatasourceCustomizer
end
end

context 'when using emulate_field_filtering' do
it 'emulate filtering on field' do
stack = @datasource_customizer.stack
stack.apply_queued_customizations({})
allow(stack.early_op_emulate).to receive(:get_collection).with('person').and_return(@datasource_customizer.stack.early_op_emulate.get_collection('person'))

customizer = described_class.new(@datasource_customizer, @datasource_customizer.stack, 'person')
customizer.emulate_field_filtering('name')
stack.apply_queued_customizations({})

expected_operators = ForestAdminDatasourceToolkit::Validations::Rules.get_allowed_operators_for_column_type['String']
op_emulate_collection = @datasource_customizer.stack.early_op_emulate.get_collection('person')

expect(op_emulate_collection.schema[:fields]['name'].filter_operators).to include(*expected_operators)
end
end

context 'when using replace_field_sorting' do
it 'replace sort on field' do
stack = @datasource_customizer.stack
Expand Down