Skip to content

Commit

Permalink
feat(MultipleVote): create a config input for the vote limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaskur committed Mar 11, 2024
1 parent 1a6db44 commit c07aed9
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/cards/NewPollFormCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class NewPollFormCard extends BaseCard {
if (this.config.autoClose) {
this.buildAutoCloseSection();
}
this.buildMultipleVoteSection();
}

buildTopicInputSection() {
Expand Down Expand Up @@ -159,6 +160,67 @@ export default class NewPollFormCard extends BaseCard {
});
}

buildMultipleVoteSection() {
const widgets: chatV1.Schema$GoogleAppsCardV1Widget[] = [];

const items = [
{
'text': 'No Limit',
'value': '0',
'selected': false,
},
{
'text': '1',
'value': '1',
'selected': false,
},
{
'text': '2',
'value': '2',
'selected': false,
},
{
'text': '3',
'value': '3',
'selected': false,
},
{
'text': '4',
'value': '4',
'selected': false,
},
{
'text': '5',
'value': '5',
'selected': false,
},
{
'text': '6',
'value': '6',
'selected': false,
},
];
// set selected item
if (this.config.voteLimit !== undefined && items?.[this.config.voteLimit]) {
items[this.config.voteLimit].selected = true;
} else {
items[1].selected = true;
}
widgets.push(
{
'selectionInput': {
'type': 'DROPDOWN',
'label': 'Vote Limit (Max options that can be voted)',
'name': 'vote_limit',
items,
},
});

this.card.sections!.push({
widgets,
});
}

buildHelpText() {
return {
textParagraph: {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function getConfigFromInput(formValues: PollFormInputs) {
state.autoMention = getStringInputValue(formValues.auto_mention) === '1';
state.closedTime = parseInt(formValues.close_schedule_time?.dateTimeInput!.msSinceEpoch ?? '0');
state.choices = getChoicesFromInput(formValues);
state.voteLimit = parseInt(getStringInputValue(formValues.vote_limit) || '1');
return state;
}

Expand Down
48 changes: 48 additions & 0 deletions tests/json/configuration_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,54 @@
}
}
]
},
{
"widgets": [
{
"selectionInput": {
"type": "DROPDOWN",
"label": "Vote Limit (Max options that can be voted)",
"name": "vote_limit",
"items": [
{
"text": "No Limit",
"value": "0",
"selected": false
},
{
"text": "1",
"value": "1",
"selected": true
},
{
"text": "2",
"value": "2",
"selected": false
},
{
"text": "3",
"value": "3",
"selected": false
},
{
"text": "4",
"value": "4",
"selected": false
},
{
"text": "5",
"value": "5",
"selected": false
},
{
"text": "6",
"value": "6",
"selected": false
}
]
}
}
]
}
],
"fixedFooter": {
Expand Down

0 comments on commit c07aed9

Please sign in to comment.