Skip to content

Commit

Permalink
fix(collection): add missing function enable_search and add_segments (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasalexandre9 authored Jan 6, 2025
1 parent f3edd98 commit 58dc7e6
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.build_actions(collection)

def self.build_segments(collection)
if collection.schema[:segments]
collection.schema[:segments].keys.sort.map { |name| { id: "#{collection.name}.#{name}", name: name } }
collection.schema[:segments].sort.map { |name| { id: "#{collection.name}.#{name}", name: name } }
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion packages/forest_admin_agent/spec/shared/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def collection_build(args = {})
fields: {},
countable: false,
searchable: false,
segments: {}
segments: []
}.merge(args[:schema]),
execute: nil,
get_form: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def add_segment(name, definition)
end

def refine_schema(sub_schema)
sub_schema[:segments] = sub_schema[:segments].merge(@segments)
sub_schema[:segments] = sub_schema[:segments] | @segments.keys

sub_schema
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module ForestAdminDatasourceCustomizer
countable: false,
searchable: false,
charts: [],
segments: {},
segments: [],
actions: {}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def collection_build(args = {})
fields: {},
countable: false,
searchable: false,
segments: {}
segments: []
}.merge(args[:schema] || {}),
execute: nil,
get_form: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(datasource, name, native_driver = nil)
countable: false,
searchable: false,
charts: [],
segments: {},
segments: [],
actions: {}
}
end
Expand All @@ -25,6 +25,10 @@ def enable_count
schema[:countable] = true
end

def enable_search
schema[:searchable] = true
end

def is_countable?
schema[:countable]
end
Expand All @@ -33,6 +37,10 @@ def is_searchable?
schema[:searchable]
end

def add_segments(segments)
schema[:segments] = schema[:segments] | segments
end

def fields
schema[:fields]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,40 @@ module ForestAdminDatasourceToolkit
)
end
end

describe 'enable_count' do
it 'set at true the countable option' do
expect(@collection.is_countable?).to be false

@collection.enable_count

expect(@collection.is_countable?).to be true
end
end

describe 'enable_search' do
it 'set at true the searchable option' do
expect(@collection.is_searchable?).to be false

@collection.enable_search

expect(@collection.is_searchable?).to be true
end
end

describe 'add_segments' do
it 'add segments into the schema' do
@collection.add_segments(%w[segment_1 segment_2])

expect(@collection.schema[:segments]).to eq(%w[segment_1 segment_2])
end

it 'add segments into the schema with existing segments' do
@collection.add_segments(%w[segment_1 segment_2])
@collection.add_segments(%w[segment_3])

expect(@collection.schema[:segments]).to eq(%w[segment_1 segment_2 segment_3])
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def collection_build(args = {})
fields: {},
countable: false,
searchable: false,
segments: {}
segments: []
}.merge(args[:schema]),
execute: nil,
get_form: nil,
Expand Down

0 comments on commit 58dc7e6

Please sign in to comment.