spring-projects / spring-shell

Spring based shell
http://projects.spring.io/spring-shell/
Apache License 2.0
724 stars 393 forks source link

ComponentFlow single and multi selectItems should behave same #946

Closed timnick-snow closed 9 months ago

timnick-snow commented 9 months ago
        ComponentFlow flow = componentFlowBuilder.clone().reset()
                .withSingleItemSelector("single1")
                .name("Single1")
                .selectItems(singleSelectItems)
                .and()
                .withMultiItemSelector("multi1")
                .name("Multi1")
                .selectItems(multiSelectItems)
                .and()
                .build();

In multiple choice, selectItems accepts a list type, but in a single selection, it accepts a map. Map will cause the final display order to be inconsistent with the order in which it was added, which makes me confused why it was designed as a map.

btw, if you use SingleItemSelector directly without component flow, you still use list to build the selectItems. It works well without any surprises.

        SingleItemSelector<String, SelectorItem<String>> component = new SingleItemSelector<>(getTerminal(),
                singleSelectItems, "testSimple", null);
jvalkeal commented 9 months ago

You're right about this. I believe what happened was that single select were done first and it really needed only key/value. Multi select needed additional structure to keep states and went with more direct route. They are sharing same facilities but we "forget" to make single side more convenient or similar.

jvalkeal commented 9 months ago

I tentatively put this to next releases next week. Hopefully we can sneak it in.

jvalkeal commented 9 months ago

Btw both single and multi selects has a way to define sorting which is one other way to handle the issue.