Skip to content

Commit e1ba4c5

Browse files
committed
feat: Allow by-name access for card commands.
1 parent a6f7613 commit e1ba4c5

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

card.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func loadCard(ns *Namespace, c CardD) *Card {
8080
}
8181
}
8282
}
83-
if k == "items" || k == "secondary_items" || k == "buttons" {
83+
if k == "items" || k == "secondary_items" || k == "buttons" || k == "commands" {
8484
if card.nameComponentMap == nil {
8585
card.nameComponentMap = make(map[string]any)
8686
}
@@ -239,7 +239,7 @@ func fillNameComponentMap(m map[string]any, wrappedItems any) {
239239
}
240240
if name, ok := component["name"]; ok {
241241
if n, ok := name.(string); ok {
242-
m[n] = item
242+
m[n] = component
243243
}
244244
}
245245
if items, ok := component["items"]; ok {

e2e/test_by_name_updates.py

+23
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,26 @@ async def serve(q: Q):
185185
with AppRunner(code):
186186
page.goto('http://localhost:10101')
187187
expect(page.get_by_text("New text")).to_be_visible()
188+
189+
190+
def test_by_name_updates_card_commands(page: Page):
191+
code = '''
192+
from h2o_wave import main, app, Q, ui
193+
194+
195+
@app('/')
196+
async def serve(q: Q):
197+
q.page['form'] = ui.form_card(
198+
box='1 1 3 3',
199+
items=[],
200+
commands=[
201+
ui.command(name='step1', label='Step 1'),
202+
]
203+
)
204+
q.page['form'].step1.label = 'New text'
205+
await q.page.save()
206+
'''
207+
with AppRunner(code):
208+
page.goto('http://localhost:10101')
209+
page.click('[data-test="form"]:nth-child(2) > div')
210+
expect(page.get_by_text("New text")).to_be_visible()

ts/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ const
767767
v = buf
768768
}
769769
}
770-
if (k === "items" || k === "secondary_items" || k === "buttons") fillComponentNameMap(componentCache, v)
770+
if (k === 'items' || k === 'secondary_items' || k === 'buttons' || k === 'commands') fillComponentNameMap(componentCache, v)
771771
set([k], v)
772772
}
773773
},

0 commit comments

Comments
 (0)