@@ -51,7 +51,7 @@ const StyledBox = styled(Box)(({theme}) => ({
5151 ...theme . mixins . panelBorder . bottom ,
5252} ) ) ;
5353
54- export function MainToolBar ( { preferences, eventBus, fillColor, textColor, notation, onNotationChange, connectionInfo} ) {
54+ export function MainToolBar ( { preferences, eventBus, fillColor, textColor, notation, onNotationChange, connectionInfo, toolbarPrefs } ) {
5555 const theme = useTheme ( ) ;
5656 const [ buttonsDisabled , setButtonsDisabled ] = useState ( {
5757 'save' : true ,
@@ -72,6 +72,7 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
7272 const notationMenuRef = React . useRef ( null ) ;
7373 const isDirtyRef = React . useRef ( null ) ;
7474 const [ checkedMenuItems , setCheckedMenuItems ] = React . useState ( { } ) ;
75+ const notationRef = React . useRef ( notation ) ;
7576 const modal = useModal ( ) ;
7677
7778 const setDisableButton = useCallback ( ( name , disable = true ) => {
@@ -86,6 +87,15 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
8687 [ e . value ] : newVal ,
8788 } ;
8889 } ) ;
90+ setSaveERDData ( ( prev ) => {
91+ return {
92+ ...prev ,
93+ toolbarPrefs : {
94+ ...prev ?. toolbarPrefs ,
95+ [ e . value ] : ! prev ?. toolbarPrefs ?. [ e . value ] ,
96+ } ,
97+ } ;
98+ } ) ;
8999 } , [ ] ) ;
90100
91101 const onHelpClick = ( ) => {
@@ -111,15 +121,31 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
111121 } ;
112122
113123 useEffect ( ( ) => {
114- if ( preferences ) {
124+ if ( ! _ . isUndefined ( toolbarPrefs ) && ! _ . isNull ( toolbarPrefs ) && Object . keys ( toolbarPrefs ) . length > 0 ) {
125+ /* Apply toolbar prefs */
126+ if ( ! _ . isUndefined ( toolbarPrefs . sql_with_drop ) ) {
127+ setCheckedMenuItems ( ( prev ) => ( {
128+ ...prev ,
129+ sql_with_drop : toolbarPrefs . sql_with_drop ,
130+ } ) ) ;
131+ }
132+ if ( ! _ . isUndefined ( toolbarPrefs . cardinality ) ) {
133+ notationRef . current = toolbarPrefs . cardinality ;
134+ onNotationChange ( { 'value' : toolbarPrefs . cardinality } ) ;
135+ } else {
136+ notationRef . current = notation ;
137+ }
138+ }
139+ else if ( preferences ) {
115140 /* Get the prefs first time */
116141 if ( _ . isUndefined ( checkedMenuItems . sql_with_drop ) ) {
117142 setCheckedMenuItems ( {
118143 sql_with_drop : preferences . sql_with_drop ,
119144 } ) ;
120145 }
146+ notationRef . current = notation ;
121147 }
122- } , [ preferences ] ) ;
148+ } , [ preferences , toolbarPrefs ] ) ;
123149
124150 useEffect ( ( ) => {
125151 const events = [
@@ -134,11 +160,11 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
134160 [ ERD_EVENTS . ANY_ITEM_SELECTED , ( selected ) => {
135161 setDisableButton ( 'drop-table' , ! selected ) ;
136162 } ] ,
137- [ ERD_EVENTS . DIRTY , ( isDirty , data , fileName ) => {
163+ [ ERD_EVENTS . DIRTY , ( isDirty , data , fileName , toolbarPrefs ) => {
138164 isDirtyRef . current = isDirty ;
139165 setDisableButton ( 'save' , ! isDirty ) ;
140166 if ( ( isDirty || fileName ) && isSaveToolDataEnabled ( 'ERD' ) ) {
141- setSaveERDData ( { data, fileName, isDirty} ) ;
167+ setSaveERDData ( { data, fileName, isDirty, toolbarPrefs } ) ;
142168 }
143169 } ] ,
144170 ] ;
@@ -153,8 +179,8 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
153179 } , [ ] ) ;
154180
155181 const [ saveERDData , setSaveERDData ] = useState ( null ) ;
156- useDelayDebounce ( ( { data, fileName, isDirty} ) => {
157- saveToolData ( 'ERD' , { ...connectionInfo , 'open_file_name' :fileName , 'is_editor_dirty' : isDirty } , connectionInfo . trans_id , data ) ;
182+ useDelayDebounce ( ( { data, fileName, isDirty, toolbarPrefs } ) => {
183+ saveToolData ( 'ERD' , { ...connectionInfo , 'open_file_name' :fileName , 'is_editor_dirty' : isDirty , 'preferences' : toolbarPrefs } , connectionInfo . trans_id , data ) ;
158184 } , saveERDData , 500 ) ;
159185
160186 useEffect ( ( ) => {
@@ -167,6 +193,20 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
167193 } ;
168194 } , [ checkedMenuItems [ 'sql_with_drop' ] ] ) ;
169195
196+ const onCardinalityNotationChange = useCallback ( ( e ) => {
197+ setSaveERDData ( ( prev ) => {
198+ return {
199+ ...prev ,
200+ toolbarPrefs : {
201+ ...prev ?. toolbarPrefs ,
202+ cardinality : e . value ,
203+ } ,
204+ } ;
205+ } ) ;
206+ notationRef . current = e . value ;
207+ onNotationChange ( e ) ;
208+ } , [ onNotationChange ] ) ;
209+
170210 return (
171211 ( < >
172212 < StyledBox >
@@ -336,8 +376,8 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
336376 label = { gettext ( 'Cardinality Notation' ) }
337377
338378 >
339- < PgMenuItem hasCheck closeOnCheck value = "crows" checked = { notation == 'crows' } onClick = { onNotationChange } > { gettext ( 'Crow\'s Foot Notation' ) } </ PgMenuItem >
340- < PgMenuItem hasCheck closeOnCheck value = "chen" checked = { notation == 'chen' } onClick = { onNotationChange } > { gettext ( 'Chen Notation' ) } </ PgMenuItem >
379+ < PgMenuItem hasCheck closeOnCheck value = "crows" checked = { notationRef . current == 'crows' } onClick = { onCardinalityNotationChange } > { gettext ( 'Crow\'s Foot Notation' ) } </ PgMenuItem >
380+ < PgMenuItem hasCheck closeOnCheck value = "chen" checked = { notationRef . current == 'chen' } onClick = { onCardinalityNotationChange } > { gettext ( 'Chen Notation' ) } </ PgMenuItem >
341381 </ PgMenu >
342382 </ > )
343383 ) ;
@@ -351,6 +391,7 @@ MainToolBar.propTypes = {
351391 notation : PropTypes . string ,
352392 onNotationChange : PropTypes . func ,
353393 connectionInfo : PropTypes . object ,
394+ toolbarPrefs : PropTypes . object ,
354395} ;
355396
356397const ColorButton = withColorPicker ( PgIconButton ) ;
0 commit comments