Fix Dropdown Example component and example processing logic (#6075)

* fix examples

* helpers

* dropdown
This commit is contained in:
Abubakar Abid 2023-10-24 02:08:35 -07:00 committed by GitHub
parent 447dfe06bf
commit 6b82a9760f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -183,4 +183,9 @@ class Dropdown(FormComponent):
return y
def as_example(self, input_data):
if self.multiselect:
return [
next((c[0] for c in self.choices if c[1] == data), None)
for data in input_data
]
return next((c[0] for c in self.choices if c[1] == input_data), None)

View File

@ -259,16 +259,14 @@ class Examples:
async def load_example(example_id):
processed_example = self.non_none_processed_examples[example_id]
examples = utils.resolve_singleton(processed_example)
return (
update(value=examples, **self.dataset.component_props[0])
if not isinstance(examples, list)
else [
update(value=ex, **self.dataset.component_props[i])
for i, ex in enumerate(examples)
]
)
if len(self.inputs_with_examples) == 1:
return update(
value=processed_example[0], **self.dataset.component_props[0]
)
return [
update(value=processed_example[i], **self.dataset.component_props[i])
for i in range(len(self.inputs_with_examples))
]
if Context.root_block:
self.load_input_event = self.dataset.click(