Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(search): mark schema as dirty when search is disable or replace search is set #93

Open
wants to merge 3 commits into
base: beta
Choose a base branch
from
Open
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 number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.build_schema(collection)
icon: nil,
integration: nil,
isReadOnly: collection.schema[:fields].all? { |_k, field| field.type != 'Column' || field.is_read_only },
isSearchable: true,
isSearchable: collection.schema[:searchable],
isVirtual: false,
name: collection.name,
onlyForRelationships: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ def initialize(child_collection, datasource)

def disable_search
@disabled_search = true
mark_schema_as_dirty
end

def replace_search(replacer)
@replacer = replacer
@disabled_search = false
mark_schema_as_dirty
end

def refine_schema(sub_schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ module ForestAdminDatasourceCustomizer
end
end

context 'when using disable_search' do
it 'calls the search decorator and disable the search' do
stack = @datasource_customizer.stack
stack.apply_queued_customizations({})
allow(stack.search).to receive(:get_collection).with('book').and_return(@datasource_customizer.stack.search.get_collection('book'))

customizer = described_class.new(@datasource_customizer, @datasource_customizer.stack, 'book')
customizer.disable_search
stack.apply_queued_customizations({})

search_collection = @datasource_customizer.stack.search.get_collection('book')

expect(search_collection.schema[:searchable]).to be(false)
end
end

context 'when using disable_count' do
it 'disables count on the collection' do
customizer = described_class.new(@datasource_customizer, @datasource_customizer.stack, 'book')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,59 @@ module Search
datasource.add_collection(collection_address)
end

context 'when disable search' do
it 'mark schema as dirty' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
search_collection_decorator.disable_search

expect(search_collection_decorator.last_schema).to be_nil
end

it 'sets the schema not searchable' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
unsearchable_schema = { searchable: true }
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: true })
search_collection_decorator.disable_search
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: false })
end
end

context 'when replace search' do
it 'mark schema as dirty' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
search_collection_decorator.replace_search(proc {})

expect(search_collection_decorator.last_schema).to be_nil
end

it 'sets the schema searchable' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
search_collection_decorator.replace_search(proc {})

expect(search_collection_decorator.schema[:searchable]).to be(true)
end
end

context 'when refine_schema' do
it 'sets the schema searchable' do
collection = build_collection(
Expand All @@ -80,21 +133,6 @@ module Search
unsearchable_schema = { searchable: false }
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: true })
end

context 'when disable search' do
it 'sets the schema not searchable' do
collection = build_collection(
schema: {
fields: { 'foo' => build_column(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
unsearchable_schema = { searchable: true }
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: true })
search_collection_decorator.disable_search
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: false })
end
end
end

context 'when refine_filter' do
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8eb0fd19608c3e5609086db683b5d6b9b6861f62399a439f5107f2fcdc2dfd0acdf09efc62589584064b83444a80a9fb88a6d4c8288df4a4f9f87404b05e1e96
Loading