| Conditions | 4 |
| Total Lines | 58 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import {splitMessage} from './helpers/utils'; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Build the configuration form. |
||
| 77 | * |
||
| 78 | * @param {object} options - Initial state to render with form |
||
| 79 | * @param {string|undefined} options.topic - Topic of poll (optional) |
||
| 80 | * @param {string[]|undefined} options.choices - Text of choices to display to users (optional) |
||
| 81 | * @returns {object} card |
||
| 82 | */ |
||
| 83 | export function buildConfigurationForm(options: PollState): chatV1.Schema$GoogleAppsCardV1Card { |
||
| 84 | const widgets = []; |
||
| 85 | widgets.push(helpText()); |
||
| 86 | widgets.push(topicInput(options.topic)); |
||
| 87 | for (let i = 0; i < MAX_NUM_OF_OPTIONS; ++i) { |
||
| 88 | const choice = options?.choices?.[i]; |
||
| 89 | widgets.push(optionInput(i, choice)); |
||
| 90 | } |
||
| 91 | |||
| 92 | // Assemble the card |
||
| 93 | return { |
||
| 94 | 'sections': [ |
||
| 95 | { |
||
| 96 | 'collapsible': true, |
||
| 97 | 'uncollapsibleWidgetsCount': 6, |
||
| 98 | widgets, |
||
| 99 | }, |
||
| 100 | { |
||
| 101 | 'widgets': [ |
||
| 102 | { |
||
| 103 | 'decoratedText': { |
||
| 104 | 'bottomLabel': 'If this checked the voters name will be not shown', |
||
| 105 | 'text': 'Anonymous voter', |
||
| 106 | 'switchControl': { |
||
| 107 | 'controlType': 'SWITCH', |
||
| 108 | 'name': 'is_anonymous', |
||
| 109 | 'value': '1', |
||
| 110 | 'selected': false, |
||
| 111 | }, |
||
| 112 | }, |
||
| 113 | 'horizontalAlignment': 'CENTER', |
||
| 114 | }, |
||
| 115 | { |
||
| 116 | 'decoratedText': { |
||
| 117 | 'bottomLabel': 'After the poll is created, other member can add more option', |
||
| 118 | 'text': 'Allow to add more option(s)', |
||
| 119 | 'switchControl': { |
||
| 120 | 'controlType': 'SWITCH', |
||
| 121 | 'name': 'allow_add_option', |
||
| 122 | 'value': '1', |
||
| 123 | 'selected': true, |
||
| 124 | }, |
||
| 125 | }, |
||
| 126 | 'horizontalAlignment': 'CENTER', |
||
| 127 | }, |
||
| 128 | ], |
||
| 129 | }, |
||
| 130 | ], |
||
| 131 | 'fixedFooter': fixedFooter(), |
||
| 132 | }; |
||
| 154 |