Skip to content

Commit 5abd9e3

Browse files
Fixed an issue where tools settings changed by the users were not restored on application relaunch. #8988
1 parent 3e05f7a commit 5abd9e3

File tree

4 files changed

+80
-17
lines changed

4 files changed

+80
-17
lines changed

web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export default class ERDTool extends React.Component {
177177
this.fmUtilsObj = new FileManagerUtils(this.apiObj, {modal: this.context});
178178
this.restore = props.params.restore == 'true';
179179
this.eventBus = new EventBus();
180+
this.toolbarPrefs = null;
180181

181182
_.bindAll(this, ['onLoadDiagram', 'onSaveDiagram', 'onSQLClick',
182183
'onImageClick', 'onSearchNode', 'onAddNewNode', 'onEditTable', 'onCloneNode', 'onDeleteNode', 'onNoteClick',
@@ -408,6 +409,7 @@ export default class ERDTool extends React.Component {
408409

409410
restoreToolContent = async (toolContent) => {
410411
if(toolContent){
412+
this.toolbarPrefs = toolContent.connectionInfo?.preferences || {};
411413
if(toolContent?.modifiedExternally){
412414
toolContent = await this.fmUtilsObj.warnFileReload(toolContent?.fileName, toolContent?.data, '');
413415
}
@@ -420,7 +422,7 @@ export default class ERDTool extends React.Component {
420422
this.registerModelEvents();
421423
if(toolContent.fileName)this.setState({current_file: toolContent.fileName});
422424
this.setState({dirty: true});
423-
this.eventBus.fireEvent(ERD_EVENTS.DIRTY, true, toolContent.data);
425+
this.eventBus.fireEvent(ERD_EVENTS.DIRTY, true, toolContent.data, null, this.toolbarPrefs);
424426
}
425427
}
426428
};
@@ -1086,6 +1088,7 @@ export default class ERDTool extends React.Component {
10861088
<MainToolBar preferences={this.state.preferences} eventBus={this.eventBus}
10871089
fillColor={this.state.fill_color} textColor={this.state.text_color}
10881090
notation={this.state.cardinality_notation} onNotationChange={this.onNotationChange} connectionInfo={this.props.params}
1091+
toolbarPrefs={this.toolbarPrefs}
10891092
/>
10901093
<FloatingNote open={this.state.note_open} onClose={this.onNoteClose}
10911094
anchorEl={this.noteRefEle} noteNode={this.state.note_node} appendTo={this.diagramContainerRef.current} rows={8}/>

web/pgadmin/tools/erd/static/js/erd_tool/components/MainToolBar.jsx

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88
//////////////////////////////////////////////////////////////
99
import React, {useCallback, useEffect, useState} from 'react';
10+
import _ from 'lodash';
1011
import { styled } from '@mui/material/styles';
1112
import { Box, useTheme } from '@mui/material';
1213
import { PgButtonGroup, PgIconButton } from '../../../../../../static/js/components/Buttons';
@@ -51,7 +52,7 @@ const StyledBox = styled(Box)(({theme}) => ({
5152
...theme.mixins.panelBorder.bottom,
5253
}));
5354

54-
export function MainToolBar({preferences, eventBus, fillColor, textColor, notation, onNotationChange, connectionInfo}) {
55+
export function MainToolBar({preferences, eventBus, fillColor, textColor, notation, onNotationChange, connectionInfo, toolbarPrefs}) {
5556
const theme = useTheme();
5657
const [buttonsDisabled, setButtonsDisabled] = useState({
5758
'save': true,
@@ -72,6 +73,7 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
7273
const notationMenuRef = React.useRef(null);
7374
const isDirtyRef = React.useRef(null);
7475
const [checkedMenuItems, setCheckedMenuItems] = React.useState({});
76+
const notationRef = React.useRef(notation);
7577
const modal = useModal();
7678

7779
const setDisableButton = useCallback((name, disable=true)=>{
@@ -86,6 +88,15 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
8688
[e.value]: newVal,
8789
};
8890
});
91+
setSaveERDData((prev)=>{
92+
return {
93+
...prev,
94+
toolbarPrefs: {
95+
...prev?.toolbarPrefs,
96+
[e.value]: !prev?.toolbarPrefs?.[e.value],
97+
},
98+
};
99+
});
89100
}, []);
90101

91102
const onHelpClick=()=>{
@@ -111,15 +122,31 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
111122
};
112123

113124
useEffect(()=>{
114-
if(preferences) {
125+
if(!_.isUndefined(toolbarPrefs) && !_.isNull(toolbarPrefs) && Object.keys(toolbarPrefs).length > 0) {
126+
/* Apply toolbar prefs */
127+
if(!_.isUndefined(toolbarPrefs.sql_with_drop)) {
128+
setCheckedMenuItems((prev)=>({
129+
...prev,
130+
sql_with_drop: toolbarPrefs.sql_with_drop,
131+
}));
132+
}
133+
if(!_.isUndefined(toolbarPrefs.cardinality)) {
134+
notationRef.current = toolbarPrefs.cardinality;
135+
onNotationChange({'value': toolbarPrefs.cardinality});
136+
} else {
137+
notationRef.current = notation;
138+
}
139+
}
140+
else if(preferences) {
115141
/* Get the prefs first time */
116142
if(_.isUndefined(checkedMenuItems.sql_with_drop)) {
117143
setCheckedMenuItems({
118144
sql_with_drop: preferences.sql_with_drop,
119145
});
120146
}
147+
notationRef.current = notation;
121148
}
122-
}, [preferences]);
149+
}, [preferences, toolbarPrefs, notation, onNotationChange]);
123150

124151
useEffect(()=>{
125152
const events = [
@@ -134,11 +161,17 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
134161
[ERD_EVENTS.ANY_ITEM_SELECTED, (selected)=>{
135162
setDisableButton('drop-table', !selected);
136163
}],
137-
[ERD_EVENTS.DIRTY, (isDirty, data, fileName)=>{
164+
[ERD_EVENTS.DIRTY, (isDirty, data, fileName, toolbarPrefs)=>{
138165
isDirtyRef.current = isDirty;
139166
setDisableButton('save', !isDirty);
140167
if((isDirty || fileName) && isSaveToolDataEnabled('ERD')){
141-
setSaveERDData({data, fileName, isDirty});
168+
setSaveERDData((prev) => ({
169+
...prev,
170+
data,
171+
fileName,
172+
isDirty,
173+
...(toolbarPrefs !== undefined && { toolbarPrefs }),
174+
}));
142175
}
143176
}],
144177
];
@@ -153,8 +186,10 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
153186
}, []);
154187

155188
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);
189+
useDelayDebounce((saveData)=>{
190+
if(saveData?.data !== undefined){
191+
saveToolData('ERD', {...connectionInfo, 'open_file_name': saveData.fileName, 'is_editor_dirty': saveData.isDirty, 'preferences': saveData.toolbarPrefs}, connectionInfo.trans_id, saveData.data);
192+
}
158193
}, saveERDData, 500);
159194

160195
useEffect(()=>{
@@ -167,6 +202,20 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
167202
};
168203
}, [checkedMenuItems['sql_with_drop']]);
169204

205+
const onCardinalityNotationChange = useCallback((e)=>{
206+
setSaveERDData((prev)=>{
207+
return {
208+
...prev,
209+
toolbarPrefs: {
210+
...prev?.toolbarPrefs,
211+
cardinality: e.value,
212+
},
213+
};
214+
});
215+
notationRef.current = e.value;
216+
onNotationChange(e);
217+
}, [onNotationChange]);
218+
170219
return (
171220
(<>
172221
<StyledBox>
@@ -336,8 +385,8 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
336385
label={gettext('Cardinality Notation')}
337386

338387
>
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>
388+
<PgMenuItem hasCheck closeOnCheck value="crows" checked={notationRef.current == 'crows'} onClick={onCardinalityNotationChange}>{gettext('Crow\'s Foot Notation')}</PgMenuItem>
389+
<PgMenuItem hasCheck closeOnCheck value="chen" checked={notationRef.current == 'chen'} onClick={onCardinalityNotationChange}>{gettext('Chen Notation')}</PgMenuItem>
341390
</PgMenu>
342391
</>)
343392
);
@@ -351,6 +400,7 @@ MainToolBar.propTypes = {
351400
notation: PropTypes.string,
352401
onNotationChange: PropTypes.func,
353402
connectionInfo: PropTypes.object,
403+
toolbarPrefs: PropTypes.object,
354404
};
355405

356406
const ColorButton = withColorPicker(PgIconButton);

web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const Root = styled('div')(({theme}) => ({
6464
},
6565
}));
6666

67-
export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowIds, onServerSchemaChange, rows, compareParams, filterParams = [FILTER_NAME.DIFFERENT, FILTER_NAME.SOURCE_ONLY, FILTER_NAME.TARGET_ONLY] }) {
67+
export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowIds, onServerSchemaChange, rows, compareParams, filterParams, filters }) {
6868
const filterRef = useRef(null);
6969
const compareRef = useRef(null);
7070

@@ -103,8 +103,13 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
103103
schemaDiffCtx?.preferences_schema_diff?.ignore_grants && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS);
104104
setSelectedCompare(prefCompareOptions);
105105
}
106-
}, [schemaDiffCtx.preferences_schema_diff]);
106+
}, [schemaDiffCtx.preferences_schema_diff, compareParams]);
107107

108+
useEffect(() => {
109+
if (!_.isUndefined(filters) && !_.isEmpty(filters)) {
110+
setSelectedFilters(filters);
111+
}
112+
}, [filters]);
108113

109114
const selectFilterOption = (option) => {
110115
let newOptions = [];

web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffCompare.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ export function SchemaDiffCompare({ params }) {
143143
if(params.params?.restore == 'true'){
144144
async function fetchData() {
145145
const response = await getToolContent(params.transId);
146-
oldSchemaDiffData.current = response?.data;
146+
oldSchemaDiffData.current = response;
147+
if(response?.connectionInfo?.preferences){
148+
setCompareOptions(response?.connectionInfo?.preferences?.compareParams);
149+
setFilterOptions(response?.connectionInfo?.preferences?.filterParams);
150+
}
147151
}
148152
fetchData();
149153
}
@@ -152,7 +156,7 @@ export function SchemaDiffCompare({ params }) {
152156

153157
useEffect(()=>{
154158
if(oldSchemaDiffData.current){
155-
_.each(oldSchemaDiffData.current,(d)=>{
159+
_.each(oldSchemaDiffData.current.data,(d)=>{
156160
if(d.diff_type == TYPE.SOURCE){
157161
setSelectedSourceSid(d.selectedSourceSid);
158162
}else{
@@ -294,7 +298,7 @@ export function SchemaDiffCompare({ params }) {
294298
{ diff_type: TYPE.SOURCE, selectedSourceSid: sourceData.sid, selectedSourceDid:sourceData.did, selectedSourceScid: sourceData.scid},
295299
{ diff_type: TYPE.TARGET, selectedTargetSid:targetData.sid, selectedTargetDid:targetData.did, selectedTargetScid:targetData.scid },
296300
];
297-
saveToolData('schema_diff', null, params.transId, toolData);
301+
saveToolData('schema_diff', {preferences:{compareParams, filterParams}}, params.transId, toolData);
298302
}
299303

300304
setLoaderText('Comparing objects... (this may take a few minutes)...');
@@ -678,7 +682,7 @@ export function SchemaDiffCompare({ params }) {
678682

679683
useEffect(()=>{
680684
if(oldSchemaDiffData.current){
681-
_.each(oldSchemaDiffData.current,(d)=>{
685+
_.each(oldSchemaDiffData.current?.data,(d)=>{
682686
if(d.diff_type == TYPE.SOURCE){
683687
setSelectedSourceDid(d.selectedSourceDid);
684688
}else{
@@ -702,7 +706,7 @@ export function SchemaDiffCompare({ params }) {
702706

703707
useEffect(()=>{
704708
if(oldSchemaDiffData.current){
705-
_.each(oldSchemaDiffData.current,(d)=>{
709+
_.each(oldSchemaDiffData.current?.data,(d)=>{
706710
if(d.diff_type == TYPE.SOURCE){
707711
setSelectedSourceScid(d.selectedSourceScid);
708712
}else{
@@ -802,6 +806,7 @@ export function SchemaDiffCompare({ params }) {
802806
}}
803807
filterParams={getFilterParams()}
804808
compareParams={compareOptions}
809+
filters={filterOptions}
805810
></SchemaDiffButtonComponent>
806811
</Grid>
807812
</Grid>

0 commit comments

Comments
 (0)