@@ -38,7 +38,7 @@ import { MagicIcon, SQLFileIcon } from '../../../../../../static/js/components/E
3838import { useModal } from '../../../../../../static/js/helpers/ModalProvider' ;
3939import { withColorPicker } from '../../../../../../static/js/helpers/withColorPicker' ;
4040import { useApplicationState } from '../../../../../../settings/static/ApplicationStateProvider' ;
41- import usePreferences from '../../../../../../preferences/ static/js/store ' ;
41+ import { useDelayDebounce } from '../../../../../../static/js/custom_hooks ' ;
4242
4343const StyledBox = styled ( Box ) ( ( { theme} ) => ( {
4444 padding : '2px 4px' ,
@@ -64,8 +64,7 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
6464 } ) ;
6565 const [ showDetails , setShowDetails ] = useState ( true ) ;
6666
67- const { saveToolData} = useApplicationState ( ) ;
68- const preferencesStore = usePreferences ( ) ;
67+ const { saveToolData, enableSaveToolData} = useApplicationState ( ) ;
6968 const { openMenuName, toggleMenu, onMenuClose} = usePgMenuGroup ( ) ;
7069 const saveAsMenuRef = React . useRef ( null ) ;
7170 const sqlMenuRef = React . useRef ( null ) ;
@@ -134,17 +133,12 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
134133 [ ERD_EVENTS . ANY_ITEM_SELECTED , ( selected ) => {
135134 setDisableButton ( 'drop-table' , ! selected ) ;
136135 } ] ,
137- [ ERD_EVENTS . DIRTY , ( isDirty ) => {
136+ [ ERD_EVENTS . DIRTY , ( isDirty , data ) => {
137+ const save_app_state = enableSaveToolData ( 'ERD' ) ;
138138 isDirtyRef . current = isDirty ;
139139 setDisableButton ( 'save' , ! isDirty ) ;
140- } ] ,
141- [ ERD_EVENTS . SAVE_ERD_TOOL_DATA , ( data ) => {
142- const save_app_state = preferencesStore ?. getPreferencesForModule ( 'misc' ) ?. save_app_state ;
143140 if ( save_app_state ) {
144- saveToolData ( { 'tool_name' : 'ERD' ,
145- 'trans_id' : connectionInfo . trans_id ,
146- 'connection_info' : connectionInfo ,
147- ...data } ) ;
141+ setSaveData ( data ) ;
148142 }
149143 } ] ,
150144 ] ;
@@ -158,6 +152,11 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
158152 } ;
159153 } , [ ] ) ;
160154
155+ const [ saveData , setSaveData ] = useState ( null ) ;
156+ useDelayDebounce ( ( saveData ) => {
157+ saveToolData ( 'ERD' , connectionInfo , connectionInfo . trans_id , saveData ) ;
158+ } , saveData , 500 ) ;
159+
161160 useEffect ( ( ) => {
162161 const showSql = ( ) => {
163162 eventBus . fireEvent ( ERD_EVENTS . SHOW_SQL , checkedMenuItems [ 'sql_with_drop' ] ) ;
0 commit comments