Browse Source

ref(modal): simplify functional footer passing to remove componentWillUpdate

master
Leonard Kim 7 years ago
parent
commit
72c1fa38be
1 changed files with 32 additions and 67 deletions
  1. 32
    67
      react/features/base/dialog/components/StatelessDialog.web.js

+ 32
- 67
react/features/base/dialog/components/StatelessDialog.web.js View File

102
         this._onDialogDismissed = this._onDialogDismissed.bind(this);
102
         this._onDialogDismissed = this._onDialogDismissed.bind(this);
103
         this._onKeyDown = this._onKeyDown.bind(this);
103
         this._onKeyDown = this._onKeyDown.bind(this);
104
         this._onSubmit = this._onSubmit.bind(this);
104
         this._onSubmit = this._onSubmit.bind(this);
105
+        this._renderFooter = this._renderFooter.bind(this);
105
         this._setDialogElement = this._setDialogElement.bind(this);
106
         this._setDialogElement = this._setDialogElement.bind(this);
106
-
107
-        this._Footer = this._createFooterConstructor(props);
108
-    }
109
-
110
-    /**
111
-     * React Component method that executes before the component is updated.
112
-     *
113
-     * @inheritdoc
114
-     * @param {Object} nextProps - The next properties, before the update.
115
-     * @returns {void}
116
-     */
117
-    componentWillUpdate(nextProps) {
118
-        // If button states have changed, update the Footer constructor function
119
-        // so buttons of the proper state are rendered.
120
-        if (nextProps.okDisabled !== this.props.okDisabled
121
-                || nextProps.cancelDisabled !== this.props.cancelDisabled
122
-                || nextProps.submitDisabled !== this.props.submitDisabled) {
123
-            this._Footer = this._createFooterConstructor(nextProps);
124
-        }
125
     }
107
     }
126
 
108
 
127
     /**
109
     /**
142
         return (
124
         return (
143
             <Modal
125
             <Modal
144
                 autoFocus = { true }
126
                 autoFocus = { true }
145
-                footer = { this._Footer }
127
+                footer = { this._renderFooter }
146
                 heading = { titleString || t(titleKey) }
128
                 heading = { titleString || t(titleKey) }
147
                 i18n = { this.props.i18n }
129
                 i18n = { this.props.i18n }
148
                 onClose = { this._onDialogDismissed }
130
                 onClose = { this._onDialogDismissed }
174
         );
156
         );
175
     }
157
     }
176
 
158
 
177
-    _onCancel: () => Function;
159
+    _renderFooter: () => React$Node;
178
 
160
 
179
     /**
161
     /**
180
-     * Returns a functional component to be used for the modal footer.
162
+     * Returns a ReactElement to display buttons for closing the modal.
181
      *
163
      *
182
-     * @param {Object} options - The configuration for how the buttons in the
183
-     * footer should display. Essentially {@code StatelessDialog} props should
184
-     * be passed in.
164
+     * @param {Object} propsFromModalFooter - The props passed in from the
165
+     * {@link ModalFooter} component.
185
      * @private
166
      * @private
186
      * @returns {ReactElement}
167
      * @returns {ReactElement}
187
      */
168
      */
188
-    _createFooterConstructor(options) {
169
+    _renderFooter(propsFromModalFooter) {
189
         // Filter out falsy (null) values because {@code ButtonGroup} will error
170
         // Filter out falsy (null) values because {@code ButtonGroup} will error
190
         // if passed in anything but buttons with valid type props.
171
         // if passed in anything but buttons with valid type props.
191
         const buttons = [
172
         const buttons = [
192
-            this._renderOKButton(options),
193
-            this._renderCancelButton(options)
173
+            this._renderOKButton(),
174
+            this._renderCancelButton()
194
         ].filter(Boolean);
175
         ].filter(Boolean);
195
 
176
 
196
-        return function Footer(modalFooterProps) {
197
-            return (
198
-                <ModalFooter showKeyline = { modalFooterProps.showKeyline } >
199
-                    {
200
-
201
-                        /**
202
-                         * Atlaskit has this empty span (JustifySim) so...
203
-                         */
204
-                    }
205
-                    <span />
206
-                    <ButtonGroup>
207
-                        { buttons }
208
-                    </ButtonGroup>
209
-                </ModalFooter>
210
-            );
211
-        };
177
+        return (
178
+            <ModalFooter showKeyline = { propsFromModalFooter.showKeyline } >
179
+                {
180
+
181
+                    /**
182
+                     * Atlaskit has this empty span (JustifySim) so...
183
+                     */
184
+                }
185
+                <span />
186
+                <ButtonGroup>
187
+                    { buttons }
188
+                </ButtonGroup>
189
+            </ModalFooter>
190
+        );
212
     }
191
     }
213
 
192
 
214
     _onCancel: () => void;
193
     _onCancel: () => void;
257
     /**
236
     /**
258
      * Renders Cancel button.
237
      * Renders Cancel button.
259
      *
238
      *
260
-     * @param {Object} options - The configuration for the Cancel button.
261
-     * @param {boolean} options.cancelDisabled - True if the cancel button
262
-     * should not be rendered.
263
-     * @param {string} options.cancelTitleKey - The translation key to use as
264
-     * text on the button.
265
-     * @param {boolean} options.isModal - True if the cancel button should not
266
-     * be rendered.
267
      * @private
239
      * @private
268
      * @returns {ReactElement|null} The Cancel button if enabled and dialog is
240
      * @returns {ReactElement|null} The Cancel button if enabled and dialog is
269
      * not modal.
241
      * not modal.
270
      */
242
      */
271
-    _renderCancelButton(options = {}) {
272
-        if (options.cancelDisabled
273
-                || options.isModal
274
-                || options.hideCancelButton) {
243
+    _renderCancelButton() {
244
+        if (this.props.cancelDisabled
245
+            || this.props.isModal
246
+            || this.props.hideCancelButton) {
275
             return null;
247
             return null;
276
         }
248
         }
277
 
249
 
286
                 key = 'cancel'
258
                 key = 'cancel'
287
                 onClick = { this._onCancel }
259
                 onClick = { this._onCancel }
288
                 type = 'button'>
260
                 type = 'button'>
289
-                { t(options.cancelTitleKey || 'dialog.Cancel') }
261
+                { t(this.props.cancelTitleKey || 'dialog.Cancel') }
290
             </Button>
262
             </Button>
291
         );
263
         );
292
     }
264
     }
294
     /**
266
     /**
295
      * Renders OK button.
267
      * Renders OK button.
296
      *
268
      *
297
-     * @param {Object} options - The configuration for the OK button.
298
-     * @param {boolean} options.okDisabled - True if the button should display
299
-     * as disabled and clicking should have no effect.
300
-     * @param {string} options.okTitleKey - The translation key to use as text
301
-     * on the button.
302
-     * @param {boolean} options.submitDisabled - True if the button should not
303
-     * be rendered.
304
      * @private
269
      * @private
305
      * @returns {ReactElement|null} The OK button if enabled.
270
      * @returns {ReactElement|null} The OK button if enabled.
306
      */
271
      */
307
-    _renderOKButton(options = {}) {
308
-        if (options.submitDisabled) {
272
+    _renderOKButton() {
273
+        if (this.props.submitDisabled) {
309
             return null;
274
             return null;
310
         }
275
         }
311
 
276
 
318
                 appearance = 'primary'
283
                 appearance = 'primary'
319
                 form = 'modal-dialog-form'
284
                 form = 'modal-dialog-form'
320
                 id = { OK_BUTTON_ID }
285
                 id = { OK_BUTTON_ID }
321
-                isDisabled = { options.okDisabled }
286
+                isDisabled = { this.props.okDisabled }
322
                 key = 'submit'
287
                 key = 'submit'
323
                 onClick = { this._onSubmit }
288
                 onClick = { this._onSubmit }
324
                 type = 'button'>
289
                 type = 'button'>
325
-                { t(options.okTitleKey || 'dialog.Ok') }
290
+                { t(this.props.okTitleKey || 'dialog.Ok') }
326
             </Button>
291
             </Button>
327
         );
292
         );
328
     }
293
     }

Loading…
Cancel
Save