Skip to content

Commit 8835122

Browse files
authored
Merge pull request #59 from Zaloog/lg/bugfix-setting-screen-refresh
Fix SettingScreen Refresh Bug
2 parents 49ee019 + 1f5717a commit 8835122

File tree

7 files changed

+257
-75
lines changed

7 files changed

+257
-75
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

3-
## v0.9.1 (unreleased)
3+
## v0.10.1 (unreleased)
4+
### Fixed
5+
- Fixed bug, that column.status_update selection values do not update, when the column order is changed
6+
- Fixed bug, that ColumnSelector is not updated, when the active board is changed
7+
8+
## v0.10.0
49
### Added
510
- Added option to change the column order via the SettingScreen
611
- Reworked the ColumnListView UI

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "kanban-tui"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
description = "customizable task tui powered by textual"
55
authors = [
66
{ name = "Zaloog", email = "[email protected]" }

src/kanban_tui/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ def update_board_list(self):
141141
def watch_board_list(self):
142142
self.active_board = self.backend.active_board
143143

144-
def watch_active_board(self):
144+
def watch_active_board(self, old_board: Board | None, new_board: Board):
145145
if self.active_board:
146146
self.app.config.set_active_board(
147147
new_active_board_id=self.active_board.board_id
148148
)
149149
self.update_column_list()
150+
# If updating Board, refresh setting screen
151+
if old_board:
152+
self.get_screen("settings", SettingsScreen).needs_refresh = True
150153

151154
def watch_column_list(self):
152155
self.update_task_list()
@@ -169,10 +172,9 @@ def action_show_backend_selector(self):
169172

170173
def action_refresh(self):
171174
self.update_board_list()
172-
self.watch_active_board()
173175
self.watch_column_list()
174176
# used a worker here, so no await
175-
self.screen.load_kanban_board()
177+
self.get_screen("board", BoardScreen).load_kanban_board()
176178

177179
def update_task_list(self):
178180
self.task_list = self.backend.get_tasks_on_active_board()

src/kanban_tui/screens/settings_screen.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from textual import on
44
from textual.binding import Binding
5+
from textual.events import ScreenResume
6+
from textual.reactive import reactive
57
from textual.widget import Widget
68
from textual.widgets import Header, Input, Switch, Button, Select
79
from textual.screen import Screen
@@ -12,6 +14,8 @@
1214

1315

1416
class SettingsScreen(Screen):
17+
needs_refresh: reactive[bool] = reactive(False, init=False)
18+
1519
BINDINGS = [Binding("ctrl+o", "show_overlay", "Jump", priority=True)]
1620

1721
def compose(self) -> Iterable[Widget]:
@@ -33,8 +37,14 @@ def compose(self) -> Iterable[Widget]:
3337
@on(Switch.Changed)
3438
@on(Button.Pressed)
3539
@on(Select.Changed)
36-
def config_changes(self):
40+
def config_changes(self, event):
3741
self.app.needs_refresh = True
3842

43+
@on(ScreenResume)
44+
def update_settings(self):
45+
if self.needs_refresh:
46+
self.query_one(SettingsView).refresh(recompose=True)
47+
self.needs_refresh = False
48+
3949
def action_show_overlay(self) -> None:
4050
self.query_one(Jumper).show()

src/kanban_tui/widgets/settings_widgets.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,32 @@ class BoardColumnsInView(Horizontal):
8282

8383
def on_mount(self):
8484
self.border_title = "board.columns_in_view"
85+
self.set_initial_select_value()
8586

8687
def compose(self) -> Iterable[Widget]:
8788
yield Label("Columns in view")
8889
with self.prevent(Select.Changed):
8990
column_select = VimSelect.from_values(
9091
[i + 1 for i in range(len(self.app.column_list))],
91-
value=self.app.config.board.columns_in_view,
9292
id="select_columns_in_view",
9393
allow_blank=False,
9494
)
95-
column_select.jump_mode = "focus"
96-
yield column_select
95+
column_select.jump_mode = "focus"
96+
yield column_select
9797

9898
@on(Select.Changed)
9999
def update_config(self, event: Select.Changed):
100100
self.app.config.set_columns_in_view(event.select.value)
101101

102+
def set_initial_select_value(self):
103+
select = self.query_one(Select)
104+
amount_cols = len(self.app.column_list)
105+
if self.app.config.board.columns_in_view > amount_cols:
106+
select.value = amount_cols
107+
else:
108+
with self.prevent(Select.Changed):
109+
select.value = self.app.config.board.columns_in_view
110+
102111

103112
class TaskAlwaysExpandedSwitch(Horizontal):
104113
app: "KanbanTui"
@@ -481,6 +490,7 @@ async def move_column_position(
481490
)
482491
# Update state and Widgets
483492
await self.update_columns()
493+
await self.update_dependent_widgets()
484494
# Trigger Update on tab Switch
485495
self.app.needs_refresh = True
486496
self.index = new_position
@@ -605,6 +615,8 @@ def get_select_widget_values(self):
605615

606616

607617
class SettingsView(Vertical):
618+
app: "KanbanTui"
619+
608620
def compose(self) -> Iterable[Widget]:
609621
yield DataBasePathInput(classes="setting-block")
610622
with Horizontal(classes="setting-horizontal"):

tests/app_tests/test_settings_screen.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,82 @@ async def test_column_position_change_up(test_app: KanbanTui):
530530
).highlighted_child.column.position
531531
== 1
532532
)
533+
534+
535+
# Part 1 test for https://github.com/Zaloog/kanban-tui/issues/58
536+
async def test_column_position_change_updates_status_values(test_app: KanbanTui):
537+
async with test_app.run_test(size=APP_SIZE) as pilot:
538+
await pilot.press("ctrl+l")
539+
540+
await pilot.press("ctrl+o")
541+
await pilot.press("c")
542+
assert pilot.app.screen.query_exactly_one(ColumnSelector).has_focus_within
543+
544+
# Go to Doing Item
545+
await pilot.press(*"jj")
546+
547+
# Move Doing Column from position 2 -> 1
548+
await pilot.press("K")
549+
550+
# get Dropdown value at position 1, which should be "Doing at this point"
551+
assert (
552+
(
553+
pilot.app.screen.query_exactly_one(StatusColumnSelector)
554+
.query_one("#select_reset", Select)
555+
._options[1][0]
556+
._text[0]
557+
)
558+
== "Doing"
559+
)
560+
561+
562+
# Part 2 test for https://github.com/Zaloog/kanban-tui/issues/58
563+
async def test_column_selector_updates_on_board_change(test_app: KanbanTui):
564+
async with test_app.run_test(size=APP_SIZE) as pilot:
565+
# Go to Setting Screen to initially load the widgets
566+
await pilot.press("ctrl+l")
567+
568+
# go back to BoardScreen and create a new board
569+
await pilot.press("ctrl+j")
570+
await pilot.press("B")
571+
572+
# Open Board Creation Screen
573+
await pilot.press("n")
574+
575+
# Enter new Icon
576+
await pilot.press(*"bug")
577+
578+
# Enter new board name
579+
await pilot.click("#input_board_name")
580+
await pilot.press(*"Test Board")
581+
582+
# Add Custom Columns
583+
# CustomList visible after switch press
584+
await pilot.click("#switch_use_default_columns")
585+
586+
# Focus input
587+
await pilot.press("tab")
588+
await pilot.press(*"test_column")
589+
# next column input
590+
await pilot.press("tab", "tab")
591+
await pilot.press(*"test_column2")
592+
# delete last column input
593+
await pilot.press("shift+tab", "shift+tab", "delete")
594+
595+
# save board
596+
await pilot.click("#btn_continue_new_board")
597+
# Click to activate new Board
598+
await pilot.press("j", "enter")
599+
600+
# Move to Setting Screen
601+
await pilot.press("ctrl+l")
602+
await pilot.press("ctrl+o")
603+
await pilot.press("c")
604+
assert pilot.app.screen.query_exactly_one(ColumnSelector).has_focus_within
605+
606+
# Go to test_column2
607+
await pilot.press("j")
608+
assert pilot.app.focused.highlighted_child.column.name == "test_column2"
609+
610+
# Columns in View also updates
611+
assert pilot.app.screen.query_one("#select_columns_in_view").value == 1

0 commit comments

Comments
 (0)