From 4f287a0e6b54f57529162c555c2502b3726d1edd Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 8 Jan 2021 12:37:40 -0800 Subject: [PATCH] Modify multi_select_block to use accessory_block, section_block, and text_block Where this content was previously open-coded and redundant. The commit removes more lines of code than it adds. --- turbot/blocks.py | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/turbot/blocks.py b/turbot/blocks.py index c037b03..dde2cfb 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -11,12 +11,18 @@ def text_block(body): } } -def section_block(block): - return { +def section_block(block, block_id=None): + + block = { "type": "section", **block } + if block_id: + block['block_id'] = block_id + + return block + def actions_block(*elements): return { "type": "actions", @@ -68,28 +74,26 @@ def input_block(label, name, placeholder, optional=False): } def multi_select_block(label, name, placeholder, options, default=None): - return { - "type": "section", - "block_id": name, - "text": { - "type": "mrkdwn", - "text": "*{}*".format(label) + + multi_select = { + "action_id": name, + "type": "multi_static_select", + "placeholder": { + "type": "plain_text", + "text": placeholder }, - "accessory": { - "action_id": name, - "type": "multi_static_select", - "placeholder": { - "type": "plain_text", - "text": placeholder - }, - "options": [ - { - "text": { - "type": "plain_text", - "text": option - }, - "value": option - } for option in options - ] - } + "options": [ + { + "text": { + "type": "plain_text", + "text": option + }, + "value": option + } for option in options + ] } + + return accessory_block( + section_block(text_block("*{}*".format(label)), block_id=name), + multi_select + ) -- 2.43.0