@@ -29,8 +29,12 @@ import { tooltipText } from './tooltipText'
29
29
import { FormValues , useForm } from './useForm'
30
30
import { ResponseMessage } from './ResponseMessage'
31
31
import { ConfigSectionTitle , Header , ModalTitle } from './Header'
32
- import { imageOptions } from './imageOptions'
33
- import { formatDockerImageArray , uniqueDatabases } from './utils'
32
+ import {
33
+ dockerImageOptions ,
34
+ defaultPgDumpOptions ,
35
+ defaultPgRestoreOptions ,
36
+ } from './configOptions'
37
+ import { formatDockerImageArray , FormValuesKey , uniqueChipValue } from './utils'
34
38
import {
35
39
SelectWithTooltip ,
36
40
InputWithChip ,
@@ -39,6 +43,11 @@ import {
39
43
40
44
import styles from './styles.module.scss'
41
45
46
+ type PgOptionsType = {
47
+ optionType : string
48
+ addDefaultOptions : string [ ]
49
+ }
50
+
42
51
const NON_LOGICAL_RETRIEVAL_MESSAGE =
43
52
'Configuration editing is only available in logical mode'
44
53
const PREVENT_MODIFYING_MESSAGE = 'Editing is disabled by admin'
@@ -149,34 +158,77 @@ export const Configuration = observer(
149
158
setIsModalOpen ( true )
150
159
}
151
160
152
- const handleDeleteDatabase = (
161
+ const handleDeleteChip = (
153
162
_ : React . FormEvent < HTMLInputElement > ,
154
- database : string ,
163
+ uniqueValue : string ,
164
+ id : string ,
155
165
) => {
156
- if ( formik . values . databases ) {
157
- let currentDatabases = uniqueDatabases ( formik . values . databases )
158
- let curDividers = formik . values . databases . match (
166
+ if ( formik . values [ id as FormValuesKey ] ) {
167
+ let newValues = ''
168
+ const currentValues = uniqueChipValue (
169
+ String ( formik . values [ id as FormValuesKey ] ) ,
170
+ )
171
+ const splitValues = currentValues . split ( ' ' )
172
+ const curDividers = String ( formik . values [ id as FormValuesKey ] ) . match (
159
173
/ [ , ( \s ) ( \n ) ( \r ) ( \t ) ( \r \n ) ] / gm,
160
174
)
161
- let newDatabases = ''
162
- let splitDatabases = currentDatabases . split ( ' ' )
163
- for ( let i in splitDatabases ) {
164
- if ( curDividers && splitDatabases [ i ] !== database ) {
165
- newDatabases =
166
- newDatabases +
167
- splitDatabases [ i ] +
175
+ for ( let i in splitValues ) {
176
+ if ( curDividers && splitValues [ i ] !== uniqueValue ) {
177
+ newValues =
178
+ newValues +
179
+ splitValues [ i ] +
168
180
( curDividers [ i ] ? curDividers [ i ] : '' )
169
181
}
170
182
}
171
- formik . setFieldValue ( 'databases' , newDatabases )
183
+ formik . setFieldValue ( id , newValues )
172
184
}
173
185
}
174
186
187
+ const handleSelectPgOptions = (
188
+ e : React . ChangeEvent < HTMLInputElement > ,
189
+ formikName : string ,
190
+ formikValue : string ,
191
+ initialValue : string | undefined ,
192
+ pgOptions : PgOptionsType [ ] ,
193
+ ) => {
194
+ let pgValue = formikValue
195
+ // set initial value on change
196
+ formik . setFieldValue ( formikName , initialValue )
197
+
198
+ const selectedPgOptions = pgOptions . filter (
199
+ ( pg ) => e . target . value === pg . optionType ,
200
+ )
201
+
202
+ // add options to formik field
203
+ selectedPgOptions . forEach ( ( pg ) => {
204
+ pg . addDefaultOptions . forEach ( ( addOption ) => {
205
+ if ( ! pgValue . includes ( addOption ) ) {
206
+ const addOptionWithSpace = addOption + ' '
207
+ formik . setFieldValue ( formikName , ( pgValue += addOptionWithSpace ) )
208
+ }
209
+ } )
210
+ } )
211
+ }
212
+
175
213
const handleDockerImageSelect = (
176
214
e : React . ChangeEvent < HTMLInputElement > ,
177
215
) => {
178
216
const newDockerImages = formatDockerImageArray ( e . target . value )
179
217
setDockerImages ( newDockerImages )
218
+ handleSelectPgOptions (
219
+ e ,
220
+ 'pgDumpCustomOptions' ,
221
+ formik . values . pgDumpCustomOptions ,
222
+ configData ?. pgDumpCustomOptions ,
223
+ defaultPgDumpOptions ,
224
+ )
225
+ handleSelectPgOptions (
226
+ e ,
227
+ 'pgRestoreCustomOptions' ,
228
+ formik . values . pgRestoreCustomOptions ,
229
+ configData ?. pgRestoreCustomOptions ,
230
+ defaultPgRestoreOptions ,
231
+ )
180
232
formik . setFieldValue ( 'dockerImageType' , e . target . value )
181
233
182
234
// select latest Postgres version on dockerImage change
@@ -206,7 +258,7 @@ export const Configuration = observer(
206
258
setConnectionRes ( null )
207
259
setSubmitMessage ( null )
208
260
getEngine ( ) . then ( ( res ) => {
209
- setDledition ( res ?. edition )
261
+ setDledition ( String ( res ?. edition ) )
210
262
} )
211
263
} , [ ] )
212
264
@@ -265,7 +317,7 @@ export const Configuration = observer(
265
317
error = { Boolean ( formik . errors . dockerImageType ) }
266
318
tooltipText = { tooltipText . dockerImageType }
267
319
disabled = { isConfigurationDisabled }
268
- items = { imageOptions . map ( ( image ) => {
320
+ items = { dockerImageOptions . map ( ( image ) => {
269
321
return {
270
322
value : image . type ,
271
323
children : image . name ,
@@ -420,7 +472,7 @@ export const Configuration = observer(
420
472
label = "Databases"
421
473
id = "databases"
422
474
tooltipText = { tooltipText . databases }
423
- handleDeleteDatabase = { handleDeleteDatabase }
475
+ handleDeleteChip = { handleDeleteChip }
424
476
disabled = { isConfigurationDisabled }
425
477
onChange = { ( e ) =>
426
478
formik . setFieldValue ( 'databases' , e . target . value )
@@ -451,22 +503,54 @@ export const Configuration = observer(
451
503
</ Box >
452
504
< InputWithTooltip
453
505
label = "pg_dump jobs"
454
- value = { formik . values . pg_dump }
455
- tooltipText = { tooltipText . pg_dump }
506
+ value = { formik . values . dumpParallelJobs }
507
+ tooltipText = { tooltipText . dumpParallelJobs }
456
508
disabled = { isConfigurationDisabled }
457
509
onChange = { ( e ) =>
458
- formik . setFieldValue ( 'pg_dump ' , e . target . value )
510
+ formik . setFieldValue ( 'dumpParallelJobs ' , e . target . value )
459
511
}
460
512
/>
461
513
< InputWithTooltip
462
514
label = "pg_restore jobs"
463
- value = { formik . values . pg_restore }
464
- tooltipText = { tooltipText . pg_restore }
515
+ value = { formik . values . restoreParallelJobs }
516
+ tooltipText = { tooltipText . restoreParallelJobs }
465
517
disabled = { isConfigurationDisabled }
466
518
onChange = { ( e ) =>
467
- formik . setFieldValue ( 'pg_restore ' , e . target . value )
519
+ formik . setFieldValue ( 'restoreParallelJobs ' , e . target . value )
468
520
}
469
521
/>
522
+ { dleEdition !== 'community' && (
523
+ < >
524
+ < InputWithChip
525
+ value = { formik . values . pgDumpCustomOptions }
526
+ label = "pg_dump customOptions"
527
+ id = "pgDumpCustomOptions"
528
+ tooltipText = { tooltipText . pgDumpCustomOptions }
529
+ handleDeleteChip = { handleDeleteChip }
530
+ disabled = { isConfigurationDisabled }
531
+ onChange = { ( e ) =>
532
+ formik . setFieldValue (
533
+ 'pgDumpCustomOptions' ,
534
+ e . target . value ,
535
+ )
536
+ }
537
+ />
538
+ < InputWithChip
539
+ value = { formik . values . pgRestoreCustomOptions }
540
+ label = "pg_restore customOptions"
541
+ id = "pgRestoreCustomOptions"
542
+ tooltipText = { tooltipText . pgRestoreCustomOptions }
543
+ handleDeleteChip = { handleDeleteChip }
544
+ disabled = { isConfigurationDisabled }
545
+ onChange = { ( e ) =>
546
+ formik . setFieldValue (
547
+ 'pgRestoreCustomOptions' ,
548
+ e . target . value ,
549
+ )
550
+ }
551
+ />
552
+ </ >
553
+ ) }
470
554
< Box >
471
555
< Typography className = { styles . subsection } >
472
556
Subsection "retrieval.refresh"
0 commit comments