From 1501401b73fc67d01508ed0d2a8d82af3c62dcc2 Mon Sep 17 00:00:00 2001 From: Harsh Patel Date: Mon, 22 Mar 2021 16:09:49 +0000 Subject: [PATCH] fix: make minor modifications for form submit on single page form --- .../main/webapp/components/BaseFormView.jsx | 38 ++++++------------- .../components/ConfigurationFormView.jsx | 27 ++++++------- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/BaseFormView.jsx b/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/BaseFormView.jsx index 49979dbf4..654edd3b6 100644 --- a/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/BaseFormView.jsx +++ b/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/BaseFormView.jsx @@ -24,7 +24,7 @@ class BaseFormView extends PureComponent { const globalConfig = getUnifiedConfigs(); this.appName = globalConfig.meta.name; this.endpoint = - props.mode === MODE_EDIT + props.mode === MODE_EDIT || props.mode === MODE_CONFIG ? `${this.props.serviceName}/${this.props.stanzaName}` : `${this.props.serviceName}`; @@ -167,21 +167,6 @@ class BaseFormView extends PureComponent { } } - // componentDidMount() { - // if(this.props.page === "configuration"){ - // axiosCallWrapper({ - // serviceName: this.endpoint, - // handleError: true, - // callbackOnError: (error) => { - // error.uccErrorCode = 'ERR0004'; - // this.setState({error}); - // }, - // }).then((response) => { - // setCurrentServiceState(response.data.entry[0].content); - // }); - // } - // } - handleSubmit = () => { this.props.handleFormSubmit(true, false); if (this.hook && typeof this.hook.onSave === 'function') { @@ -195,8 +180,6 @@ class BaseFormView extends PureComponent { Object.keys(this.state.data).forEach((field) => { datadict[field] = this.state.data[field].value; }); - console.log(datadict); - console.log(this.entities); // Validation of form fields on Submit const validator = new Validator(this.entities); @@ -248,15 +231,16 @@ class BaseFormView extends PureComponent { }) .then((response) => { const val = response?.data?.entry[0]; - const tmpObj = {}; - - tmpObj[val.name] = { - ...val.content, - id: val.id, - name: val.name, - serviceName: this.props.serviceName, - }; if (this.props.mode !== MODE_CONFIG) { + const tmpObj = {}; + + tmpObj[val.name] = { + ...val.content, + id: val.id, + name: val.name, + serviceName: this.props.serviceName, + }; + this.context.setRowData( update(this.context.rowData, { [this.props.serviceName]: { $merge: tmpObj }, @@ -422,7 +406,7 @@ class BaseFormView extends PureComponent { return (
{this.generateWarningMessage()} {this.generateErrorMessage()} diff --git a/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/ConfigurationFormView.jsx b/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/ConfigurationFormView.jsx index 0131f6b4b..6875b52a5 100644 --- a/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/ConfigurationFormView.jsx +++ b/splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/ConfigurationFormView.jsx @@ -17,7 +17,6 @@ function ConfigurationFormView({ serviceName }) { const [isSubmitting, setIsSubmitting] = useState(false); const [currentServiceState, setCurrentServiceState] = useState({}); - // TODO: move this logic to BaseFormView useEffect(() => { axiosCallWrapper({ serviceName: `settings/${serviceName}`, @@ -43,21 +42,17 @@ function ConfigurationFormView({ serviceName }) { throw error; } - return ( + return Object.keys(currentServiceState).length ? ( <> - {Object.keys(currentServiceState).length ? ( - - ) : ( - - )} +