From 7dbe365b6bf065dd97a7899b216766ed88aa9ea6 Mon Sep 17 00:00:00 2001 From: mrllama123 Date: Wed, 5 Jun 2024 21:28:24 +1200 Subject: [PATCH 1/2] do not unmount keyFilter widget when scanning table when reenabling query mode form doing a scan it was causing the key names e.g primary key to be lost in the keyFilter widget --- dyno_viewer/components/screens/query.py | 5 +++-- tests/unit/screens/test_query_screen.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dyno_viewer/components/screens/query.py b/dyno_viewer/components/screens/query.py index e0312d4..72c6171 100644 --- a/dyno_viewer/components/screens/query.py +++ b/dyno_viewer/components/screens/query.py @@ -166,9 +166,10 @@ def toggle_scan_mode(self, changed: Switch.Changed) -> None: self.scan_mode = changed.value if changed.value: key_filter = self.query_one(KeyFilter) - key_filter.remove() + key_filter.display = False else: - self.mount(KeyFilter(id="keyFilter"), after="#scanToggle") + key_filter = self.query_one(KeyFilter) + key_filter.display = True # watcher methods diff --git a/tests/unit/screens/test_query_screen.py b/tests/unit/screens/test_query_screen.py index 23a91d2..ef4306c 100644 --- a/tests/unit/screens/test_query_screen.py +++ b/tests/unit/screens/test_query_screen.py @@ -278,7 +278,11 @@ async def test_run_query_scan(screen_app, ddb_table, ddb_table_with_data): "tab", ) - assert not pilot.app.query(KeyFilter) + key_filter = pilot.app.query_one(KeyFilter) + + assert key_filter + assert not key_filter.display + await assert_filter_one(pilot, "test", "test1") # send run query message back to root app @@ -311,7 +315,10 @@ async def test_run_query_scan_no_filters(screen_app, ddb_table, ddb_table_with_d "tab", ) - assert not pilot.app.query(KeyFilter) + key_filter = pilot.app.query_one(KeyFilter) + + assert key_filter + assert not key_filter.display # send run query message back to root app await type_commands(["tab", "r"], pilot) From 14db4f4b39e5599e780d3551b61fe644d989ea6c Mon Sep 17 00:00:00 2001 From: mrllama123 Date: Wed, 5 Jun 2024 21:29:57 +1200 Subject: [PATCH 2/2] simplify code --- dyno_viewer/components/screens/query.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dyno_viewer/components/screens/query.py b/dyno_viewer/components/screens/query.py index 72c6171..3c4c8ac 100644 --- a/dyno_viewer/components/screens/query.py +++ b/dyno_viewer/components/screens/query.py @@ -164,11 +164,10 @@ def on_mount(self): @on(Switch.Changed, "#scanToggleSwitch") def toggle_scan_mode(self, changed: Switch.Changed) -> None: self.scan_mode = changed.value + key_filter = self.query_one(KeyFilter) if changed.value: - key_filter = self.query_one(KeyFilter) key_filter.display = False else: - key_filter = self.query_one(KeyFilter) key_filter.display = True # watcher methods