sampaiodiego / rocket.chat.app-poll

Rocket.Chat App for creating polls.
MIT License
50 stars 39 forks source link

Single choice option not working #49

Closed dmfilippon closed 3 years ago

dmfilippon commented 4 years ago

Hello!

We've just enabled the poll app @ our server and I can't generate a single choice poll. The 2 choices for votes allow multiple votes.

rc server 3.5.0 rc client 2.17.11

Am I doing something wrong?

pierrel64 commented 4 years ago

+1 same here rc server 3.5.1 app engin : 1.16.0 poll version : 2.0.0

RootPrivileges commented 4 years ago

Can confirm this still doesn't work as expected on RC 3.5.2:

Version 3.5.2
Apps Engine Version 1.16.0

This issue also affects the "confidential" value too. Without modifications to the code, all polls are multi-choice and public voting, and this cannot be changed, even if the alternative options are selected.

Interestingly, forcibly changing the initialValue options in src/lib/createPollModal.ts, recompiling the zip and adding this new build to the server does allow the creation of single-choice/confidential polls, but at the detriment of stopping creation of multi-choice/open polls from them on.

It looks like the Modal isn't correctly reflecting the user's choices in the modal and uses the initialValue setting instead?

RootPrivileges commented 4 years ago

I've done some further digging which may be of interest in isolating the bug. I believe it's a consequence of the use of block.addActionsBlock() to build elements that are user controlled, causes the user's selection in the dropdown to not be written to the state, passing the default option to the created poll.

To demonstrate this, replacing the lines 40-80 in src/lib/createPollModal.ts with an equivalent block.addInputBlock() call works as expected:

    block.addInputBlock({
        blockId: 'config',
        element: block.newStaticSelectElement({
            actionId: 'mode',
            initialValue: 'multiple',
            options: [
                {
                    text: block.newPlainTextObject('Multiple choices'),
                    value: 'multiple',
                },
                {
                    text: block.newPlainTextObject('Single choice'),
                    value: 'single',
                },
            ],
        }),
        label: block.newPlainTextObject(''),
    });

Choosing "Multiple choices and "Single choice" at this dialog creates two polls which behave as expected.

Switching the above snippet back into a block.addActionsBlock() variant (only changes are changing element to elements as an array and removing the label parameter) and the poll displays the current (incorrect) behaviour again.

    block.addActionsBlock({
        blockId: 'config',
        elements: [
            block.newStaticSelectElement({
                actionId: 'mode',
                initialValue: 'multiple',
                options: [
                    {
                        text: block.newPlainTextObject('Multiple choices'),
                        value: 'multiple',
                    },
                    {
                        text: block.newPlainTextObject('Single choice'),
                        value: 'single',
                    },
                ],
            }),
        ],
    });
sampaiodiego commented 4 years ago

I got good news.. there is a fix in Rocket.Chat for this https://github.com/RocketChat/Rocket.Chat/pull/18598

that was just released on version 3.5.3 😬