From 3c39035fdc65b251b6761d2969f28637d97bcc43 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Simonard Date: Wed, 11 Dec 2024 11:11:45 +0100 Subject: [PATCH 1/3] Fix #505 : remove "empty filter" row --- ragna/deploy/_ui/components/metadata_filters_builder.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ragna/deploy/_ui/components/metadata_filters_builder.py b/ragna/deploy/_ui/components/metadata_filters_builder.py index 5307d32d..331531a6 100644 --- a/ragna/deploy/_ui/components/metadata_filters_builder.py +++ b/ragna/deploy/_ui/components/metadata_filters_builder.py @@ -11,7 +11,7 @@ ] NO_CORPUS_KEY = "No corpuses available" -NO_FILTER_KEY = "Empty Filter" +NO_FILTER_KEY = "" class FilterRow(pn.viewable.Viewer): @@ -146,8 +146,6 @@ def __init__(self, corpus_metadata, **params): self.corpus_metadata = corpus_metadata - self.filter_rows = self.create_filter_row() - self.add_filter_row_button = pn.widgets.ButtonIcon( icon="circle-plus", width=25, height=25 ) @@ -174,10 +172,6 @@ def add_filter_row(self, event): self.filter_rows = self.filter_rows + self.create_filter_row() def delete_filter_row(self, event): - if len(self.filter_rows) == 1: - self.reset_filter_rows() - return - filter_row_to_remove = None for filter_row in self.filter_rows: if event.obj == filter_row.delete_button: From f70b5fad67ff3d94c046d4ac317d3ce733dd12e4 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Simonard Date: Mon, 16 Dec 2024 10:00:58 +0100 Subject: [PATCH 2/3] Fix #505 --- .../_ui/components/metadata_filters_builder.py | 18 ++++++++++++------ ragna/deploy/_ui/modal_configuration.py | 6 +++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ragna/deploy/_ui/components/metadata_filters_builder.py b/ragna/deploy/_ui/components/metadata_filters_builder.py index 331531a6..83f77432 100644 --- a/ragna/deploy/_ui/components/metadata_filters_builder.py +++ b/ragna/deploy/_ui/components/metadata_filters_builder.py @@ -151,8 +151,7 @@ def __init__(self, corpus_metadata, **params): ) self.add_filter_row_button.on_click(self.add_filter_row) - self.corpus_names_select.param.watch(self.reset_filter_rows, "value") - + def create_filter_row(self): return [ FilterRow( @@ -165,9 +164,6 @@ def create_filter_row(self): ) ] - def reset_filter_rows(self, event=None): - self.filter_rows = self.create_filter_row() - def add_filter_row(self, event): self.filter_rows = self.filter_rows + self.create_filter_row() @@ -188,7 +184,7 @@ def render_filters_rows(self): *self.filter_rows, css_classes=["metadata-filter-row-collection"], ) - + def construct_metadata_filters(self): metadata_filters = [ filter_row.construct_metadata_filter() @@ -201,6 +197,16 @@ def construct_metadata_filters(self): return MetadataFilter.and_(metadata_filters).to_primitive() def __panel__(self): + + + if len(self.corpus_names) == 0: + return pn.Column( + pn.pane.HTML("No corpus available for selected source storage"), + sizing_mode="stretch_both", + height_policy="max", + ) + + return pn.Column( self.corpus_names_select, pn.pane.HTML("Metadata Filters"), diff --git a/ragna/deploy/_ui/modal_configuration.py b/ragna/deploy/_ui/modal_configuration.py index 04ad655d..8172e99e 100644 --- a/ragna/deploy/_ui/modal_configuration.py +++ b/ragna/deploy/_ui/modal_configuration.py @@ -414,6 +414,7 @@ def add_error_message(self): ) def corpus_or_upload_row(self): if self.corpus_or_upload == USE_CORPUS_LABEL: + if self.config.source_storage_name in self.corpus_names: corpus_names = self.corpus_names[self.config.source_storage_name] else: @@ -428,7 +429,10 @@ def corpus_or_upload_row(self): corpus_names=corpus_names, corpus_metadata=corpus_metadata ) - data = pn.Column(self.metadata_filter_rows_title, self.metadata_filter_rows) + if len(corpus_names) > 0: + data = pn.Column(self.metadata_filter_rows_title, self.metadata_filter_rows) + else: + data = pn.Column(self.metadata_filter_rows) self.error = False return data From 7a7eb256d9482e9439f52f0c3733520f96e3c59f Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Simonard Date: Mon, 16 Dec 2024 10:01:14 +0100 Subject: [PATCH 3/3] Fix #505 --- ragna/deploy/_ui/components/metadata_filters_builder.py | 6 +----- ragna/deploy/_ui/modal_configuration.py | 5 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ragna/deploy/_ui/components/metadata_filters_builder.py b/ragna/deploy/_ui/components/metadata_filters_builder.py index 83f77432..b1a11c5b 100644 --- a/ragna/deploy/_ui/components/metadata_filters_builder.py +++ b/ragna/deploy/_ui/components/metadata_filters_builder.py @@ -151,7 +151,6 @@ def __init__(self, corpus_metadata, **params): ) self.add_filter_row_button.on_click(self.add_filter_row) - def create_filter_row(self): return [ FilterRow( @@ -184,7 +183,7 @@ def render_filters_rows(self): *self.filter_rows, css_classes=["metadata-filter-row-collection"], ) - + def construct_metadata_filters(self): metadata_filters = [ filter_row.construct_metadata_filter() @@ -197,8 +196,6 @@ def construct_metadata_filters(self): return MetadataFilter.and_(metadata_filters).to_primitive() def __panel__(self): - - if len(self.corpus_names) == 0: return pn.Column( pn.pane.HTML("No corpus available for selected source storage"), @@ -206,7 +203,6 @@ def __panel__(self): height_policy="max", ) - return pn.Column( self.corpus_names_select, pn.pane.HTML("Metadata Filters"), diff --git a/ragna/deploy/_ui/modal_configuration.py b/ragna/deploy/_ui/modal_configuration.py index 8172e99e..17ab87d2 100644 --- a/ragna/deploy/_ui/modal_configuration.py +++ b/ragna/deploy/_ui/modal_configuration.py @@ -414,7 +414,6 @@ def add_error_message(self): ) def corpus_or_upload_row(self): if self.corpus_or_upload == USE_CORPUS_LABEL: - if self.config.source_storage_name in self.corpus_names: corpus_names = self.corpus_names[self.config.source_storage_name] else: @@ -430,7 +429,9 @@ def corpus_or_upload_row(self): ) if len(corpus_names) > 0: - data = pn.Column(self.metadata_filter_rows_title, self.metadata_filter_rows) + data = pn.Column( + self.metadata_filter_rows_title, self.metadata_filter_rows + ) else: data = pn.Column(self.metadata_filter_rows)