Skip to content

Commit

Permalink
fix object options in block kit
Browse files Browse the repository at this point in the history
  • Loading branch information
koonwen committed Nov 11, 2024
1 parent 2ecc5cb commit 9178f23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
12 changes: 6 additions & 6 deletions lib/block_kit.atd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type multi_static_select_menu <ocaml attr="deriving make"> = {
?action_id : string nullable <ocaml valid="fun s -> String.length s <= 255">;
?options : option_object list nullable <ocaml valid="fun l -> List.length <= 100">;
?option_groups : option_group list nullable <ocaml valid="fun l -> List.length <= 100">;
?inital_options : options list nullable;
?initial_option : option_object list nullable;
?confirm : confirmation_dialog_object nullable;
?max_selected_items : int nullable <ocaml valid="fun i -> i >= 1">;
?focus_on_load : bool nullable;
Expand All @@ -103,7 +103,7 @@ type static_select_menu <ocaml attr="deriving make"> = {
?action_id : string nullable <ocaml valid="fun s -> String.length s <= 255">;
?options : option_object list nullable;
?option_groups : option_group list nullable;
?initial_option : options nullable;
?initial_option: option_object nullable;
?confirm : confirmation_dialog_object nullable;
?focus_on_load : bool nullable;
?place_holder : text_object nullable
Expand All @@ -124,10 +124,10 @@ type confirmation_dialog_object <ocaml attr="deriving make"> = {
?style : style nullable;
}

type options = [
| Option_object of option_object
| Option_group of option_group
] <ocaml repr = "classic">
(* type options = [ *)
(* | Option_object of option_object *)
(* | Option_group of option_group *)
(* ] <ocaml repr = "classic"> *)

type option_object <ocaml attr="deriving make"> = {
text : text_object;
Expand Down
16 changes: 6 additions & 10 deletions lib/block_kit_safe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@ let make_multi_static_select_menu ?action_id ~(options : option_object list)
)
place_holder
in
let initial_option = Option.map (fun v -> List.map (fun o -> Option_object o) v) initial_option in
Block_kit_j.(
Multi_static_select_menu
(make_multi_static_select_menu ?action_id ~options ?inital_options:initial_option ?confirm ?max_selected_items
?focus_on_load ?place_holder ()
(make_multi_static_select_menu ?action_id ~options ?initial_option ?confirm ?max_selected_items ?focus_on_load
?place_holder ()
)
)

let make_multi_static_select_menu_group ?action_id ~(option_groups : option_group list)
?(initial_option : option_group list option) ?confirm ?max_selected_items ?focus_on_load
?(initial_option : option_object list option) ?confirm ?max_selected_items ?focus_on_load
?(place_holder : plain_text option) ()
=
let place_holder =
Expand All @@ -86,11 +85,10 @@ let make_multi_static_select_menu_group ?action_id ~(option_groups : option_grou
)
place_holder
in
let initial_option = Option.map (fun v -> List.map (fun o -> Option_group o) v) initial_option in
Block_kit_j.(
Multi_static_select_menu
(make_multi_static_select_menu ?action_id ~option_groups ?inital_options:initial_option ?confirm
?max_selected_items ?focus_on_load ?place_holder ()
(make_multi_static_select_menu ?action_id ~option_groups ?initial_option ?confirm ?max_selected_items
?focus_on_load ?place_holder ()
)
)

Expand All @@ -107,14 +105,13 @@ let make_static_select_menu ?action_id ~(options : option_object list) ?(initial
)
place_holder
in
let initial_option = Option.map (fun o -> Option_object o) initial_option in
Block_kit_j.(
Static_select_menu
(make_static_select_menu ?action_id ~options ?initial_option ?confirm ?focus_on_load ?place_holder ())
)

let make_static_select_menu_group ?action_id ~(option_groups : option_group list)
?(initial_option : option_group option) ?confirm ?focus_on_load ?(place_holder : plain_text option) ()
?(initial_option : option_object option) ?confirm ?focus_on_load ?(place_holder : plain_text option) ()
=
if List.length option_groups > 100 then raise (Invalid_argument "option objects limit 100 exceeded");
let place_holder =
Expand All @@ -126,7 +123,6 @@ let make_static_select_menu_group ?action_id ~(option_groups : option_group list
)
place_holder
in
let initial_option = Option.map (fun o -> Option_group o) initial_option in
Block_kit_j.(
Static_select_menu
(make_static_select_menu ?action_id ~option_groups ?initial_option ?confirm ?focus_on_load ?place_holder ())
Expand Down
3 changes: 2 additions & 1 deletion lib_test/test_block_kit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ let make_modal_v2 (todo_list_options : todo_list_option list) =
)
todo_list_options
in
make_static_select_menu ~options ()
let initial_option = List.hd options in
make_static_select_menu ~initial_option ~options ()
in
let label = make_plain_text ~text:"Todo-list" () in
make_input ~label ~element:static_select_menu ()
Expand Down

0 comments on commit 9178f23

Please sign in to comment.