From 8fd7b08068d2c5d083aaca1256bc44ac7fa21f8d Mon Sep 17 00:00:00 2001 From: Peter Teixeira Date: Fri, 17 Feb 2017 10:03:38 -0500 Subject: [PATCH] Reduce code duplication in form modal inputs Formerly the code for the password input field was entirely duplicated from the code for the password and duration fields. This refactors that slightly so the input type can be configured in the same way, but it only uses the code for it once. --- .../app/components/common/modal/FormModal.jsx | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/BaragonUI/app/components/common/modal/FormModal.jsx b/BaragonUI/app/components/common/modal/FormModal.jsx index 4780f1bda..8e97f3e54 100644 --- a/BaragonUI/app/components/common/modal/FormModal.jsx +++ b/BaragonUI/app/components/common/modal/FormModal.jsx @@ -25,6 +25,7 @@ function getDefaultFormState(props) { return formState; } + export default class FormModal extends React.Component { constructor(props) { super(props); @@ -270,6 +271,11 @@ export default class FormModal extends React.Component { extraHelp = 'Accepts any English duration (Days, Hr, Min...)'; } + let isPassword = false; + if (formElement.type === FormModal.INPUT_TYPES.PASSWORD) { + isPassword = true; + } + switch (formElement.type) { case FormModal.INPUT_TYPES.BOOLEAN: @@ -292,29 +298,14 @@ export default class FormModal extends React.Component { ); - case FormModal.INPUT_TYPES.PASSWORD: - return ( - -
- - this.handleFormChange(formElement.name, event.target.value)} - /> -
-
- ); - case FormModal.INPUT_TYPES.DURATION: case FormModal.INPUT_TYPES.STRING: + case FormModal.INPUT_TYPES.PASSWORD: return (
-