Skip to content

Class peagen.tui.components.filter_bar.FilterBar

peagen.tui.components.filter_bar.FilterBar

FilterBar()

Bases: Horizontal

Dropdown filters for the dashboard.

Source code in peagen/tui/components/filter_bar.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(self) -> None:
    super().__init__()
    self._select_widget_configs: Dict[Select, Dict[str, Any]] = {}

    select_definitions = [
        {
            "name": "pool_select",
            "prompt": "pool",
            "filter_id": "filter_pool",
            "allow_blank": True,
        },
        {
            "name": "status_select",
            "prompt": "status",
            "filter_id": "filter_status",
            "allow_blank": True,
        },
        {
            "name": "action_select",
            "prompt": "action",
            "filter_id": "filter_action",
            "allow_blank": True,
        },
        {
            "name": "label_select",
            "prompt": "label",
            "filter_id": "filter_label",
            "allow_blank": True,
        },
    ]

    for definition in select_definitions:
        select_widget = Select(
            [],
            prompt=definition["prompt"],
            allow_blank=definition["allow_blank"],
            id=definition["filter_id"],
            compact=True,
        )
        select_widget.styles.width = 20
        setattr(self, definition["name"], select_widget)
        self._select_widget_configs[select_widget] = {
            "allow_blank": definition["allow_blank"]
        }

    self.id_input = Input(placeholder="task id", id="filter_id", compact=True)
    self.id_input.styles.width = 40

id_input instance-attribute

id_input = Input(
    placeholder="task id", id="filter_id", compact=True
)

compose

compose()
Source code in peagen/tui/components/filter_bar.py
63
64
65
66
67
68
def compose(self) -> ComposeResult:
    yield self.id_input
    yield self.pool_select
    yield self.status_select
    yield self.action_select
    yield self.label_select

update_options

update_options(tasks)
Source code in peagen/tui/components/filter_bar.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def update_options(self, tasks: Iterable[dict]) -> None:
    pools = {str(t.get("pool")) for t in tasks if t.get("pool") is not None}
    statuses = {status.value for status in Status}
    actions = {str(t.get("action")) for t in tasks if t.get("action") is not None}
    labels = {
        str(lbl) for t in tasks for lbl in t.get("labels", []) if lbl is not None
    }

    if not self.pool_select.expanded:
        self._set_options(self.pool_select, pools)
    if not self.status_select.expanded:
        self._set_options(self.status_select, statuses)
    if not self.action_select.expanded:
        self._set_options(self.action_select, actions)
    if not self.label_select.expanded:
        self._set_options(self.label_select, labels)

clear

clear()
Source code in peagen/tui/components/filter_bar.py
119
120
121
122
123
124
125
126
127
128
def clear(self) -> None:
    for select_widget in (
        self.pool_select,
        self.status_select,
        self.action_select,
        self.label_select,
    ):
        if self._get_select_allow_blank(select_widget):
            select_widget.value = Select.BLANK
    self.id_input.value = ""