Skip to content

Commit 8795b7e

Browse files
Fixed an issue where internal settings for the separate tools tab were not being restored during application relaunch. #8988
1 parent 9464e44 commit 8795b7e

File tree

4 files changed

+71
-17
lines changed

4 files changed

+71
-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: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

356397
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)