Skip to content

Commit 1164083

Browse files
committed
chore: finalize search behavior
1 parent c3fe356 commit 1164083

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

src/datasource_rpc/forestadmin/datasource_rpc/datasource.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ def create_collection(self, collection_name, collection_schema):
7070
collection.add_rpc_action(action_name, action_schema)
7171

7272
collection._schema["charts"] = {name: None for name in collection_schema["charts"]}
73-
collection._schema["searchable"] = collection_schema["searchable"]
74-
collection._schema["countable"] = collection_schema["countable"]
7573
collection.add_segments(collection_schema["segments"])
7674

75+
if collection_schema["countable"]:
76+
collection.enable_count()
77+
collection.enable_search()
78+
7779
self.add_collection(collection)
7880

7981
def wait_for_connection(self):
@@ -87,8 +89,10 @@ def wait_for_connection(self):
8789

8890
async def internal_reload(self):
8991
has_changed = self.introspect()
90-
if has_changed and self.reload_method is not None:
91-
await call_user_function(self.reload_method)
92+
if has_changed:
93+
await Agent.get_instance().reload()
94+
# if has_changed and self.reload_method is not None:
95+
# await call_user_function(self.reload_method)
9296

9397
async def run(self):
9498
self.wait_for_connection()

src/datasource_toolkit/forestadmin/datasource_toolkit/datasource_customizer/collection_customizer.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,6 @@ async def _disable_count():
550550
self.stack.queue_customization(_disable_count)
551551
return self
552552

553-
def bypass_search(self) -> Self:
554-
async def _bypass_search():
555-
cast(SearchCollectionDecorator, self.stack.search.get_collection(self.collection_name)).bypass_search()
556-
557-
self.stack.queue_customization(_bypass_search)
558-
return self
559-
560553
def replace_search(self, definition: SearchDefinition) -> Self:
561554
"""Replace the behavior of the search bar
562555
Args:

src/datasource_toolkit/forestadmin/datasource_toolkit/decorators/search/collections.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,18 @@ def __init__(self, collection: Collection, datasource: Datasource[BoundCollectio
3333
super().__init__(collection, datasource)
3434
self._replacer: SearchDefinition = None
3535
self._searchable = len(self._get_searchable_fields(self.child_collection, False)) > 0
36-
self._bypass_searchable = False
3736

3837
def disable_search(self):
3938
self._searchable = False
4039
self.mark_schema_as_dirty()
4140

42-
def bypass_search(self):
43-
# only used when a disable search was done on server RPC
44-
self._bypass_searchable = True
45-
self.mark_schema_as_dirty()
46-
4741
def replace_search(self, replacer: SearchDefinition):
4842
self._replacer = replacer
4943
self._searchable = True
5044
self.mark_schema_as_dirty()
5145

5246
def _refine_schema(self, sub_schema: CollectionSchema) -> CollectionSchema:
53-
if sub_schema["searchable"] is True:
54-
self._bypass_searchable = True
55-
return {
56-
**sub_schema,
57-
"searchable": self._searchable if self._bypass_searchable is False else True,
58-
}
47+
return {**sub_schema, "searchable": self._searchable}
5948

6049
def _default_replacer(self, search: str, extended: bool) -> ConditionTree:
6150
searchable_fields = self._get_searchable_fields(self.child_collection, extended)
@@ -66,7 +55,7 @@ def _default_replacer(self, search: str, extended: bool) -> ConditionTree:
6655
async def _refine_filter(
6756
self, caller: User, _filter: Union[Optional[PaginatedFilter], Optional[Filter]]
6857
) -> Optional[Union[PaginatedFilter, Filter]]:
69-
if _filter is None or self._bypass_searchable:
58+
if _filter is None:
7059
return _filter
7160

7261
# Search string is not significant

0 commit comments

Comments
 (0)