| Conditions | 4 |
| Total Lines | 60 |
| Code Lines | 47 |
| 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 BaseCard from './BaseCard'; |
||
| 80 | |||
| 81 | buildCloseConfigSection() { |
||
| 82 | const widgets: chatV1.Schema$GoogleAppsCardV1Widget[] = [ |
||
| 83 | { |
||
| 84 | 'selectionInput': { |
||
| 85 | 'type': 'DROPDOWN', |
||
| 86 | 'label': 'Allow to manually close poll', |
||
| 87 | 'name': 'type', |
||
| 88 | 'items': [ |
||
| 89 | { |
||
| 90 | 'text': 'Yes, but only creator', |
||
| 91 | 'value': '1', |
||
| 92 | 'selected': this.config.type === ClosableType.CLOSEABLE_BY_CREATOR, |
||
| 93 | }, |
||
| 94 | { |
||
| 95 | 'text': 'Yes, anyone can close', |
||
| 96 | 'value': '2', |
||
| 97 | 'selected': this.config.type === ClosableType.CLOSEABLE_BY_ANYONE, |
||
| 98 | }, |
||
| 99 | { |
||
| 100 | 'text': 'No, I want unclosable poll', |
||
| 101 | 'value': '0', |
||
| 102 | 'selected': this.config.type === ClosableType.UNCLOSEABLE, |
||
| 103 | }, |
||
| 104 | ], |
||
| 105 | }, |
||
| 106 | 'horizontalAlignment': 'START', |
||
| 107 | }, |
||
| 108 | { |
||
| 109 | 'decoratedText': { |
||
| 110 | 'topLabel': '', |
||
| 111 | 'text': 'Automatic close poll at certain time', |
||
| 112 | 'bottomLabel': 'The schedule time will show up', |
||
| 113 | 'switchControl': { |
||
| 114 | 'controlType': 'SWITCH', |
||
| 115 | 'name': 'is_autoclose', |
||
| 116 | 'value': '1', |
||
| 117 | 'selected': this.config.autoclose ?? false, |
||
| 118 | 'onChangeAction': { |
||
| 119 | 'function': 'new_poll_on_change', |
||
| 120 | 'parameters': [], |
||
| 121 | }, |
||
| 122 | }, |
||
| 123 | }, |
||
| 124 | }]; |
||
| 125 | if (this.config.autoclose) { |
||
| 126 | const timezone = offsetToTimezone(this.timezone.offset!); |
||
| 127 | const nowMs = Date.now() + this.timezone.offset! + 18000000; |
||
| 128 | widgets.push( |
||
| 129 | { |
||
| 130 | 'dateTimePicker': { |
||
| 131 | 'label': 'Close schedule time ' + timezone, |
||
| 132 | 'name': 'close_schedule_time', |
||
| 133 | 'type': 'DATE_AND_TIME', |
||
| 134 | 'valueMsEpoch': nowMs.toString(), |
||
| 135 | }, |
||
| 136 | }); |
||
| 137 | } |
||
| 138 | this.card.sections!.push({ |
||
| 139 | widgets, |
||
| 140 | }); |
||
| 187 |