Skip to content

Commit 80ed33b

Browse files
committed
fix(selection): improve variable selection
1 parent 0d09ece commit 80ed33b

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

src/e3sm_quickview/components/drawers.py

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def __init__(self, load_variables=None):
7575
)
7676

7777
self.state.setdefault("loading_time", 0)
78+
self.state.setdefault(
79+
"visible_selection_icons",
80+
[
81+
"mdi-eye-outline", # 0 => all
82+
"mdi-eye-check-outline", # 1 => only-checked
83+
"mdi-eye-remove-outline", # 2 => only-unchecked
84+
],
85+
)
86+
self.state.setdefault("visible_selection_icon_idx", 0)
7887

7988
with self:
8089
with html.Div(
@@ -112,6 +121,7 @@ def __init__(self, load_variables=None):
112121
),
113122
size="small",
114123
closable=True,
124+
click="variables_filter === vtype.name ? (variables_filter = '') : (variables_filter = vtype.name)",
115125
click_close=(
116126
"variables_selected = variables_selected.filter(id => variables_listing.find(v => v.id === id)?.type !== vtype.name)"
117127
),
@@ -127,18 +137,27 @@ def __init__(self, load_variables=None):
127137

128138
v3.VTextField(
129139
v_model=("variables_filter", ""),
130-
hide_details=True,
140+
# hide_details=True,
131141
color="primary",
132142
placeholder="Filter",
133143
density="compact",
134144
variant="outlined",
135145
classes="mx-2 flex-0-0",
146+
prepend_icon=[
147+
"visible_selection_icons[visible_selection_icon_idx]"
148+
],
136149
prepend_inner_icon="mdi-magnify",
137150
clearable=True,
151+
click_prepend=self.toggle_visible_selection,
152+
messages=[
153+
"['Show selected and unselected variables','Show only selected variables', 'Show only unselected variables'][visible_selection_icon_idx]"
154+
],
138155
)
139156
with html.Div(style="margin:1px;padding:1px;", classes="flex-fill"):
140157
with client.SizeObserver("var_selection_size"):
158+
# All
141159
with v3.VDataTable(
160+
v_if="visible_selection_icon_idx === 0",
142161
v_model=("variables_selected", []),
143162
show_select=True,
144163
item_value="id",
@@ -169,6 +188,81 @@ def __init__(self, load_variables=None):
169188
classes="text-break text-caption",
170189
)
171190

191+
# Checked only
192+
with v3.VDataTable(
193+
v_if="visible_selection_icon_idx === 1",
194+
v_model=("variables_selected", []),
195+
show_select=True,
196+
item_value="id",
197+
density="compact",
198+
fixed_header=True,
199+
headers=(
200+
"variables_headers",
201+
constants.VAR_HEADERS,
202+
),
203+
items=(
204+
"variables_listing.filter((v) => variables_selected.includes(v.id))",
205+
),
206+
height=["var_selection_size?.size.height || '30vh'"],
207+
style="user-select: none; cursor: pointer;top:0;left:0;",
208+
classes="position-absolute show-scrollbar",
209+
hover=True,
210+
search=("variables_filter", ""),
211+
items_per_page=-1,
212+
hide_default_footer=True,
213+
):
214+
with v3.Template(raw_attrs=['#item.name="{ value }"']):
215+
html.Div(
216+
"{{ value }}",
217+
classes="text-break",
218+
title=["`${value}`"],
219+
)
220+
with v3.Template(raw_attrs=['#item.type="{ value }"']):
221+
html.Div(
222+
"{{ value }}",
223+
classes="text-break text-caption",
224+
)
225+
226+
# Unhecked only
227+
with v3.VDataTable(
228+
v_if="visible_selection_icon_idx === 2",
229+
v_model=("variables_selected", []),
230+
show_select=True,
231+
item_value="id",
232+
density="compact",
233+
fixed_header=True,
234+
headers=(
235+
"variables_headers",
236+
constants.VAR_HEADERS,
237+
),
238+
items=(
239+
"variables_listing.filter((v) => !variables_selected.includes(v.id))",
240+
),
241+
height=["var_selection_size?.size.height || '30vh'"],
242+
style="user-select: none; cursor: pointer;top:0;left:0;",
243+
classes="position-absolute show-scrollbar",
244+
hover=True,
245+
search=("variables_filter", ""),
246+
items_per_page=-1,
247+
hide_default_footer=True,
248+
):
249+
with v3.Template(raw_attrs=['#item.name="{ value }"']):
250+
html.Div(
251+
"{{ value }}",
252+
classes="text-break",
253+
title=["`${value}`"],
254+
)
255+
with v3.Template(raw_attrs=['#item.type="{ value }"']):
256+
html.Div(
257+
"{{ value }}",
258+
classes="text-break text-caption",
259+
)
260+
172261
@change("variables_selected")
173262
def _on_dirty_variable_selection(self, **_):
174263
self.state.variables_loaded = False
264+
265+
def toggle_visible_selection(self):
266+
self.state.visible_selection_icon_idx += 1
267+
if self.state.visible_selection_icon_idx >= 3:
268+
self.state.visible_selection_icon_idx = 0

0 commit comments

Comments
 (0)