Skip to content

Commit 0c897f1

Browse files
committed
refactor: simplify sort option handling and icon label rendering
1 parent 89b24fd commit 0c897f1

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

widgets/workflow_search.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525

2626
class SortOption(typing.NamedTuple):
27-
key: str
2827
label: str
2928
icon: str
3029

@@ -34,31 +33,28 @@ class SortOption(typing.NamedTuple):
3433

3534
class SortOptions(SortOption, GooeyEnum):
3635
FEATURED = SortOption(
37-
key="featured",
3836
label="Featured",
3937
icon=f'<i class="fa-solid fa-star" style="width: {_icon_width};"></i>',
4038
)
4139
UPDATED_AT = SortOption(
42-
key="last_updated",
4340
label="Last Updated",
4441
icon=f'<i class="fa-solid fa-clock" style="width: {_icon_width};"></i>',
4542
)
4643
CREATED_AT = SortOption(
47-
key="created_at",
4844
label="Created At",
4945
icon=f'<i class="fa-solid fa-calendar" style="width: {_icon_width};"></i>',
5046
)
5147
MOST_RUNS = SortOption(
52-
key="most_runs",
5348
label="Most Runs",
5449
icon=f'<i class="fa-solid fa-chart-line" style="width: {_icon_width};"></i>',
5550
)
5651

5752
@classmethod
58-
def get(cls, key=None, default=None):
59-
return next(
60-
(option for option in cls if option.key == key), default or cls.FEATURED
61-
)
53+
def get(cls, key=None):
54+
return super().get(key, default=cls.FEATURED)
55+
56+
def html_icon_label(self) -> str:
57+
return f'{self.icon}<span class="hide-on-small-screens"> {self.label}</span>'
6258

6359

6460
class SearchFilters(BaseModel):
@@ -117,12 +113,6 @@ def render_search_filters(
117113
with gui.div(
118114
className=f"{col_class} d-flex gap-2 justify-content-end align-items-center",
119115
):
120-
sort_options: dict[str, str] = {
121-
(opt.key if opt != SortOptions.get() else ""): (
122-
f'{opt.icon}<span class="hide-on-small-screens"> {opt.label}</span>'
123-
)
124-
for opt in SortOptions
125-
}
126116
with (
127117
gui.styled(
128118
"""
@@ -140,6 +130,12 @@ def render_search_filters(
140130
),
141131
gui.div(),
142132
):
133+
sort_options = {
134+
opt.name if opt != SortOptions.get() else None: (
135+
opt.html_icon_label()
136+
)
137+
for opt in SortOptions
138+
}
143139
search_filters.sort = (
144140
gui.selectbox(
145141
label="",
@@ -379,7 +375,7 @@ def _render_run(pr: PublishedRun):
379375
show_workspace_author = not bool(search_filters and search_filters.workspace)
380376
is_member = bool(getattr(pr, "is_member", False))
381377
hide_last_editor = bool(pr.workspace_id and not is_member)
382-
show_run_count = is_member or search_filters.sort == SortOptions.MOST_RUNS.value
378+
show_run_count = is_member or search_filters.sort == SortOptions.MOST_RUNS.name
383379

384380
render_saved_workflow_preview(
385381
workflow.page_cls,

0 commit comments

Comments
 (0)