Skip to content

Commit 41fc9f1

Browse files
Merge pull request #559 from neuroinformatics-unit/only_refresh_datatype_checkbox
2 parents f57de6d + 8413951 commit 41fc9f1

3 files changed

Lines changed: 76 additions & 20 deletions

File tree

datashuttle/tui/tabs/create_folders.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ def compose(self) -> ComposeResult:
9494
)
9595
yield Label("Datatype(s)", id="create_folders_datatype_label")
9696
yield Container(
97-
DatatypeCheckboxes(
98-
self.interface, id="create_folders_datatype_checkboxes"
99-
)
97+
self.get_datatype_checkboxes_widget(),
98+
id="create_folders_datatype_container", #
10099
)
101100
yield Horizontal(
102101
Button(
@@ -157,9 +156,17 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
157156
)
158157

159158
async def refresh_after_datatypes_changed(self, ignore) -> None:
160-
"""Redisplay the datatype checkboxes."""
161-
await self.recompose()
162-
self.on_mount()
159+
"""Redisplay the datatype checkboxes.
160+
161+
The widget must be completely removed and reinitialised.
162+
"""
163+
container = self.query_one("#create_folders_datatype_container")
164+
165+
await container.query_one(
166+
"#create_folders_datatype_checkboxes"
167+
).remove()
168+
169+
await container.mount(self.get_datatype_checkboxes_widget())
163170

164171
@require_double_click
165172
def on_clickable_input_clicked(
@@ -534,3 +541,9 @@ def run_local_validation(self, prefix: Prefix) -> tuple[bool, str]:
534541
def update_directorytree_root(self, new_root_path: Path) -> None:
535542
"""Refresh the tree through the reactive attribute `path`."""
536543
self.query_one("#create_folders_directorytree").path = new_root_path
544+
545+
def get_datatype_checkboxes_widget(self):
546+
"""Create the datatype checkboxes, centralised as used in multiple places."""
547+
return DatatypeCheckboxes(
548+
self.interface, id="create_folders_datatype_checkboxes"
549+
)

datashuttle/tui/tabs/transfer.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,8 @@ def compose(self) -> ComposeResult:
141141
),
142142
# These are almost identical to create tab
143143
Label("Datatype(s)", id="transfer_datatype_label"),
144-
DatatypeCheckboxes(
145-
self.interface,
146-
create_or_transfer="transfer",
147-
id="transfer_custom_datatype_checkboxes",
148-
),
149-
Button(
150-
"Displayed Datatypes",
151-
id="transfer_tab_displayed_datatypes_button",
152-
),
144+
self.get_datatypes_checkboxes_widget(),
145+
self.get_displayed_datatypes_button(),
153146
]
154147

155148
yield TransferStatusTree(
@@ -325,11 +318,28 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
325318
)
326319

327320
async def refresh_after_datatype_changed(self, ignore):
328-
"""Refresh Checkboxes after the shown datatypes have changed."""
329-
await self.recompose()
330-
self.on_mount()
331-
self.query_one("#transfer_custom_radiobutton").value = True
332-
self.switch_transfer_widgets_display()
321+
"""Refresh Checkboxes after the shown datatypes have changed.
322+
323+
The widget must be completely removed and reinitialised.
324+
This means the button underneath it must also be removed and
325+
re-added, or it ends up above the datatype checkbox widget.
326+
"""
327+
container = self.query_one("#transfer_params_container")
328+
await container.query_one(
329+
"#transfer_custom_datatype_checkboxes"
330+
).remove()
331+
await container.query_one(
332+
"#transfer_tab_displayed_datatypes_button"
333+
).remove()
334+
335+
(
336+
Button(
337+
"Displayed Datatypes",
338+
id="transfer_tab_displayed_datatypes_button",
339+
),
340+
)
341+
await container.mount(self.get_datatypes_checkboxes_widget())
342+
await container.mount(self.get_displayed_datatypes_button())
333343

334344
def on_custom_directory_tree_directory_tree_special_key_press(
335345
self, event: CustomDirectoryTree.DirectoryTreeSpecialKeyPress
@@ -411,3 +421,18 @@ def transfer_data(self) -> Worker[InterfaceOutput]:
411421
self.app.call_from_thread(self.reload_directorytree)
412422

413423
return success, output
424+
425+
def get_datatypes_checkboxes_widget(self):
426+
"""Create the datatype checkboxes, centralised as used in multiple places."""
427+
return DatatypeCheckboxes(
428+
self.interface,
429+
create_or_transfer="transfer",
430+
id="transfer_custom_datatype_checkboxes",
431+
)
432+
433+
def get_displayed_datatypes_button(self):
434+
"""Create the datatype button, centralised as used in multiple places."""
435+
return Button(
436+
"Displayed Datatypes",
437+
id="transfer_tab_displayed_datatypes_button",
438+
)

tests/tests_tui/test_tui_datatypes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ async def test_select_displayed_datatypes_create(
2424
pilot, project_name
2525
)
2626

27+
self.fill_input(pilot, "#create_folders_subject_input", "sub-001")
28+
2729
# Open the datatypes screen
2830
await self.scroll_to_click_pause(
2931
pilot,
@@ -124,6 +126,14 @@ async def test_select_displayed_datatypes_create(
124126
is False
125127
)
126128

129+
# Check that input information is not deleted on refresh
130+
assert (
131+
pilot.app.screen.query_one(
132+
"#create_folders_subject_input"
133+
).value
134+
== "sub-001"
135+
)
136+
127137
# Confirm also that narrow datatypes are not shown.
128138
with pytest.raises(BaseException):
129139
pilot.app.screen.query_one(
@@ -148,6 +158,7 @@ async def test_select_displayed_datatypes_transfer(
148158
await self.scroll_to_click_pause(
149159
pilot, "#transfer_custom_radiobutton"
150160
)
161+
await self.fill_input(pilot, "#transfer_subject_input", "sub-001")
151162
await self.scroll_to_click_pause(
152163
pilot,
153164
"#transfer_tab_displayed_datatypes_button",
@@ -159,6 +170,7 @@ async def test_select_displayed_datatypes_transfer(
159170
pilot.app.screen.query_one(
160171
"#displayed_datatypes_selection_list"
161172
).toggle_all()
173+
162174
await self.scroll_to_click_pause(
163175
pilot, "#displayed_datatypes_save_button"
164176
)
@@ -174,6 +186,12 @@ async def test_select_displayed_datatypes_transfer(
174186
is False
175187
)
176188

189+
# Check that input information is not deleted on refresh
190+
assert (
191+
pilot.app.screen.query_one("#transfer_subject_input").value
192+
== "sub-001"
193+
)
194+
177195
# Turn on a single checkbox and run a transfer, checking that
178196
# the underlying function is called correctly (monkeypatch)
179197
await self.scroll_to_click_pause(

0 commit comments

Comments
 (0)