shoomow
shoomow•12mo ago

Using invisible `drawer`

Hey all. I'm trying to refactor an app to not have drawer inside list component, and to set up a single invisible drawer outside of the list component, and use a lightweight button to open and close it. Now, opening the drawer with button is simple enough - but how, inside the drawer, do I reference data of the particular list item which button I clicked? Say, the list has id= a, it contains text component (b) and button ( c), and drawer has id= d. Drawer contains a text component e that is supposed to show value of a.result.selectedRow.b.result or something like that, but I can't figure it out. Please help.
8 Replies
rubenf
rubenf•12mo ago
when you press the button, store the index in the state then reuse that index so button press -> frontend script -> set state + open drawer
shoomow
shoomow•12mo ago
Ok, so I'm gonna tell you what I managed to do with that advice, and I would like you to tell me exactly how wrong I got it. 1. I added inline script for the button with the following code:
import wmill
def main(tool_index: int):
wmill.set_state({"id": tool_index})
return wmill.get_state()
import wmill
def main(tool_index: int):
wmill.set_state({"id": tool_index})
return wmill.get_state()
(pardon Python, I don't speak JS very well) 2. I connected the tool_index input to the index of the list item by setting it to iter.index 3. Inside the drawer, I have a text component that is supposed to render date:
new Date(bg_1.result[c.result.id].added_on).toDateString()
new Date(bg_1.result[c.result.id].added_on).toDateString()
Where bg_1 refers to the runnable that fuels the list, c is the button which state holds tool_index It works, but I wonder if this is how it's supposed to work. Hope I don't come off as presumptuous 🙂 I really appreciate your work.
rubenf
rubenf•12mo ago
SOrry I was unclear, that's not how it's supposed to work 😄 YOu need to use frontend script directly so that it's executed in your browser and can manipulate the browser state directly you're doing an uncessary api call to set and retrieve the state as well as an unecessary compute
shoomow
shoomow•12mo ago
Do you think your team can create some helper article about that? 'Cause I have no idea how to do that.
rubenf
rubenf•12mo ago
state.item = iter.index open('<draweritem>')
shoomow
shoomow•12mo ago
If I understood you correctly, the date then should be referred to as
new Date(bg_1.result[state.item].added_on).toDateString()
new Date(bg_1.result[state.item].added_on).toDateString()
... Right?
rubenf
rubenf•12mo ago
probably yes
shoomow
shoomow•12mo ago
thank you!