@@ -29,8 +29,12 @@ import { tooltipText } from './tooltipText'
2929import { FormValues , useForm } from './useForm'
3030import { ResponseMessage } from './ResponseMessage'
3131import { 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'
3438import {
3539 SelectWithTooltip ,
3640 InputWithChip ,
@@ -39,6 +43,11 @@ import {
3943
4044import styles from './styles.module.scss'
4145
46+ type PgOptionsType = {
47+ optionType : string
48+ addDefaultOptions : string [ ]
49+ }
50+ 4251const NON_LOGICAL_RETRIEVAL_MESSAGE =
4352 'Configuration editing is only available in logical mode'
4453const PREVENT_MODIFYING_MESSAGE = 'Editing is disabled by admin'
@@ -149,34 +158,77 @@ export const Configuration = observer(
149158 setIsModalOpen ( true )
150159 }
151160
152- const handleDeleteDatabase = (
161+ const handleDeleteChip = (
153162 _ : React . FormEvent < HTMLInputElement > ,
154- database : string ,
163+ uniqueValue : string ,
164+ id : string ,
155165 ) => {
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 (
159173 / [ , ( \s ) ( \n ) ( \r ) ( \t ) ( \r \n ) ] / gm,
160174 )
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 ] +
168180 ( curDividers [ i ] ? curDividers [ i ] : '' )
169181 }
170182 }
171- formik . setFieldValue ( 'databases' , newDatabases )
183+ formik . setFieldValue ( id , newValues )
172184 }
173185 }
174186
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+ 175213 const handleDockerImageSelect = (
176214 e : React . ChangeEvent < HTMLInputElement > ,
177215 ) => {
178216 const newDockerImages = formatDockerImageArray ( e . target . value )
179217 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+ )
180232 formik . setFieldValue ( 'dockerImageType' , e . target . value )
181233
182234 // select latest Postgres version on dockerImage change
@@ -206,7 +258,7 @@ export const Configuration = observer(
206258 setConnectionRes ( null )
207259 setSubmitMessage ( null )
208260 getEngine ( ) . then ( ( res ) => {
209- setDledition ( res ?. edition )
261+ setDledition ( String ( res ?. edition ) )
210262 } )
211263 } , [ ] )
212264
@@ -265,7 +317,7 @@ export const Configuration = observer(
265317 error = { Boolean ( formik . errors . dockerImageType ) }
266318 tooltipText = { tooltipText . dockerImageType }
267319 disabled = { isConfigurationDisabled }
268- items = { imageOptions . map ( ( image ) => {
320+ items = { dockerImageOptions . map ( ( image ) => {
269321 return {
270322 value : image . type ,
271323 children : image . name ,
@@ -420,7 +472,7 @@ export const Configuration = observer(
420472 label = "Databases"
421473 id = "databases"
422474 tooltipText = { tooltipText . databases }
423- handleDeleteDatabase = { handleDeleteDatabase }
475+ handleDeleteChip = { handleDeleteChip }
424476 disabled = { isConfigurationDisabled }
425477 onChange = { ( e ) =>
426478 formik . setFieldValue ( 'databases' , e . target . value )
@@ -451,22 +503,54 @@ export const Configuration = observer(
451503 </ Box >
452504 < InputWithTooltip
453505 label = "pg_dump jobs"
454- value = { formik . values . pg_dump }
455- tooltipText = { tooltipText . pg_dump }
506+ value = { formik . values . dumpParallelJobs }
507+ tooltipText = { tooltipText . dumpParallelJobs }
456508 disabled = { isConfigurationDisabled }
457509 onChange = { ( e ) =>
458- formik . setFieldValue ( 'pg_dump ' , e . target . value )
510+ formik . setFieldValue ( 'dumpParallelJobs ' , e . target . value )
459511 }
460512 />
461513 < InputWithTooltip
462514 label = "pg_restore jobs"
463- value = { formik . values . pg_restore }
464- tooltipText = { tooltipText . pg_restore }
515+ value = { formik . values . restoreParallelJobs }
516+ tooltipText = { tooltipText . restoreParallelJobs }
465517 disabled = { isConfigurationDisabled }
466518 onChange = { ( e ) =>
467- formik . setFieldValue ( 'pg_restore ' , e . target . value )
519+ formik . setFieldValue ( 'restoreParallelJobs ' , e . target . value )
468520 }
469521 />
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+ ) }
470554 < Box >
471555 < Typography className = { styles . subsection } >
472556 Subsection "retrieval.refresh"
0 commit comments