@@ -2,8 +2,10 @@ import React, { useState, useEffect } from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
4
4
import MiqFormRenderer from '@@ddf' ;
5
+ // import { Button } from 'carbon-components-react';
6
+ // import MiqDataTable from '../miq-data-table';
5
7
import createSchema from './settings-replication-form.schema' ;
6
- import { SubscriptionsTableComponent } from './helper ' ;
8
+ import { SubscriptionsTableComponent } from './subscriptions-table ' ;
7
9
import ValidateSubscription from './validate-subscription' ;
8
10
import miqRedirectBack from '../../helpers/miq-redirect-back' ;
9
11
import mapper from '../../forms/mappers/componentMapper' ;
@@ -51,29 +53,58 @@ const SettingsReplicationForm = ({ pglogicalReplicationFormId }) => {
51
53
52
54
const onSubmit = ( values ) => {
53
55
if ( form . type === 'subscription' ) {
54
- const newSubscriptions = [ ] ;
55
-
56
- newSubscriptions . push ( {
57
- dbname : values . dbname ,
58
- host : values . host ,
59
- user : values . user ,
60
- password : values . password ,
61
- port : values . port ,
62
- } ) ;
56
+ if ( form . action === 'add' ) {
57
+ const newSubscriptions = [ ] ;
63
58
64
- setState ( ( state ) => ( {
65
- ...state ,
66
- initialValues : {
67
- replication_type : state . initialValues . replication_type ,
68
- subscriptions : state . initialValues . subscriptions ,
69
- } ,
70
- subscriptions : subscriptions . concat ( newSubscriptions ) ,
71
- form : {
72
- type : 'replication' ,
73
- className : 'replication_form' ,
74
- action : 'edit' ,
75
- } ,
76
- } ) ) ;
59
+ newSubscriptions . push ( {
60
+ dbname : values . dbname ,
61
+ host : values . host ,
62
+ user : values . user ,
63
+ password : values . password ,
64
+ port : values . port ,
65
+ } ) ;
66
+
67
+ setState ( ( state ) => ( {
68
+ ...state ,
69
+ initialValues : {
70
+ replication_type : state . initialValues . replication_type ,
71
+ subscriptions : state . initialValues . subscriptions ,
72
+ } ,
73
+ subscriptions : subscriptions . concat ( newSubscriptions ) ,
74
+ form : {
75
+ type : 'replication' ,
76
+ className : 'replication_form' ,
77
+ action : 'edit' ,
78
+ } ,
79
+ } ) ) ;
80
+ } else if ( form . action === 'edit' ) {
81
+ let modifiedSubscriptions = [ ] ;
82
+ modifiedSubscriptions = modifiedSubscriptions . concat ( subscriptions ) ;
83
+
84
+ const editedSub = {
85
+ dbname : values . dbname ,
86
+ host : values . host ,
87
+ password : values . password ,
88
+ port : values . port ,
89
+ user : values . user ,
90
+ } ;
91
+
92
+ modifiedSubscriptions [ initialValues . subId ] = editedSub ;
93
+
94
+ setState ( ( state ) => ( {
95
+ ...state ,
96
+ initialValues : {
97
+ replication_type : state . initialValues . replication_type ,
98
+ subscriptions : state . initialValues . subscriptions ,
99
+ } ,
100
+ subscriptions : modifiedSubscriptions ,
101
+ form : {
102
+ type : 'replication' ,
103
+ className : 'replication_form' ,
104
+ action : 'edit' ,
105
+ } ,
106
+ } ) ) ;
107
+ }
77
108
} else {
78
109
// Redirect to Settings -> Tasks
79
110
@@ -86,6 +117,17 @@ const SettingsReplicationForm = ({ pglogicalReplicationFormId }) => {
86
117
}
87
118
} ;
88
119
120
+ /* const onReset = () => {
121
+ setEnforced(() => ({ ...initialValues.enforced }));
122
+ setValues(() => ({ ...initialValues.values }));
123
+ setDisabled(true);
124
+ setChanged(true);
125
+ setInvalid(() => ({ ...initialValues.invalid }));
126
+ // eslint-disable-next-line no-return-assign
127
+ Array.from(document.querySelectorAll('.quota-table-input')).forEach((input, index) => input.value = initialValues.values[index]);
128
+ add_flash(__('All changes have been reset'), 'warn');
129
+ }; */
130
+
89
131
const onCancel = ( ) => {
90
132
if ( form . type === 'subscription' ) {
91
133
setState ( ( state ) => ( {
@@ -111,8 +153,63 @@ const SettingsReplicationForm = ({ pglogicalReplicationFormId }) => {
111
153
onCancel = { onCancel }
112
154
canReset
113
155
buttonsLabels = { { submitLabel } }
156
+ clearOnUnmount = { form . type !== 'replication' }
114
157
/>
115
158
) ;
159
+
160
+ /* if (form.type === 'subscription') {
161
+
162
+ } else {
163
+ return !isLoading && (
164
+ <div className="settings-replication-form">
165
+ <div className="subscriptions-section">
166
+ <div className="subscriptions-button" style={{ display: 'flex', flexDirection: 'row-reverse' }}>
167
+ <Button
168
+ kind="primary"
169
+ className="subscription-add bx--btn bx--btn--primary pull-right"
170
+ type="button"
171
+ variant="contained"
172
+ onClick={() => onButtonClick(formOptions)}
173
+ >
174
+ {addButtonLabel}
175
+ </Button>
176
+ </div>
177
+
178
+ <div className="subscriptions-table" style={{ display: 'grid', overflow: 'auto' }}>
179
+ <MiqDataTable
180
+ headers={[
181
+ { key: 'dbname', header: __('Database') },
182
+ { key: 'host', header: __('Host') },
183
+ { key: 'user', header: __('Username') },
184
+ { key: 'password', header: __('Password') },
185
+ { key: 'port', header: __('Port') },
186
+ { key: 'backlog', header: __('Backlog') },
187
+ { key: 'status', header: __('Status') },
188
+ { key: 'provider_region', header: __('Region') },
189
+ { key: 'edit', header: __('Edit') },
190
+ { key: 'delete', header: __('Delete') },
191
+ ]}
192
+ rows={rows}
193
+ size="md"
194
+ sortable={false}
195
+ onCellClick={(selectedRow, cellType) => onCellClick(selectedRow, cellType, formOptions)}
196
+ />
197
+ </div>
198
+ </div>
199
+ <div className="bx--btn-set">
200
+ <Button kind="primary" tabIndex={0} disabled={disabled} type="submit" onClick={onSubmit}>
201
+ {submitLabel}
202
+ </Button>
203
+ <Button kind="secondary" style={{ marginLeft: '10px' }} tabIndex={0} disabled={changed} type="reset" onClick={onReset}>
204
+ {__('Reset')}
205
+ </Button>
206
+ <Button kind="secondary" style={{ marginLeft: '10px' }} tabIndex={0} type="button" onClick={onCancel}>
207
+ {__('Cancel')}
208
+ </Button>
209
+ </div>
210
+ </div>
211
+ );
212
+ } */
116
213
} ;
117
214
118
215
SettingsReplicationForm . propTypes = {
0 commit comments