Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion blockkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,14 @@ def validate(self, component: "Component") -> None:
if not isinstance(source_value, list | tuple | set):
source_value = [source_value]

if not set(source_value).issubset(set(target_value)):
flattened_target = []
for item in target_value:
if isinstance(item, OptionGroup):
flattened_target.extend(item._get_field_value("options") or [])
else:
flattened_target.append(item)

if not set(source_value).issubset(set(flattened_target)):
raise ComponentValidationError(
component,
f"'{self.source_field}' has items that aren't "
Expand Down
40 changes: 8 additions & 32 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,16 +1120,8 @@ def test_builds_option_groups(self):
],
"initial_options": [
{
"label": {
"type": "plain_text",
"text": "Group 1",
},
"options": [
{
"text": {"type": "plain_text", "text": "Option 1"},
"value": "option_1",
}
],
"text": {"type": "plain_text", "text": "Option 1"},
"value": "option_1",
},
],
}
Expand All @@ -1144,9 +1136,7 @@ def test_builds_option_groups(self):
),
],
initial_options=[
OptionGroup(
label="Group 1", options=[Option(text="Option 1", value="option_1")]
)
Option(text="Option 1", value="option_1")
],
).build()
assert got == want
Expand All @@ -1165,9 +1155,7 @@ def test_builds_option_groups(self):
),
)
.add_initial_option(
OptionGroup(
label="Group 1", options=[Option(text="Option 1", value="option_1")]
)
Option(text="Option 1", value="option_1")
)
.build()
)
Expand Down Expand Up @@ -1933,16 +1921,8 @@ def test_builds_option_groups(self):
},
],
"initial_option": {
"label": {
"type": "plain_text",
"text": "Group 1",
},
"options": [
{
"text": {"type": "plain_text", "text": "Option 1"},
"value": "option_1",
}
],
"text": {"type": "plain_text", "text": "Option 1"},
"value": "option_1",
},
}
got = StaticSelect(
Expand All @@ -1955,9 +1935,7 @@ def test_builds_option_groups(self):
label="Group 2", options=[Option(text="Option 2", value="option_2")]
),
],
initial_option=OptionGroup(
label="Group 1", options=[Option(text="Option 1", value="option_1")]
),
initial_option=Option(text="Option 1", value="option_1"),
).build()
assert got == want

Expand All @@ -1975,9 +1953,7 @@ def test_builds_option_groups(self):
),
)
.initial_option(
OptionGroup(
label="Group 1", options=[Option(text="Option 1", value="option_1")]
)
Option(text="Option 1", value="option_1")
)
.build()
)
Expand Down
Loading