@@ -7,10 +7,6 @@ import { ToastHelper } from '../../../shared/toast';
77import { ConfirmationComponent } from '../../../shared/ui' ;
88import { EditBackupConfigComponent , ShowBackupConfigComponent } from '../../backups' ;
99import { EditHealthcheckConfigComponent , ShowHealthcheckConfigComponent } from '../../healthcheck' ;
10- import {
11- EditMonitoringSettingsComponent ,
12- ShowMonitoringSettingsComponent ,
13- } from '../../monitoring/settings' ;
1410import { EditDatabaseNotifiersComponent } from './edit/EditDatabaseNotifiersComponent' ;
1511import { EditDatabaseSpecificDataComponent } from './edit/EditDatabaseSpecificDataComponent' ;
1612import { ShowDatabaseNotifiersComponent } from './show/ShowDatabaseNotifiersComponent' ;
@@ -39,13 +35,12 @@ export const DatabaseConfigComponent = ({
3935 const [ isEditBackupConfig , setIsEditBackupConfig ] = useState ( false ) ;
4036 const [ isEditNotifiersSettings , setIsEditNotifiersSettings ] = useState ( false ) ;
4137 const [ isEditHealthcheckSettings , setIsEditHealthcheckSettings ] = useState ( false ) ;
42- const [ isEditMonitoringSettings , setIsEditMonitoringSettings ] = useState ( false ) ;
4338
4439 const [ isNameUnsaved , setIsNameUnsaved ] = useState ( false ) ;
4540 const [ isSaving , setIsSaving ] = useState ( false ) ;
4641
4742 const [ isTestingConnection , setIsTestingConnection ] = useState ( false ) ;
48-
43+ const [ isCopying , setIsCopying ] = useState ( false ) ;
4944 const [ isShowRemoveConfirm , setIsShowRemoveConfirm ] = useState ( false ) ;
5045 const [ isRemoving , setIsRemoving ] = useState ( false ) ;
5146
@@ -55,6 +50,28 @@ export const DatabaseConfigComponent = ({
5550 databaseApi . getDatabase ( database . id ) . then ( setDatabase ) ;
5651 } ;
5752
53+ const copyDatabase = ( ) => {
54+ if ( ! database ) return ;
55+
56+ setIsCopying ( true ) ;
57+
58+ databaseApi
59+ . copyDatabase ( database . id )
60+ . then ( ( copiedDatabase ) => {
61+ ToastHelper . showToast ( {
62+ title : 'Database copied successfully!' ,
63+ description : `"${ copiedDatabase . name } " has been created successfully` ,
64+ } ) ;
65+ window . location . reload ( ) ;
66+ } )
67+ . catch ( ( e : Error ) => {
68+ alert ( e . message ) ;
69+ } )
70+ . finally ( ( ) => {
71+ setIsCopying ( false ) ;
72+ } ) ;
73+ } ;
74+
5875 const testConnection = ( ) => {
5976 if ( ! database ) return ;
6077
@@ -97,16 +114,13 @@ export const DatabaseConfigComponent = ({
97114 } ) ;
98115 } ;
99116
100- const startEdit = (
101- type : 'name' | 'database' | 'backup-config' | 'notifiers' | 'healthcheck' | 'monitoring' ,
102- ) => {
117+ const startEdit = ( type : 'name' | 'database' | 'backup-config' | 'notifiers' | 'healthcheck' ) => {
103118 setEditDatabase ( JSON . parse ( JSON . stringify ( database ) ) ) ;
104119 setIsEditName ( type === 'name' ) ;
105120 setIsEditDatabaseSpecificDataSettings ( type === 'database' ) ;
106121 setIsEditBackupConfig ( type === 'backup-config' ) ;
107122 setIsEditNotifiersSettings ( type === 'notifiers' ) ;
108123 setIsEditHealthcheckSettings ( type === 'healthcheck' ) ;
109- setIsEditMonitoringSettings ( type === 'monitoring' ) ;
110124 setIsNameUnsaved ( false ) ;
111125 } ;
112126
@@ -344,40 +358,6 @@ export const DatabaseConfigComponent = ({
344358 </ div >
345359 </ div >
346360
347- < div className = "flex flex-wrap gap-10" >
348- < div className = "w-[400px]" >
349- < div className = "mt-5 flex items-center font-bold" >
350- < div > Monitoring settings</ div >
351-
352- { ! isEditMonitoringSettings ? (
353- < div className = "ml-2 h-4 w-4 cursor-pointer" onClick = { ( ) => startEdit ( 'monitoring' ) } >
354- < img src = "/icons/pen-gray.svg" />
355- </ div >
356- ) : (
357- < div />
358- ) }
359- </ div >
360-
361- < div className = "mt-1 text-sm" >
362- { isEditMonitoringSettings ? (
363- < EditMonitoringSettingsComponent
364- database = { database }
365- onCancel = { ( ) => {
366- setIsEditMonitoringSettings ( false ) ;
367- loadSettings ( ) ;
368- } }
369- onSaved = { ( ) => {
370- setIsEditMonitoringSettings ( false ) ;
371- loadSettings ( ) ;
372- } }
373- />
374- ) : (
375- < ShowMonitoringSettingsComponent database = { database } />
376- ) }
377- </ div >
378- </ div >
379- </ div >
380-
381361 { ! isEditDatabaseSpecificDataSettings && (
382362 < div className = "mt-10" >
383363 < Button
@@ -391,6 +371,17 @@ export const DatabaseConfigComponent = ({
391371 Test connection
392372 </ Button >
393373
374+ < Button
375+ type = "primary"
376+ className = "mr-1"
377+ ghost
378+ onClick = { copyDatabase }
379+ loading = { isCopying }
380+ disabled = { isCopying }
381+ >
382+ Copy
383+ </ Button >
384+
394385 < Button
395386 type = "primary"
396387 danger
0 commit comments